diff --git a/daily/chery.js b/daily/chery.js index 300d4f7..65b2be4 100644 --- a/daily/chery.js +++ b/daily/chery.js @@ -7,8 +7,8 @@ cron: 8 30 * * * ------------------------------------------ #Notice: APP 抓包的登录接口uaa2c.chery.cn 里面的返回的access_token就是环境变量需要的token,多个账号换行或者& - - +自助获取变量 +https://logintools.smallfawn.top/chery.html ⚠️【免责声明】 ------------------------------------------ 1、此脚本仅用于学习研究,不保证其合法性、准确性、有效性,请根据情况自行判断,本人对此不承担任何保证责任。 @@ -20,7 +20,7 @@ APP 抓包的登录接口uaa2c.chery.cn 里面的返回的access_token就是环 7、所有直接或间接使用、查看此脚本的人均应该仔细阅读此声明。本人保留随时更改或补充此声明的权利。一旦您使用或复制了此脚本,即视为您已接受此免责声明。 */ -const { Env } = require("./tools/env") +const { Env } = require("../tools/env") const $ = new Env("奇瑞汽车"); let ckName = `chery`; const strSplitor = "#"; diff --git a/daily/ddsy.js b/daily/ddsy.js new file mode 100644 index 0000000..d694387 --- /dev/null +++ b/daily/ddsy.js @@ -0,0 +1,152 @@ +/* +------------------------------------------ +@Author: sm +@Date: 2024.06.07 19:15 +@Description: ddky +cron: 9 30 * * * +------------------------------------------ +#Notice: +变量值:https://hapi.ddky.com/mcp/weixin/rest.htm?后面的loginToken&userId&uDate 多账户换行或者&分隔 +网页版登录 https://m.ddky.com/ +小程序登录叮当快药 +APP 都可以找到这三个值 +⚠️【免责声明】 +------------------------------------------ +1、此脚本仅用于学习研究,不保证其合法性、准确性、有效性,请根据情况自行判断,本人对此不承担任何保证责任。 +2、由于此脚本仅用于学习研究,您必须在下载后 24 小时内将所有内容从您的计算机或手机或任何存储设备中完全删除,若违反规定引起任何事件本人对此均不负责。 +3、请勿将此脚本用于任何商业或非法目的,若违反规定请自行对此负责。 +4、此脚本涉及应用与本人无关,本人对因此引起的任何隐私泄漏或其他后果不承担任何责任。 +5、本人对任何脚本引发的问题概不负责,包括但不限于由脚本错误引起的任何损失和损害。 +6、如果任何单位或个人认为此脚本可能涉嫌侵犯其权利,应及时通知并提供身份证明,所有权证明,我们将在收到认证文件确认后删除此脚本。 +7、所有直接或间接使用、查看此脚本的人均应该仔细阅读此声明。本人保留随时更改或补充此声明的权利。一旦您使用或复制了此脚本,即视为您已接受此免责声明。 +*/ + +const { Env } = require("./tools/env") +const $ = new Env("叮当快药"); +let ckName = `ddky`; +const strSplitor = "#"; +const axios = require("axios"); +const defaultUserAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 16_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/8.0.31(0x18001e31) NetType/WIFI Language/zh_CN miniProgram" + + +class Task { + constructor(env) { + this.index = $.userIdx++ + this.token = env.split(strSplitor)[0]; //单账号多变量分隔符 + + this.userId = env.split(strSplitor)[1]; + this.uDate = env.split(strSplitor)[2]; + + } + + async run() { + + await this.getSignInId() + } + + getSign(s) { + const crypto = require("crypto");//SIGN TYPE 1是签到 2是补签 + return crypto.createHash('md5').update(s).digest('hex'); + } + getTime() { + var now = new Date(); + var year = now.getFullYear() + , month = now.getMonth() + 1 + , day = now.getDate() + , hours = now.getHours() + , minutes = now.getMinutes() + , seconds = now.getSeconds(); + return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds; + } + getSignDay() { + var now = new Date(); + var year = now.getFullYear() + , month = now.getMonth() + 1 + , day = now.getDate() + return year + '-' + month + '-' + day + } + async getSignInId() { + const time = this.getTime() + const method = `ddky.promotion.signin.pageinfo` + const signDay = this.getSignDay() + const str = method + + `loginToken${this.token}` + + `method${method}` + + `platH5` + + `platformH5` + + `signDay${signDay}` + + `t${time}` + + `uDate${this.uDate}` + + `userId${this.userId}` + + `v1.0` + + `versionName4.9.0` + + `6C57AB91A1308E26B797F4CD382AC79D` + let sign = (this.getSign(str)).toUpperCase(); + let callbackStr = new Date().getTime() + try { + let options = { + url: `https://hapi.ddky.com/mcp/weixin/rest.htm?sign=${sign}&loginToken=${this.token}&method=${method}&plat=H5&platform=H5&signDay=${signDay}&t=${time}&uDate=${this.uDate}&userId=${this.userId}&v=1.0&versionName=4.9.0&callback=Zepto${callbackStr}`, + headers: {}, + } + let { data: response } = await axios.request(options); + let result = response.replace(`Zepto${callbackStr}`, "") + result = result.replaceAll("(", "") + result = result.replaceAll(")", "") + result = JSON.parse(result) + if (result.code = "0") { + await this.user_info(result.result.signDayVo.signinId) + } + + } catch (e) { + console.log(e); + } + } + async user_info(signInId) { + let callbackStr = new Date().getTime() + const time = this.getTime() + const str = `ddky.promotion.signin.sign` + `channelH5` + `laterSignType1` + `loginToken${this.token}` + `methodddky.promotion.signin.sign` + + `platH5` + `platformH5` + `signinId${signInId}` + `t${time}` + `uDate${this.uDate}` + `userId${this.userId}` + `v1.0` + `versionName4.9.0` + + `6C57AB91A1308E26B797F4CD382AC79D` + let sign = (this.getSign(str)).toUpperCase(); + try { + let options = { + url: `https://hapi.ddky.com/mcp/weixin/rest.htm?sign=${sign}&channel=H5&laterSignType=1&loginToken=${this.token}&method=ddky.promotion.signin.sign&plat=H5&platform=H5&signinId=${signInId}&t=${time}&uDate=${this.uDate}&userId=${this.userId}&v=1.0&versionName=4.9.0&callback=Zepto${callbackStr}`, + headers: {}, + } + let { data: response } = await axios.request(options); + console.log(response); + } catch (e) { + console.log(e); + } + } + + + + + + + +} + +!(async () => { + await getNotice() + $.checkEnv(ckName); + + for (let user of $.userList) { + await new Task(user).run(); + } +})() + .catch((e) => console.log(e)) + .finally(() => $.done()); + +async function getNotice() { + let options = { + url: `https://ghproxy.net/https://raw.githubusercontent.com/smallfawn/Note/refs/heads/main/Notice.json`, + headers: { + "User-Agent": defaultUserAgent, + } + } + let { data: res } = await axios.request(options); + $.log(res) + return res +} \ No newline at end of file diff --git a/dayuecheng.js b/dayuecheng.js deleted file mode 100644 index e90cb46..0000000 --- a/dayuecheng.js +++ /dev/null @@ -1,454 +0,0 @@ -/* - * 大悦城自动任务脚本 for 青龙面板 - * 环境变量:dyc - * 格式:MallId#Token#PublicKey#mpOpenId - * 多账号:MallId#Token#PublicKey#mpOpenId&MallId#Token#PublicKey#mpOpenId - * - * 功能说明: - * 1. 检查用户状态 - * 2. 自动签到 - * 3. 获取积分信息 - */ - -const $ = new Env("大悦城自动任务"); -const notify = $.isNode() ? require("./sendNotify") : ""; - -// 环境变量名 -const envName = "dyc"; - -// 固定参数 -const mpAppId = "wxc1f0da607b34c3bd"; -const systemInfo = { - model: "microsoft", - SDKVersion: "3.13.1", - system: "Windows 10 x64", - version: "4.1.6.46", - miniVersion: "1.0.96" -}; - -class Dayuecheng { - constructor(mallId, token, publicKey, mpOpenId) { - this.mallId = mallId; - this.token = token; - this.publicKey = publicKey; - this.mpOpenId = mpOpenId; - this.baseUrl = "https://m-crm.joycity.mobi/api"; - this.headers = { - "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36 MicroMessenger/7.0.20.1781(0x6700143B) NetType/WIFI MiniProgramEnv/Windows WindowsWechat/WMPF WindowsWechat(0x63090a13) UnifiedPCWindowsWechat(0xf254162e) XWEB/18151", - "Content-Type": "application/json", - "Accept": "*/*", - "Referer": "https://servicewechat.com/wxc1f0da607b34c3bd/40/page-frame.html", - "xweb_xhr": "1" - }; - this.retryCount = 3; - this.retryDelay = 2000; - } - - generateSign(timestamp, data) { - const crypto = require("crypto"); - let signStr = timestamp + this.publicKey; - - if (data && data.trim() !== "") { - signStr += data; - } - - return crypto.createHash("md5").update(signStr).digest("hex"); - } - - generateSignAndTimestamp(data = "") { - const timestamp = Date.now().toString(); - const sign = this.generateSign(timestamp, data); - return { sign, timestamp }; - } - - async requestWithRetry(path, data, method = "POST", retry = this.retryCount) { - let lastError; - - for (let i = 0; i < retry; i++) { - try { - if (i > 0) { - $.log(`🔄 第${i + 1}次重试请求: ${path}`); - await $.wait(this.retryDelay); - } - - return await this.request(path, data, method); - } catch (error) { - lastError = error; - $.log(`⚠️ 请求失败 (${i + 1}/${retry}): ${error.message}`); - - if (error.code === 'ECONNABORTED' || error.code === 'ENETUNREACH' || - error.code === 'ETIMEDOUT' || error.message.includes('timeout')) { - continue; - } - - break; - } - } - - throw lastError || new Error(`请求失败,重试${retry}次后仍然失败`); - } - - async request(path, data, method = "POST") { - const { sign, timestamp } = this.generateSignAndTimestamp(JSON.stringify(data)); - - const headers = { - ...this.headers, - "Sign": sign, - "Timestamp": timestamp, - "PublicKey": this.publicKey - }; - - let requestData = {}; - - if (path.includes("getSnsInfo")) { - requestData = { - MallId: this.mallId, - mpAppId: mpAppId, - mpOpenId: this.mpOpenId, - Header: { - Token: this.token, - systemInfo: systemInfo - } - }; - } else { - requestData = { - MallID: this.mallId, - Header: { - Token: this.token, - systemInfo: systemInfo - } - }; - } - - if (data && typeof data === 'object') { - requestData = { ...requestData, ...data }; - } - - try { - const response = await $.httpRequest({ - url: `${this.baseUrl}${path}`, - method: method, - headers: headers, - data: JSON.stringify(requestData), - timeout: 15000 - }); - - const result = typeof response.data === "object" ? response.data : JSON.parse(response.data); - - $.log(`📡 ${method} ${path} -> ${result.m === 1 ? '成功' : '失败'}`); - - return result; - } catch (error) { - $.log(`❌ 请求异常: ${error.message}`); - throw error; - } - } - - async checkUserStatus() { - $.log("🔍 检查用户状态..."); - try { - const result = await this.requestWithRetry("/passport/wx/mp/getSnsInfo", {}); - - if (result.m === 1) { - const authorized = result.d?.authorized; - if (authorized) { - $.log("✅ 用户状态正常"); - return { success: true, data: result.d }; - } else { - $.log("❌ 用户授权已失效"); - return { success: false, message: "用户授权已失效" }; - } - } else if (result.code === 401 || result.status === 401) { - $.log("❌ Token已过期,需要重新获取"); - return { success: false, message: "Token已过期" }; - } else { - $.log(`❌ 检查用户状态失败: ${result.e || "未知错误"}`); - return { success: false, message: result.e || "未知错误" }; - } - } catch (error) { - $.log(`❌ 检查用户状态异常: ${error.message}`); - return { success: false, message: error.message }; - } - } - - async autoCheckin() { - $.log("🔍 开始签到..."); - try { - const result = await this.requestWithRetry("/user/User/CheckinV2", {}); - - if (result.m === 1) { - const data = result.d; - if (data.IsCheckIn) { - $.log(`✅ 签到成功: ${data.Msg || "签到完成"}`); - if (data.NickName) { - $.log(`👤 用户: ${data.NickName}`); - } - if (data.Title) { - $.log(`📝 ${data.Title}`); - } - return { success: true, data: data }; - } else { - $.log(`❌ 签到失败: ${data.Msg || "未知原因"}`); - return { success: false, message: data.Msg || "未知原因" }; - } - } else { - $.log(`❌ 签到接口调用失败: ${result.e || "未知错误"}`); - return { success: false, message: result.e || "未知错误" }; - } - } catch (error) { - $.log(`❌ 签到异常: ${error.message}`); - return { success: false, message: error.message }; - } - } - - async getUserPoints() { - $.log("🔍 获取用户积分..."); - try { - const result = await this.requestWithRetry("/user/user/GetMallCard_Encrypt", {}); - - if (result.m === 1) { - const data = result.d; - const points = data.Bonus; - $.log(`💰 当前积分: ${points}`); - if (data.CardTitle) { - $.log(`🎫 卡片类型: ${data.CardTitle}`); - } - if (data.CardLevel) { - $.log(`⭐ 卡片等级: ${data.CardLevel}`); - } - return { success: true, points: points, data: data }; - } else { - $.log(`❌ 获取积分失败: ${result.e || "未知错误"}`); - return { success: false, message: result.e || "未知错误" }; - } - } catch (error) { - $.log(`❌ 获取积分异常: ${error.message}`); - return { success: false, message: error.message }; - } - } - - async runAllTasks() { - $.log(`🏪 开始处理大悦城账号: ${this.mallId}`); - - const taskResults = []; - - const statusResult = await this.checkUserStatus(); - taskResults.push({ name: "用户状态检查", success: statusResult.success }); - - if (!statusResult.success) { - $.log("❌ 用户状态异常,跳过后续任务"); - return { - success: false, - message: statusResult.message || "用户状态异常", - taskResults: taskResults - }; - } - - const checkinResult = await this.autoCheckin(); - taskResults.push({ name: "自动签到", success: checkinResult.success }); - - const pointsResult = await this.getUserPoints(); - taskResults.push({ name: "获取积分", success: pointsResult.success }); - - const successCount = taskResults.filter(r => r.success).length; - const totalCount = taskResults.length; - - $.log(`\n📊 任务执行汇总: ${successCount}/${totalCount} 成功`); - taskResults.forEach((task, index) => { - $.log(`${task.success ? '✅' : '❌'} ${index + 1}. ${task.name}`); - }); - - return { - success: successCount === totalCount, - taskResults: taskResults, - summary: { - successCount: successCount, - totalCount: totalCount, - mallId: this.mallId, - publicKey: this.publicKey, - mpOpenId: this.mpOpenId - } - }; - } -} - -function Env(name) { - this.name = name; - this.logs = []; - - this.log = (...args) => { - const msg = args.join(" "); - const timestamp = new Date().toLocaleTimeString(); - const logMsg = `[${timestamp}] ${msg}`; - this.logs.push(logMsg); - console.log(logMsg); - }; - - this.isNode = () => { - return typeof process !== "undefined" && process.release && process.release.name === 'node'; - }; - - this.getdata = (key) => { - if (this.isNode()) { - return process.env[key] || ""; - } - return ""; - }; - - this.wait = (ms) => { - return new Promise(resolve => setTimeout(resolve, ms)); - }; - - this.httpRequest = async (config) => { - if (this.isNode()) { - const axios = require('axios'); - try { - const response = await axios({ - ...config, - validateStatus: function (status) { - return status >= 200 && status < 500; - } - }); - return response; - } catch (error) { - throw error; - } - } else { - throw new Error("非Node环境不支持HTTP请求"); - } - }; - - this.done = () => { - if (this.isNode()) { - process.exit(0); - } - }; -} - -async function main() { - const envValue = $.getdata(envName); - if (!envValue) { - $.log(`❌ 未找到环境变量 ${envName}`); - $.log(`💡 请添加环境变量 ${envName},格式: MallId#Token#PublicKey#mpOpenId`); - $.log(`📝 多账号格式: MallId#Token#PublicKey#mpOpenId&MallId#Token#PublicKey#mpOpenId`); - return; - } - - const accounts = []; - const accountStrings = envValue.split('&').filter(Boolean); - - for (const accountStr of accountStrings) { - const parts = accountStr.split('#'); - if (parts.length === 4) { - const mallId = parts[0].trim(); - const token = parts[1].trim(); - const publicKey = parts[2].trim(); - const mpOpenId = parts[3].trim(); - - if (mallId && token && publicKey && mpOpenId) { - accounts.push({ mallId, token, publicKey, mpOpenId }); - } else { - $.log(`⚠️ 忽略无效账号格式: ${accountStr}`); - } - } else { - $.log(`⚠️ 忽略格式错误的账号(需要4个参数): ${accountStr}`); - } - } - - if (accounts.length === 0) { - $.log("❌ 未找到有效的账号配置"); - $.log("💡 正确格式: MallId#Token#PublicKey#mpOpenId"); - $.log("💡 多账号: MallId#Token#PublicKey#mpOpenId&MallId#Token#PublicKey#mpOpenId"); - return; - } - - $.log(`🎯 共找到 ${accounts.length} 个有效账号`); - - const allResults = []; - - for (let i = 0; i < accounts.length; i++) { - const account = accounts[i]; - $.log(`\n📱 开始处理第 ${i + 1} 个账号 (MallId: ${account.mallId})`); - - try { - const dyc = new Dayuecheng(account.mallId, account.token, account.publicKey, account.mpOpenId); - const result = await dyc.runAllTasks(); - - allResults.push({ - mallId: account.mallId, - ...result - }); - - if (i < accounts.length - 1) { - $.log(`⏳ 等待3秒后处理下一个账号...`); - await $.wait(3000); - } - } catch (error) { - $.log(`❌ 处理账号异常: ${error.message}`); - allResults.push({ - mallId: account.mallId, - success: false, - error: error.message, - taskResults: [] - }); - } - } - - $.log("\n" + "=".repeat(60)); - $.log("📈 所有账号任务执行汇总:"); - $.log("=".repeat(60)); - - let totalSuccess = 0; - let totalTasks = 0; - - allResults.forEach((result, index) => { - const successCount = result.taskResults ? result.taskResults.filter(r => r.success).length : 0; - const totalCount = result.taskResults ? result.taskResults.length : 0; - - $.log(`\n账号 ${index + 1} (MallId: ${result.mallId}):`); - $.log(` ${result.success ? '✅ 成功' : '❌ 失败'} (${successCount}/${totalCount} 任务成功)`); - - if (result.taskResults) { - result.taskResults.forEach((task, taskIndex) => { - $.log(` ${task.success ? '✅' : '❌'} ${task.name}`); - }); - } - - if (result.error) { - $.log(` 错误: ${result.error}`); - } - - totalSuccess += successCount; - totalTasks += totalCount; - }); - - $.log("\n" + "=".repeat(60)); - $.log(`📊 总体统计: ${totalSuccess}/${totalTasks} 个任务成功完成`); - $.log("=".repeat(60)); - - if ($.isNode() && notify) { - try { - const summaryText = allResults.map(r => { - const successCount = r.taskResults ? r.taskResults.filter(t => t.success).length : 0; - const totalCount = r.taskResults ? r.taskResults.length : 0; - return `MallId: ${r.mallId} - ${successCount}/${totalCount} 成功`; - }).join('\n'); - - const title = `大悦城自动任务 - ${allResults.filter(r => r.success).length}/${allResults.length} 个账号成功`; - const content = $.logs.join("\n") + "\n\n" + summaryText; - - await notify.sendNotify(title, content); - } catch (error) { - $.log(`⚠️ 发送通知失败: ${error.message}`); - } - } -} - -if (require.main === module) { - main().catch(e => { - $.log(`❌ 脚本执行异常: ${e.message}`); - console.error(e.stack); - }).finally(() => { - $.done(); - }); -} diff --git a/ddsy_songyao.js b/ddsy_songyao.js deleted file mode 100644 index 0c02e25..0000000 --- a/ddsy_songyao.js +++ /dev/null @@ -1,180 +0,0 @@ -/** - * cron 27 19 * * * ddsy_songyao.js - * Show:叮当快药APP 积分抵钱 我的=>签到有礼 - * 变量名:ddsy_songyao - * 变量值:https://hapi.ddky.com/mcp/weixin/rest.htm?后面的loginToken&userId&uDate 多账户@ - * scriptVersionNow = "0.0.1"; - * / - */ - -const $ = new Env("叮当快药APP"); -const notify = $.isNode() ? require('./sendNotify') : ''; -let ckName = "ddsy_songyao"; -let envSplitor = ["@", "\n"]; //多账号分隔符 -let strSplitor = "&"; //多变量分隔符 -let userIdx = 0; -let userList = []; -class UserInfo { - constructor(str) { - this.index = ++userIdx; - this.token = str.split(strSplitor)[0]; //单账号多变量分隔符 - this.ckStatus = true; - this.userId = str.split(strSplitor)[1]; - this.uDate = str.split(strSplitor)[2]; - } - async main() { - await this.getSignInId() - } - getSign(s) { - const crypto = require("crypto");//SIGN TYPE 1是签到 2是补签 - return crypto.createHash('md5').update(s).digest('hex'); - } - getTime() { - var now = new Date(); - var year = now.getFullYear() - , month = now.getMonth() + 1 - , day = now.getDate() - , hours = now.getHours() - , minutes = now.getMinutes() - , seconds = now.getSeconds(); - return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds; - } - getSignDay() { - var now = new Date(); - var year = now.getFullYear() - , month = now.getMonth() + 1 - , day = now.getDate() - return year + '-' + month + '-' + day - } - async getSignInId() { - const time = this.getTime() - const method = `ddky.promotion.signin.pageinfo` - const signDay = this.getSignDay() - const str = method + - `loginToken${this.token}` + - `method${method}` + - `platH5` + - `platformH5` + - `signDay${signDay}` + - `t${time}` + - `uDate${this.uDate}` + - `userId${this.userId}` + - `v1.0` + - `versionName4.9.0` + - `6C57AB91A1308E26B797F4CD382AC79D` - let sign = (this.getSign(str)).toUpperCase(); - let callbackStr = new Date().getTime() - try { - let options = { - url: `https://hapi.ddky.com/mcp/weixin/rest.htm?sign=${sign}&loginToken=${this.token}&method=${method}&plat=H5&platform=H5&signDay=${signDay}&t=${time}&uDate=${this.uDate}&userId=${this.userId}&v=1.0&versionName=4.9.0&callback=Zepto${callbackStr}`, - headers: {}, - }, - result = await httpRequest(options); - //console.log(options); - result = result.replace(`Zepto${callbackStr}`, "") - result = result.replaceAll("(", "") - result = result.replaceAll(")", "") - result = JSON.parse(result) - if(result.code = "0"){ - console.log(result.result.signDayVo.signinId); - await this.user_info(result.result.signDayVo.signinId) - } - - } catch (e) { - console.log(e); - } - } - async user_info(signInId) { - let callbackStr = new Date().getTime() - - const time = this.getTime() - const str = `ddky.promotion.signin.sign` + `channelH5` + `laterSignType1` + `loginToken${this.token}` + `methodddky.promotion.signin.sign` + - `platH5` + `platformH5` + `signinId${signInId}` + `t${time}` + `uDate${this.uDate}` + `userId${this.userId}` + `v1.0` + `versionName4.9.0` + - `6C57AB91A1308E26B797F4CD382AC79D` - let sign = (this.getSign(str)).toUpperCase(); - try { - let options = { - url: `https://hapi.ddky.com/mcp/weixin/rest.htm?sign=${sign}&channel=H5&laterSignType=1&loginToken=${this.token}&method=ddky.promotion.signin.sign&plat=H5&platform=H5&signinId=${signInId}&t=${time}&uDate=${this.uDate}&userId=${this.userId}&v=1.0&versionName=4.9.0&callback=Zepto${callbackStr}`, - headers: {}, - }, - result = await httpRequest(options); - //console.log(options); - console.log(result); - } catch (e) { - console.log(e); - } - } -} - -async function start() { - let taskall = []; - for (let user of userList) { - if (user.ckStatus) { - taskall.push(await user.main()); - } - } - await Promise.all(taskall); -} - -!(async () => { - if (!(await checkEnv())) return; - if (userList.length > 0) { - await start(); - } -})() - .catch((e) => console.log(e)) - .finally(() => $.done()); - -//******************************************************** -/** - * 变量检查与处理 - * @returns - */ -async function checkEnv() { - let userCookie = ($.isNode() ? process.env[ckName] : $.getdata(ckName)) || ""; - if (userCookie) { - let e = envSplitor[0]; - for (let o of envSplitor) - if (userCookie.indexOf(o) > -1) { - e = o; - break; - } - for (let n of userCookie.split(e)) n && userList.push(new UserInfo(n)); - } else { - console.log("未找到CK"); - return; - } - return console.log(`共找到${userList.length}个账号`), true; //true == !0 -} - -///////////////////////////////////////////////////////////////////////////////////// -function httpRequest(options, timeout = 5 * 1000) { - method = options.method - ? options.method.toLowerCase() - : options.body - ? "post" - : "get"; - return new Promise((resolve) => { - setTimeout(() => { - $[method](options, (err, resp, data) => { - try { - if (err) { - console.log(JSON.stringify(err)); - $.logErr(err); - } else { - try { - data = JSON.parse(data); - } catch (error) { } - } - } catch (e) { - console.log(e); - $.logErr(e, resp); - } finally { - resolve(data); - } - }); - }, timeout); - }); -} -// prettier-ignore -function Env(t, s) { return new (class { constructor(t, s) { (this.name = t), (this.data = null), (this.dataFile = "box.dat"), (this.logs = []), (this.logSeparator = "\n"), (this.startTime = new Date().getTime()), Object.assign(this, s), this.log("", `\ud83d\udd14${this.name},\u5f00\u59cb!`) } isNode() { return "undefined" != typeof module && !!module.exports } isQuanX() { return "undefined" != typeof $task } isSurge() { return "undefined" != typeof $httpClient && "undefined" == typeof $loon } isLoon() { return "undefined" != typeof $loon } getScript(t) { return new Promise((s) => { this.get({ url: t }, (t, e, i) => s(i)) }) } runScript(t, s) { return new Promise((e) => { let i = this.getdata("@chavy_boxjs_userCfgs.httpapi"); i = i ? i.replace(/\n/g, "").trim() : i; let o = this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout"); (o = o ? 1 * o : 20), (o = s && s.timeout ? s.timeout : o); const [h, a] = i.split("@"), r = { url: `http://${a}/v1/scripting/evaluate`, body: { script_text: t, mock_type: "cron", timeout: o }, headers: { "X-Key": h, Accept: "*/*" }, }; this.post(r, (t, s, i) => e(i)) }).catch((t) => this.logErr(t)) } loaddata() { if (!this.isNode()) return {}; { (this.fs = this.fs ? this.fs : require("fs")), (this.path = this.path ? this.path : require("path")); const t = this.path.resolve(this.dataFile), s = this.path.resolve(process.cwd(), this.dataFile), e = this.fs.existsSync(t), i = !e && this.fs.existsSync(s); if (!e && !i) return {}; { const i = e ? t : s; try { return JSON.parse(this.fs.readFileSync(i)) } catch (t) { return {} } } } } writedata() { if (this.isNode()) { (this.fs = this.fs ? this.fs : require("fs")), (this.path = this.path ? this.path : require("path")); const t = this.path.resolve(this.dataFile), s = this.path.resolve(process.cwd(), this.dataFile), e = this.fs.existsSync(t), i = !e && this.fs.existsSync(s), o = JSON.stringify(this.data); e ? this.fs.writeFileSync(t, o) : i ? this.fs.writeFileSync(s, o) : this.fs.writeFileSync(t, o) } } lodash_get(t, s, e) { const i = s.replace(/\[(\d+)\]/g, ".$1").split("."); let o = t; for (const t of i) if (((o = Object(o)[t]), void 0 === o)) return e; return o } lodash_set(t, s, e) { return Object(t) !== t ? t : (Array.isArray(s) || (s = s.toString().match(/[^.[\]]+/g) || []), (s.slice(0, -1).reduce((t, e, i) => Object(t[e]) === t[e] ? t[e] : (t[e] = Math.abs(s[i + 1]) >> 0 == +s[i + 1] ? [] : {}), t)[s[s.length - 1]] = e), t) } getdata(t) { let s = this.getval(t); if (/^@/.test(t)) { const [, e, i] = /^@(.*?)\.(.*?)$/.exec(t), o = e ? this.getval(e) : ""; if (o) try { const t = JSON.parse(o); s = t ? this.lodash_get(t, i, "") : s } catch (t) { s = "" } } return s } setdata(t, s) { let e = !1; if (/^@/.test(s)) { const [, i, o] = /^@(.*?)\.(.*?)$/.exec(s), h = this.getval(i), a = i ? ("null" === h ? null : h || "{}") : "{}"; try { const s = JSON.parse(a); this.lodash_set(s, o, t), (e = this.setval(JSON.stringify(s), i)) } catch (s) { const h = {}; this.lodash_set(h, o, t), (e = this.setval(JSON.stringify(h), i)) } } else e = this.setval(t, s); return e } getval(t) { return this.isSurge() || this.isLoon() ? $persistentStore.read(t) : this.isQuanX() ? $prefs.valueForKey(t) : this.isNode() ? ((this.data = this.loaddata()), this.data[t]) : (this.data && this.data[t]) || null } setval(t, s) { return this.isSurge() || this.isLoon() ? $persistentStore.write(t, s) : this.isQuanX() ? $prefs.setValueForKey(t, s) : this.isNode() ? ((this.data = this.loaddata()), (this.data[s] = t), this.writedata(), !0) : (this.data && this.data[s]) || null } initGotEnv(t) { (this.got = this.got ? this.got : require("got")), (this.cktough = this.cktough ? this.cktough : require("tough-cookie")), (this.ckjar = this.ckjar ? this.ckjar : new this.cktough.CookieJar()), t && ((t.headers = t.headers ? t.headers : {}), void 0 === t.headers.Cookie && void 0 === t.cookieJar && (t.cookieJar = this.ckjar)) } get(t, s = () => { }) { t.headers && (delete t.headers["Content-Type"], delete t.headers["Content-Length"]), this.isSurge() || this.isLoon() ? $httpClient.get(t, (t, e, i) => { !t && e && ((e.body = i), (e.statusCode = e.status)), s(t, e, i) }) : this.isQuanX() ? $task.fetch(t).then((t) => { const { statusCode: e, statusCode: i, headers: o, body: h } = t; s(null, { status: e, statusCode: i, headers: o, body: h }, h) }, (t) => s(t)) : this.isNode() && (this.initGotEnv(t), this.got(t).on("redirect", (t, s) => { try { const e = t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString(); this.ckjar.setCookieSync(e, null), (s.cookieJar = this.ckjar) } catch (t) { this.logErr(t) } }).then((t) => { const { statusCode: e, statusCode: i, headers: o, body: h, } = t; s(null, { status: e, statusCode: i, headers: o, body: h }, h) }, (t) => s(t))) } post(t, s = () => { }) { if ((t.body && t.headers && !t.headers["Content-Type"] && (t.headers["Content-Type"] = "application/x-www-form-urlencoded"), delete t.headers["Content-Length"], this.isSurge() || this.isLoon())) $httpClient.post(t, (t, e, i) => { !t && e && ((e.body = i), (e.statusCode = e.status)), s(t, e, i) }); else if (this.isQuanX()) (t.method = "POST"), $task.fetch(t).then((t) => { const { statusCode: e, statusCode: i, headers: o, body: h } = t; s(null, { status: e, statusCode: i, headers: o, body: h }, h) }, (t) => s(t)); else if (this.isNode()) { this.initGotEnv(t); const { url: e, ...i } = t; this.got.post(e, i).then((t) => { const { statusCode: e, statusCode: i, headers: o, body: h } = t; s(null, { status: e, statusCode: i, headers: o, body: h }, h) }, (t) => s(t)) } } time(t) { let s = { "M+": new Date().getMonth() + 1, "d+": new Date().getDate(), "H+": new Date().getHours(), "m+": new Date().getMinutes(), "s+": new Date().getSeconds(), "q+": Math.floor((new Date().getMonth() + 3) / 3), S: new Date().getMilliseconds(), }; /(y+)/.test(t) && (t = t.replace(RegExp.$1, (new Date().getFullYear() + "").substr(4 - RegExp.$1.length))); for (let e in s) new RegExp("(" + e + ")").test(t) && (t = t.replace(RegExp.$1, 1 == RegExp.$1.length ? s[e] : ("00" + s[e]).substr(("" + s[e]).length))); return t } msg(s = t, e = "", i = "", o) { const h = (t) => !t || (!this.isLoon() && this.isSurge()) ? t : "string" == typeof t ? this.isLoon() ? t : this.isQuanX() ? { "open-url": t } : void 0 : "object" == typeof t && (t["open-url"] || t["media-url"]) ? this.isLoon() ? t["open-url"] : this.isQuanX() ? t : void 0 : void 0; this.isMute || (this.isSurge() || this.isLoon() ? $notification.post(s, e, i, h(o)) : this.isQuanX() && $notify(s, e, i, h(o))), this.logs.push("", "==============\ud83d\udce3\u7cfb\u7edf\u901a\u77e5\ud83d\udce3=============="), this.logs.push(s), e && this.logs.push(e), i && this.logs.push(i) } log(...t) { t.length > 0 && (this.logs = [...this.logs, ...t]), console.log(t.join(this.logSeparator)) } logErr(t, s) { const e = !this.isSurge() && !this.isQuanX() && !this.isLoon(); e ? this.log("", `\u2757\ufe0f${this.name},\u9519\u8bef!`, t.stack) : this.log("", `\u2757\ufe0f${this.name},\u9519\u8bef!`, t) } wait(t) { return new Promise((s) => setTimeout(s, t)) } done(t = {}) { const s = new Date().getTime(), e = (s - this.startTime) / 1e3; this.log("", `\ud83d\udd14${this.name},\u7ed3\u675f!\ud83d\udd5b ${e}\u79d2`), this.log(), (this.isSurge() || this.isQuanX() || this.isLoon()) && $done(t) } })(t, s) }