mirror of
https://github.com/XiaoGe-LiBai/yangmao.git
synced 2025-12-17 03:58:13 +08:00
146 lines
5.1 KiB
JavaScript
146 lines
5.1 KiB
JavaScript
/*
|
||
* @File: wyl_signin.js
|
||
* @Author: Gemini
|
||
* @Date: 2025-10-02
|
||
* @Description: 维誉链每日签到脚本(青龙面板/普通 Node 均可)
|
||
* 积分自动 +1,无需再设 WYL_INTEGRAL 环境变量
|
||
* cron: 0 0,12 * * *
|
||
*/
|
||
|
||
// ========== 依赖 ==========
|
||
const axios = require('axios');
|
||
const fs = require('fs');
|
||
const path = require('path');
|
||
const { sendNotify } = require('./sendNotify'); // 通知文件路径保持与你原来一致
|
||
// =============================
|
||
|
||
// ========== 积分持久化 ==========
|
||
const INTEGRAL_FILE = path.join(__dirname, '.wyl_integral'); // 存在脚本同目录
|
||
|
||
/* 读上次积分,文件不存在就给个默认值 100 */
|
||
function readLastIntegral() {
|
||
try {
|
||
return Number(fs.readFileSync(INTEGRAL_FILE, 'utf8').trim());
|
||
} catch {
|
||
return 100; // 首次运行起点,可自行修改
|
||
}
|
||
}
|
||
|
||
/* 把本次积分写盘,下次继续 +1 */
|
||
function saveIntegral(val) {
|
||
fs.writeFileSync(INTEGRAL_FILE, String(val));
|
||
}
|
||
// =================================
|
||
|
||
// ========== 配置区 ==========
|
||
const usersDataEnv = process.env.WYL_USER_IDS;
|
||
const users = usersDataEnv ? usersDataEnv.split(/&|\n/).filter(Boolean) : [];
|
||
// 不再需要 WYL_INTEGRAL 环境变量
|
||
// =============================
|
||
|
||
// ========== 工具 ==========
|
||
const logSeparator = () => console.log('-'.repeat(40));
|
||
// ===========================
|
||
|
||
// ========== 签到逻辑 ==========
|
||
async function signIn(userData, integral) {
|
||
const [userId, openId] = userData.split('#');
|
||
if (!userId || !openId) {
|
||
return {
|
||
resultMessage: `账号 [${userData}] 格式错误,请使用 "用户ID#openId" 格式。`,
|
||
success: false
|
||
};
|
||
}
|
||
|
||
const url = `https://zjz.114kaili.com:200/webapi/AddUsersIntegral` +
|
||
`?business_id=2&users_id=${userId}&remark=%E7%AD%BE%E5%88%B0%E8%B5%A0%E7%A7%AF%E5%88%86&type=1` +
|
||
`&integral=${integral}&open_id=${openId}`;
|
||
|
||
const headers = {
|
||
Host: 'zjz.114kaili.com:200',
|
||
'User-Agent': 'Mozilla/5.0 (Linux; Android 15; Mi 10 Pro Build/AQ3A.240812.002; wv) AppleWebKit/5.0 (KHTML, like Gecko) Version/4.0 Chrome/122.0.6261.120 Mobile Safari/537.36 XWEB/1220067 MMWEBSDK/20230805 MMWEBID/909 MicroMessenger/8.0.42.29(0x28002A49) WeChat/arm64 Weixin GPVersion/1 Android Tablet NetType/WIFI Language/zh_CN ABI/arm64 MiniProgramEnv/android',
|
||
'content-type': 'application/x-www-form-urlencoded',
|
||
Referer: 'https://servicewechat.com/wx6da7c2450ef6e28f/4/page-frame.html'
|
||
};
|
||
|
||
let resultMessage = `账号 [${userId}]`;
|
||
let success = false;
|
||
|
||
try {
|
||
console.log(`正在为账号 [${userId}] 签到,使用积分: ${integral}`);
|
||
const { data } = await axios.post(url, '', { headers, timeout: 10000 });
|
||
|
||
console.log(`账号 [${userId}] 返回:`, JSON.stringify(data));
|
||
|
||
if (data.Status === 1) {
|
||
resultMessage += ` ✅ 签到成功(积分:${integral}): ${data.Message || '操作成功'}`;
|
||
success = true;
|
||
} else if (data.Message && data.Message.includes('今天已签到')) {
|
||
resultMessage += ` ❕ 操作提示: ${data.Message}`;
|
||
success = true; // 认为已签到也算成功,需要把积分 +1
|
||
} else if (data.Message) {
|
||
resultMessage += ` ❕ 操作提示: ${data.Message}`;
|
||
} else {
|
||
resultMessage += ` ❌ 操作失败:服务器返回未知状态`;
|
||
}
|
||
} catch (e) {
|
||
console.error(`❌ 账号 [${userId}] 请求异常:`, e.message);
|
||
resultMessage += ` ❌ 请求失败: ${e.message}`;
|
||
}
|
||
return { resultMessage, success };
|
||
}
|
||
// ================================
|
||
|
||
// ========== 入口 ==========
|
||
(async () => {
|
||
const taskName = '【维誉链】签到通知';
|
||
let notificationContent = '';
|
||
|
||
console.log(`===== 开始执行 ${taskName} =====`);
|
||
logSeparator();
|
||
|
||
if (!users.length) {
|
||
const err = '错误:未找到任何账号信息!\n请在环境变量里添加 WYL_USER_IDS';
|
||
console.log(err);
|
||
notificationContent = err;
|
||
} else {
|
||
let currentIntegral = readLastIntegral();
|
||
console.log(`共检测到 ${users.length} 个账号`);
|
||
console.log(`本次起始积分:${currentIntegral}`);
|
||
logSeparator();
|
||
|
||
const summary = [];
|
||
let firstSuccess = false;
|
||
|
||
for (let i = 0; i < users.length; i++) {
|
||
console.log(`--> 开始执行第 ${i + 1} 个账号`);
|
||
const { resultMessage, success } = await signIn(users[i], currentIntegral);
|
||
console.log(resultMessage);
|
||
summary.push(resultMessage);
|
||
|
||
if (success && !firstSuccess) {
|
||
firstSuccess = true;
|
||
const newIntegral = currentIntegral + 1;
|
||
saveIntegral(newIntegral);
|
||
console.log(`已自动把积分更新为 ${newIntegral}(下次使用)`);
|
||
}
|
||
logSeparator();
|
||
}
|
||
notificationContent = summary.join('\n');
|
||
console.log('✅ 所有账号任务已执行完毕');
|
||
}
|
||
|
||
if (sendNotify) {
|
||
try {
|
||
console.log('正在发送通知...');
|
||
await sendNotify(taskName, notificationContent);
|
||
console.log('通知发送成功!');
|
||
} catch (e) {
|
||
console.error('通知发送失败:', e);
|
||
}
|
||
} else {
|
||
console.log('未找到 sendNotify,跳过通知');
|
||
}
|
||
|
||
console.log(`===== ${taskName} 执行结束 =====`);
|
||
})(); |