mirror of
https://github.com/XiaoGe-LiBai/yangmao.git
synced 2025-12-19 01:04:35 +08:00
Update 维誉链.js
This commit is contained in:
167
维誉链.js
167
维誉链.js
@@ -2,129 +2,144 @@
|
|||||||
* @File: wyl_signin.js
|
* @File: wyl_signin.js
|
||||||
* @Author: Gemini
|
* @Author: Gemini
|
||||||
* @Date: 2025-10-02
|
* @Date: 2025-10-02
|
||||||
* @Description: 维誉链项目每日签到脚本,适配青龙面板,并支持运行后发送通知。
|
* @Description: 维誉链每日签到脚本(青龙面板/普通 Node 均可)
|
||||||
|
* 积分自动 +1,无需再设 WYL_INTEGRAL 环境变量
|
||||||
* cron: 0 0,12 * * *
|
* cron: 0 0,12 * * *
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// 引入 axios 依赖
|
// ========== 依赖 ==========
|
||||||
const axios = require('axios');
|
const axios = require('axios');
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
const { sendNotify } = require('./sendNotify'); // 通知文件路径保持与你原来一致
|
||||||
|
// =============================
|
||||||
|
|
||||||
// ======================= 主要修改点 =======================
|
// ========== 积分持久化 ==========
|
||||||
// 从旧版 sendNotify.js 导出的对象中,解构出 sendNotify 函数
|
const INTEGRAL_FILE = path.join(__dirname, '.wyl_integral'); // 存在脚本同目录
|
||||||
// 这样就可以兼容您的通知文件了
|
|
||||||
const { sendNotify } = require('./sendNotify');
|
|
||||||
// =======================================================
|
|
||||||
|
|
||||||
|
/* 读上次积分,文件不存在就给个默认值 100 */
|
||||||
|
function readLastIntegral() {
|
||||||
|
try {
|
||||||
|
return Number(fs.readFileSync(INTEGRAL_FILE, 'utf8').trim());
|
||||||
|
} catch {
|
||||||
|
return 100; // 首次运行起点,可自行修改
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// --- 配置区 ---
|
/* 把本次积分写盘,下次继续 +1 */
|
||||||
// 请在青龙面板 -> 环境变量 中添加新变量
|
function saveIntegral(val) {
|
||||||
// 名称: WYL_USER_IDS
|
fs.writeFileSync(INTEGRAL_FILE, String(val));
|
||||||
// 值: 你的用户ID (例如: 1003153)
|
}
|
||||||
// 备注: 维誉链签到
|
// =================================
|
||||||
//
|
|
||||||
// 多账号支持: 如果有多个账号,用 & 或者 换行符 分隔
|
|
||||||
|
|
||||||
const userIdsEnv = process.env.WYL_USER_IDS;
|
// ========== 配置区 ==========
|
||||||
const userIds = userIdsEnv ? userIdsEnv.split(/&|\n/).filter(id => !!id) : [];
|
const usersDataEnv = process.env.WYL_USER_IDS;
|
||||||
|
const users = usersDataEnv ? usersDataEnv.split(/&|\n/).filter(Boolean) : [];
|
||||||
|
// 不再需要 WYL_INTEGRAL 环境变量
|
||||||
|
// =============================
|
||||||
|
|
||||||
// --- 工具函数 ---
|
// ========== 工具 ==========
|
||||||
const logSeparator = () => console.log("-" .repeat(40));
|
const logSeparator = () => console.log('-'.repeat(40));
|
||||||
|
// ===========================
|
||||||
|
|
||||||
// --- 主逻辑 ---
|
// ========== 签到逻辑 ==========
|
||||||
|
async function signIn(userData, integral) {
|
||||||
/**
|
const [userId, openId] = userData.split('#');
|
||||||
* 为指定的用户ID执行签到操作,并返回结果字符串
|
if (!userId || !openId) {
|
||||||
* @param {string} userId - 用户ID
|
return {
|
||||||
* @returns {Promise<string>} 包含执行结果的单行消息
|
resultMessage: `账号 [${userData}] 格式错误,请使用 "用户ID#openId" 格式。`,
|
||||||
*/
|
success: false
|
||||||
async function signIn(userId) {
|
|
||||||
const url = `https://zjz.114kaili.com:200/webapi/AddUsersIntegral?users_id=${userId}&type=1`;
|
|
||||||
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'
|
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const config = {
|
const url = `https://zjz.114kaili.com:200/webapi/AddUsersIntegral` +
|
||||||
method: 'POST',
|
`?business_id=2&users_id=${userId}&remark=%E7%AD%BE%E5%88%B0%E8%B5%A0%E7%A7%AF%E5%88%86&type=1` +
|
||||||
url: url,
|
`&integral=${integral}&open_id=${openId}`;
|
||||||
headers: headers,
|
|
||||||
timeout: 10000 // 设置10秒超时
|
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 resultMessage = `账号 [${userId}]`;
|
||||||
|
let success = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
console.log(`正在为账号 [${userId}] 执行签到...`);
|
console.log(`正在为账号 [${userId}] 签到,使用积分: ${integral}`);
|
||||||
const response = await axios.request(config);
|
const { data } = await axios.post(url, '', { headers, timeout: 10000 });
|
||||||
const data = response.data;
|
|
||||||
|
|
||||||
console.log(`账号 [${userId}] 服务器返回:`, JSON.stringify(data));
|
console.log(`账号 [${userId}] 返回:`, JSON.stringify(data));
|
||||||
|
|
||||||
if (data.Status === 1) {
|
if (data.Status === 1) {
|
||||||
resultMessage += ` ✅ 签到成功: ${data.Message || '操作成功'}`;
|
resultMessage += ` ✅ 签到成功(积分:${integral}): ${data.Message || '操作成功'}`;
|
||||||
|
success = true;
|
||||||
|
} else if (data.Message && data.Message.includes('今天已签到')) {
|
||||||
|
resultMessage += ` ❕ 操作提示: ${data.Message}`;
|
||||||
|
success = true; // 认为已签到也算成功,需要把积分 +1
|
||||||
} else if (data.Message) {
|
} else if (data.Message) {
|
||||||
resultMessage += ` ❕ 操作提示: ${data.Message}`;
|
resultMessage += ` ❕ 操作提示: ${data.Message}`;
|
||||||
} else {
|
} else {
|
||||||
resultMessage += ` ❌ 操作失败: 服务器返回了未知状态。`;
|
resultMessage += ` ❌ 操作失败:服务器返回未知状态`;
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
} catch (error) {
|
console.error(`❌ 账号 [${userId}] 请求异常:`, e.message);
|
||||||
console.error(`❌ 账号 [${userId}] 请求发生严重错误:`);
|
resultMessage += ` ❌ 请求失败: ${e.message}`;
|
||||||
if (error.response) {
|
|
||||||
console.error(` - 状态码: ${error.response.status}, 返回数据: ${JSON.stringify(error.response.data)}`);
|
|
||||||
resultMessage += ` ❌ 请求失败: 服务器返回状态码 ${error.response.status}`;
|
|
||||||
} else if (error.request) {
|
|
||||||
console.error(' - 网络错误,服务器未响应。');
|
|
||||||
resultMessage += ` ❌ 请求失败: 服务器未响应`;
|
|
||||||
} else {
|
|
||||||
console.error(' - 请求配置错误:', error.message);
|
|
||||||
resultMessage += ` ❌ 请求失败: 脚本配置错误`;
|
|
||||||
}
|
}
|
||||||
}
|
return { resultMessage, success };
|
||||||
|
|
||||||
return resultMessage;
|
|
||||||
}
|
}
|
||||||
|
// ================================
|
||||||
|
|
||||||
// --- 任务入口 ---
|
// ========== 入口 ==========
|
||||||
(async () => {
|
(async () => {
|
||||||
|
const taskName = '【维誉链】签到通知';
|
||||||
let notificationContent = '';
|
let notificationContent = '';
|
||||||
const taskName = "【维誉链】签到通知";
|
|
||||||
|
|
||||||
console.log(`===== 开始执行${taskName} =====`);
|
console.log(`===== 开始执行 ${taskName} =====`);
|
||||||
logSeparator();
|
logSeparator();
|
||||||
|
|
||||||
if (userIds.length === 0) {
|
if (!users.length) {
|
||||||
const errorMsg = "错误: 未找到任何用户ID。\n请先在青龙面板【环境变量】中添加名为 WYL_USER_IDS 的变量。";
|
const err = '错误:未找到任何账号信息!\n请在环境变量里添加 WYL_USER_IDS';
|
||||||
console.log(errorMsg);
|
console.log(err);
|
||||||
notificationContent = errorMsg;
|
notificationContent = err;
|
||||||
} else {
|
} else {
|
||||||
console.log(`共检测到 ${userIds.length} 个账号,即将开始执行...`);
|
let currentIntegral = readLastIntegral();
|
||||||
|
console.log(`共检测到 ${users.length} 个账号`);
|
||||||
|
console.log(`本次起始积分:${currentIntegral}`);
|
||||||
logSeparator();
|
logSeparator();
|
||||||
|
|
||||||
let summary = [];
|
const summary = [];
|
||||||
for (let i = 0; i < userIds.length; i++) {
|
let firstSuccess = false;
|
||||||
|
|
||||||
|
for (let i = 0; i < users.length; i++) {
|
||||||
console.log(`--> 开始执行第 ${i + 1} 个账号`);
|
console.log(`--> 开始执行第 ${i + 1} 个账号`);
|
||||||
const result = await signIn(userIds[i]);
|
const { resultMessage, success } = await signIn(users[i], currentIntegral);
|
||||||
console.log(result);
|
console.log(resultMessage);
|
||||||
summary.push(result);
|
summary.push(resultMessage);
|
||||||
|
|
||||||
|
if (success && !firstSuccess) {
|
||||||
|
firstSuccess = true;
|
||||||
|
const newIntegral = currentIntegral + 1;
|
||||||
|
saveIntegral(newIntegral);
|
||||||
|
console.log(`已自动把积分更新为 ${newIntegral}(下次使用)`);
|
||||||
|
}
|
||||||
logSeparator();
|
logSeparator();
|
||||||
}
|
}
|
||||||
notificationContent = summary.join('\n');
|
notificationContent = summary.join('\n');
|
||||||
console.log("✅ 所有账号任务已执行完毕。");
|
console.log('✅ 所有账号任务已执行完毕');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 发送通知
|
|
||||||
// 您的旧版 sendNotify 函数需要两个参数: 标题(text) 和 内容(desp)
|
|
||||||
if (sendNotify) {
|
if (sendNotify) {
|
||||||
try {
|
try {
|
||||||
console.log("正在发送通知...");
|
console.log('正在发送通知...');
|
||||||
await sendNotify(taskName, notificationContent);
|
await sendNotify(taskName, notificationContent);
|
||||||
console.log("通知发送成功!");
|
console.log('通知发送成功!');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("通知发送失败:", e);
|
console.error('通知发送失败:', e);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log("未找到通知函数,请检查 sendNotify.js 文件。");
|
console.log('未找到 sendNotify,跳过通知');
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`===== ${taskName} 执行结束 =====`);
|
console.log(`===== ${taskName} 执行结束 =====`);
|
||||||
|
|||||||
Reference in New Issue
Block a user