diff --git a/function/.DS_Store b/function/.DS_Store new file mode 100644 index 0000000..ff78b20 Binary files /dev/null and b/function/.DS_Store differ diff --git a/function/TS_USER_AGENTS.ts b/function/TS_USER_AGENTS.ts new file mode 100644 index 0000000..fccc43a --- /dev/null +++ b/function/TS_USER_AGENTS.ts @@ -0,0 +1,341 @@ +import axios from "axios" +import {Md5} from "ts-md5" +import * as dotenv from "dotenv" +import {existsSync, readFileSync} from "fs" +import {sendNotify} from './sendNotify' + +dotenv.config() + +let fingerprint: string | number, token: string = '', enCryptMethodJD: any + +const USER_AGENTS: Array = [ + "jdapp;android;10.0.2;10;network/wifi;Mozilla/5.0 (Linux; Android 10; ONEPLUS A5010 Build/QKQ1.191014.012; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.120 MQQBrowser/6.2 TBS/045230 Mobile Safari/537.36", + "jdapp;iPhone;10.0.2;14.3;network/4g;Mozilla/5.0 (iPhone; CPU iPhone OS 14_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1", + "jdapp;android;10.0.2;9;network/4g;Mozilla/5.0 (Linux; Android 9; Mi Note 3 Build/PKQ1.181007.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/66.0.3359.126 MQQBrowser/6.2 TBS/045131 Mobile Safari/537.36", + "jdapp;android;10.0.2;10;network/wifi;Mozilla/5.0 (Linux; Android 10; GM1910 Build/QKQ1.190716.003; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.120 MQQBrowser/6.2 TBS/045230 Mobile Safari/537.36", + "jdapp;android;10.0.2;9;network/wifi;Mozilla/5.0 (Linux; Android 9; 16T Build/PKQ1.190616.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/66.0.3359.126 MQQBrowser/6.2 TBS/044942 Mobile Safari/537.36", + "jdapp;iPhone;10.0.2;13.6;network/wifi;Mozilla/5.0 (iPhone; CPU iPhone OS 13_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1", + "jdapp;iPhone;10.0.2;13.6;network/wifi;Mozilla/5.0 (iPhone; CPU iPhone OS 13_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1", + "jdapp;iPhone;10.0.2;13.5;network/wifi;Mozilla/5.0 (iPhone; CPU iPhone OS 13_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1", + "jdapp;iPhone;10.0.2;14.1;network/wifi;Mozilla/5.0 (iPhone; CPU iPhone OS 14_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1", + "jdapp;iPhone;10.0.2;13.3;network/wifi;Mozilla/5.0 (iPhone; CPU iPhone OS 13_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1", + "jdapp;iPhone;10.0.2;13.7;network/wifi;Mozilla/5.0 (iPhone; CPU iPhone OS 13_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1", + "jdapp;iPhone;10.0.2;14.1;network/wifi;Mozilla/5.0 (iPhone; CPU iPhone OS 14_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1", + "jdapp;iPhone;10.0.2;13.3;network/wifi;Mozilla/5.0 (iPhone; CPU iPhone OS 13_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1", + "jdapp;iPhone;10.0.2;13.4;network/wifi;Mozilla/5.0 (iPhone; CPU iPhone OS 13_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1", + "jdapp;iPhone;10.0.2;14.3;network/wifi;Mozilla/5.0 (iPhone; CPU iPhone OS 14_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1", + "jdapp;android;10.0.2;9;network/wifi;Mozilla/5.0 (Linux; Android 9; MI 6 Build/PKQ1.190118.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/66.0.3359.126 MQQBrowser/6.2 TBS/044942 Mobile Safari/537.36", + "jdapp;android;10.0.2;11;network/wifi;Mozilla/5.0 (Linux; Android 11; Redmi K30 5G Build/RKQ1.200826.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.120 MQQBrowser/6.2 TBS/045511 Mobile Safari/537.36", + "jdapp;iPhone;10.0.2;11.4;network/wifi;Mozilla/5.0 (iPhone; CPU iPhone OS 11_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15F79", + "jdapp;android;10.0.2;10;;network/wifi;Mozilla/5.0 (Linux; Android 10; M2006J10C Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.120 MQQBrowser/6.2 TBS/045230 Mobile Safari/537.36", + "jdapp;android;10.0.2;10;network/wifi;Mozilla/5.0 (Linux; Android 10; M2006J10C Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.120 MQQBrowser/6.2 TBS/045230 Mobile Safari/537.36", + "jdapp;android;10.0.2;10;network/wifi;Mozilla/5.0 (Linux; Android 10; ONEPLUS A6000 Build/QKQ1.190716.003; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.120 MQQBrowser/6.2 TBS/045224 Mobile Safari/537.36", + "jdapp;android;10.0.2;9;network/wifi;Mozilla/5.0 (Linux; Android 9; MHA-AL00 Build/HUAWEIMHA-AL00; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/66.0.3359.126 MQQBrowser/6.2 TBS/044942 Mobile Safari/537.36", + "jdapp;android;10.0.2;8.1.0;network/wifi;Mozilla/5.0 (Linux; Android 8.1.0; 16 X Build/OPM1.171019.026; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/66.0.3359.126 MQQBrowser/6.2 TBS/044942 Mobile Safari/537.36", + "jdapp;android;10.0.2;8.0.0;network/wifi;Mozilla/5.0 (Linux; Android 8.0.0; HTC U-3w Build/OPR6.170623.013; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/66.0.3359.126 MQQBrowser/6.2 TBS/044942 Mobile Safari/537.36", + "jdapp;iPhone;10.0.2;14.0.1;network/wifi;Mozilla/5.0 (iPhone; CPU iPhone OS 14_0_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1", + "jdapp;android;10.0.2;10;network/wifi;Mozilla/5.0 (Linux; Android 10; LYA-AL00 Build/HUAWEILYA-AL00L; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.120 MQQBrowser/6.2 TBS/045230 Mobile Safari/537.36", + "jdapp;iPhone;10.0.2;14.2;network/wifi;Mozilla/5.0 (iPhone; CPU iPhone OS 14_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1", + "jdapp;iPhone;10.0.2;14.3;network/wifi;Mozilla/5.0 (iPhone; CPU iPhone OS 14_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1", + "jdapp;iPhone;10.0.2;14.2;network/wifi;Mozilla/5.0 (iPhone; CPU iPhone OS 14_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1", + "jdapp;android;10.0.2;8.1.0;network/wifi;Mozilla/5.0 (Linux; Android 8.1.0; MI 8 Build/OPM1.171019.026; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/66.0.3359.126 MQQBrowser/6.2 TBS/045131 Mobile Safari/537.36", + "jdapp;android;10.0.2;10;network/wifi;Mozilla/5.0 (Linux; Android 10; Redmi K20 Pro Premium Edition Build/QKQ1.190825.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.120 MQQBrowser/6.2 TBS/045227 Mobile Safari/537.36", + "jdapp;iPhone;10.0.2;14.3;network/wifi;Mozilla/5.0 (iPhone; CPU iPhone OS 14_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1", + "jdapp;iPhone;10.0.2;14.3;network/4g;Mozilla/5.0 (iPhone; CPU iPhone OS 14_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1", + "jdapp;android;10.0.2;11;network/wifi;Mozilla/5.0 (Linux; Android 11; Redmi K20 Pro Premium Edition Build/RKQ1.200826.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.120 MQQBrowser/6.2 TBS/045513 Mobile Safari/537.36", + "jdapp;android;10.0.2;10;network/wifi;Mozilla/5.0 (Linux; Android 10; MI 8 Build/QKQ1.190828.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.120 MQQBrowser/6.2 TBS/045227 Mobile Safari/537.36", + "jdapp;iPhone;10.0.2;14.1;network/wifi;Mozilla/5.0 (iPhone; CPU iPhone OS 14_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1", +] + +function TotalBean(cookie: string) { + return { + cookie: cookie, + isLogin: true, + nickName: '' + } +} + +function getRandomNumberByRange(start: number, end: number) { + end <= start && (end = start + 100) + return Math.floor(Math.random() * (end - start) + start) +} + +let USER_AGENT = USER_AGENTS[getRandomNumberByRange(0, USER_AGENTS.length)] + +async function getBeanShareCode(cookie: string) { + let {data}: any = await axios.post('https://api.m.jd.com/client.action', + `functionId=plantBeanIndex&body=${encodeURIComponent( + JSON.stringify({version: "9.0.0.1", "monitor_source": "plant_app_plant_index", "monitor_refer": ""}) + )}&appid=ld&client=apple&area=5_274_49707_49973&build=167283&clientVersion=9.1.0`, { + headers: { + Cookie: cookie, + Host: "api.m.jd.com", + Accept: "*/*", + Connection: "keep-alive", + "User-Agent": USER_AGENT + } + }) + if (data.data?.jwordShareInfo?.shareUrl) + return data.data.jwordShareInfo.shareUrl.split('Uuid=')![1] + else + return '' +} + +async function getFarmShareCode(cookie: string) { + let {data}: any = await axios.post('https://api.m.jd.com/client.action?functionId=initForFarm', `body=${encodeURIComponent(JSON.stringify({"version": 4}))}&appid=wh5&clientVersion=9.1.0`, { + headers: { + "cookie": cookie, + "origin": "https://home.m.jd.com", + "referer": "https://home.m.jd.com/myJd/newhome.action", + "User-Agent": USER_AGENT, + "Content-Type": "application/x-www-form-urlencoded" + } + }) + + if (data.farmUserPro) + return data.farmUserPro.shareCode + else + return '' +} + +async function requireConfig(check: boolean = false): Promise { + let cookiesArr: string[] = [] + const jdCookieNode = require('../jdCookie.js') + let keys: string[] = Object.keys(jdCookieNode) + for (let i = 0; i < keys.length; i++) { + let cookie = jdCookieNode[keys[i]] + if (!check) { + cookiesArr.push(cookie) + } else { + if (await checkCookie(cookie)) { + cookiesArr.push(cookie) + } else { + let username = decodeURIComponent(jdCookieNode[keys[i]].match(/pt_pin=([^;]*)/)![1]) + console.log('Cookie失效', username) + await sendNotify('Cookie失效', '【京东账号】' + username) + } + } + } + console.log(`共${cookiesArr.length}个京东账号\n`) + return cookiesArr +} + +async function checkCookie(cookie) { + await wait(1000) + try { + let {data}: any = await axios.get(`https://api.m.jd.com/client.action?functionId=GetJDUserInfoUnion&appid=jd-cphdeveloper-m&body=${encodeURIComponent(JSON.stringify({"orgFlag": "JD_PinGou_New", "callSource": "mainorder", "channel": 4, "isHomewhite": 0, "sceneval": 2}))}&loginType=2&_=${Date.now()}&sceneval=2&g_login_type=1&callback=GetJDUserInfoUnion&g_ty=ls`, { + headers: { + 'authority': 'api.m.jd.com', + 'user-agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1', + 'referer': 'https://home.m.jd.com/', + 'cookie': cookie + } + }) + data = JSON.parse(data.match(/GetJDUserInfoUnion\((.*)\)/)[1]) + return data.retcode === '0'; + } catch (e) { + return false + } +} + +function wait(timeout: number) { + return new Promise(resolve => { + setTimeout(resolve, timeout) + }) +} + +async function requestAlgo(appId: number = 10032) { + fingerprint = generateFp() + return new Promise(async resolve => { + let {data}: any = await axios.post('https://cactus.jd.com/request_algo?g_ty=ajax', { + "version": "1.0", + "fp": fingerprint, + "appId": appId, + "timestamp": Date.now(), + "platform": "web", + "expandParams": "" + }, { + "headers": { + 'Authority': 'cactus.jd.com', + 'Pragma': 'no-cache', + 'Cache-Control': 'no-cache', + 'Accept': 'application/json', + 'User-Agent': USER_AGENT, + 'Content-Type': 'application/json', + 'Origin': 'https://st.jingxi.com', + 'Sec-Fetch-Site': 'cross-site', + 'Sec-Fetch-Mode': 'cors', + 'Sec-Fetch-Dest': 'empty', + 'Referer': 'https://st.jingxi.com/', + 'Accept-Language': 'zh-CN,zh;q=0.9,zh-TW;q=0.8,en;q=0.7' + }, + }) + if (data['status'] === 200) { + token = data.data.result.tk + let enCryptMethodJDString = data.data.result.algo + if (enCryptMethodJDString) enCryptMethodJD = new Function(`return ${enCryptMethodJDString}`)() + } else { + console.log(`fp: ${fingerprint}`) + console.log('request_algo 签名参数API请求失败:') + } + resolve() + }) +} + +function generateFp() { + let e = "0123456789" + let a = 13 + let i = '' + for (; a--;) + i += e[Math.random() * e.length | 0] + return (i + Date.now()).slice(0, 16) +} + +function getJxToken(cookie: string, phoneId: string = '') { + function generateStr(input: number) { + let src = 'abcdefghijklmnopqrstuvwxyz1234567890' + let res = '' + for (let i = 0; i < input; i++) { + res += src[Math.floor(src.length * Math.random())] + } + return res + } + + if (!phoneId) + phoneId = generateStr(40) + let timestamp = Date.now().toString() + let nickname = cookie.match(/pt_pin=([^;]*)/)![1] + let jstoken = Md5.hashStr('' + decodeURIComponent(nickname) + timestamp + phoneId + 'tPOamqCuk9NLgVPAljUyIHcPRmKlVxDy') + return { + 'strPgtimestamp': timestamp, + 'strPhoneID': phoneId, + 'strPgUUNum': jstoken + } +} + +function exceptCookie(filename: string = 'x.ts') { + let except: any = [] + if (existsSync('./utils/exceptCookie.json')) { + try { + except = JSON.parse(readFileSync('./utils/exceptCookie.json').toString() || '{}')[filename] || [] + } catch (e) { + console.log('./utils/exceptCookie.json JSON格式错误') + } + } + return except +} + +function randomString(e: number, word?: number) { + e = e || 32 + let t = word === 26 ? "012345678abcdefghijklmnopqrstuvwxyz" : "0123456789abcdef", a = t.length, n = "" + for (let i = 0; i < e; i++) + n += t.charAt(Math.floor(Math.random() * a)) + return n +} + +function o2s(arr: object, title: string = '') { + title ? console.log(title, JSON.stringify(arr)) : console.log(JSON.stringify(arr)) +} + +function randomNumString(e: number) { + e = e || 32 + let t = '0123456789', a = t.length, n = "" + for (let i = 0; i < e; i++) + n += t.charAt(Math.floor(Math.random() * a)) + return n +} + +function randomWord(n: number = 1) { + let t = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', a = t.length + let rnd: string = '' + for (let i = 0; i < n; i++) { + rnd += t.charAt(Math.floor(Math.random() * a)) + } + return rnd +} + +function obj2str(obj: object) { + return JSON.stringify(obj) +} + +async function getDevice() { + let {data} = await axios.get('https://betahub.cn/api/apple/devices/iPhone', { + headers: { + 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' + } + }) + data = data[getRandomNumberByRange(0, 16)] + return data.identifier +} + +async function getVersion(device: string) { + let {data} = await axios.get(`https://betahub.cn/api/apple/firmwares/${device}`, { + headers: { + 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36' + } + }) + data = data[getRandomNumberByRange(0, data.length)] + return data.firmware_info.version +} + +async function jdpingou() { + let device: string, version: string; + device = await getDevice(); + version = await getVersion(device); + return `jdpingou;iPhone;5.19.0;${version};${randomString(40)};network/wifi;model/${device};appBuild/100833;ADID/;supportApplePay/1;hasUPPay/0;pushNoticeIsOpen/0;hasOCPay/0;supportBestPay/0;session/${getRandomNumberByRange(10, 90)};pap/JA2019_3111789;brand/apple;supportJDSHWK/1;Mozilla/5.0 (iPhone; CPU iPhone OS 14_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148` +} + +function get(url: string, headers?: any): Promise { + return new Promise((resolve, reject) => { + axios.get(url, { + headers: headers + }).then(res => { + if (typeof res.data === 'string' && res.data.includes('jsonpCBK')) { + resolve(JSON.parse(res.data.match(/jsonpCBK.?\(([\w\W]*)\);?/)[1])) + } else { + resolve(res.data) + } + }).catch(err => { + reject({ + code: err?.response?.status || -1, + msg: err?.response?.statusText || err.message || 'error' + }) + }) + }) +} + +function post(url: string, prarms?: string | object, headers?: any): Promise { + return new Promise((resolve, reject) => { + axios.post(url, prarms, { + headers: headers + }).then(res => { + resolve(res.data) + }).catch(err => { + reject({ + code: err?.response?.status || -1, + msg: err?.response?.statusText || err.message || 'error' + }) + }) + }) +} + +export default USER_AGENT +export { + TotalBean, + getBeanShareCode, + getFarmShareCode, + requireConfig, + wait, + getRandomNumberByRange, + requestAlgo, + getJxToken, + randomString, + o2s, + randomNumString, + getShareCodePool, + randomWord, + obj2str, + jdpingou, + get, + post +} diff --git a/function/common.js b/function/common.js index 0ee3115..a8a8e9e 100644 --- a/function/common.js +++ b/function/common.js @@ -37,20 +37,12 @@ class env { console.log(`🔔${this.name}, 结束!\n`) } notify(array) { - let text = []; - let type = 0 + let text = ''; for (let i of array) { - text.push(`${i.user} -- ${i.msg}`) - type = i.type + text += `${i.user} -- ${i.msg}\n` } console.log(`\n=============================开始发送提醒消息=============================`) - if (type == 1) { - for (let i of text) { - notify.sendNotify(this.name + "消息提醒", i) - } - } else { - notify.sendNotify(this.name + "消息提醒", text.join('\n')) - } + notify.sendNotify(this.name + "消息提醒", text) } wait(t) { return new Promise(e => setTimeout(e, t)) @@ -131,20 +123,18 @@ class env { loads(str) { return JSON.parse(str) } - notice(msg, type = 0) { + notice(msg) { this.message.push({ 'index': this.index, 'user': this.user, - 'msg': msg, - type + 'msg': msg }) } - notices(msg, user, type = 0) { + notices(msg, user, index = '') { this.message.push({ 'user': user, 'msg': msg, - // 'index': index, - type + 'index': index }) } urlparse(url) { diff --git a/function/eval.js b/function/eval.js index 9277379..8aa31f7 100644 --- a/function/eval.js +++ b/function/eval.js @@ -8,9 +8,6 @@ function mainEval($) { } $.sleep=cookies['all'].length * 500 taskCookie=cookies['all'] - if($.config[\`\${$.runfile}_limit\`]){ - taskCookie = cookies['all'].slice(0,parseInt($.config[\`\${$.runfile}_limit\`])) - } jxAlgo = new common.jxAlgo(); if ($.readme) { console.log(\`使用说明:\\n\${$.readme}\\n以上内容仅供参考,有需求自行添加\\n\`,) diff --git a/function/h5st.ts b/function/h5st.ts new file mode 100644 index 0000000..3f0463d --- /dev/null +++ b/function/h5st.ts @@ -0,0 +1,73 @@ +import axios from "axios" +import {format} from "date-fns" + +const CryptoJS = require("crypto-js") + +class H5ST { + tk: string; + timestamp: string; + rd: string; + appId: string; + fp: string; + time: number; + ua: string + enc: string; + + constructor(appId: string, ua: string, fp: string) { + this.appId = appId + this.ua = ua + this.fp = fp || this.__genFp() + } + + __genFp() { + let e = "0123456789"; + let a = 13; + let i = ''; + for (; a--;) + i += e[Math.random() * e.length | 0]; + return (i + Date.now()).slice(0, 16) + } + + async __genAlgo() { + this.time = Date.now() + this.timestamp = format(this.time, "yyyyMMddHHmmssSSS") + let {data} = await axios.post(`https://cactus.jd.com/request_algo?g_ty=ajax`, { + 'version': '3.0', + 'fp': this.fp, + 'appId': this.appId.toString(), + 'timestamp': this.time, + 'platform': 'web', + 'expandParams': '' + }, { + headers: { + 'Host': 'cactus.jd.com', + 'accept': 'application/json', + 'content-type': 'application/json', + 'user-agent': this.ua, + } + }) + this.tk = data.data.result.tk + this.rd = data.data.result.algo.match(/rd='(.*)'/)[1] + this.enc = data.data.result.algo.match(/algo\.(.*)\(/)[1] + } + + __genKey(tk, fp, ts, ai, algo) { + let str = `${tk}${fp}${ts}${ai}${this.rd}`; + return algo[this.enc](str, tk) + } + + __genH5st(body: object) { + let y = this.__genKey(this.tk, this.fp, this.timestamp, this.appId, CryptoJS).toString(CryptoJS.enc.Hex) + let s = '' + for (let i in body) { + i === 'body' ? s += `${i}:${CryptoJS.SHA256(body[i]).toString(CryptoJS.enc.Hex)}&` : s += `${i}:${body[i]}&` + } + s = s.slice(0, -1) + s = CryptoJS.HmacSHA256(s, y).toString(CryptoJS.enc.Hex) + return encodeURIComponent(`${this.timestamp};${this.fp};${this.appId.toString()};${this.tk};${s};3.0;${this.time.toString()}`) + } +} + +export { + H5ST +} \ No newline at end of file diff --git a/function/jinli_log.ts b/function/jinli_log.ts new file mode 100644 index 0000000..1ec621a --- /dev/null +++ b/function/jinli_log.ts @@ -0,0 +1,9 @@ +let logs = [ +'"random":"34038984","log":"1649609592095~18RCD4zkS04d41d8cd98f00b204e9800998ecf8427e~1,1~E97F477EB64B001195F05A4D48067CD6C272595D~0doi8po~C~TRpGXBAPbWUeE0ZbWxoIam8ZFF9AXxAPBxQQQkEXDBoDBwYMAw8KBgcAAw4KAgEMABoeE0VQUhoIE0ZBQkxGV0dTFBQQRldUFAIQRVRBV01TRFMXGhpCVVwXDGMGHQIZBhQBHQAZB2UeE1hfFAIDHRBWRRoIEwVQUFpQAFABAAgEVAZTD1sGBwABUw9RCQMHDw1WCQAFFBQQX0IXDBp+WFxAThhKCQRqAAwQHRBBFAIQAAQBDw4CCAcMBAgLBBAZFFJZEwgXVxoeE1RFVBoIExAZFFZEEwgXcVddVl5QFnFcUhwXGhpcUEQXDBoLAwsGBRoeE0FWRBoIagQDARQBBgdoGhpAXhAPbRpTEx4XVxoeE1MXGhpTEx4XVxoeE1MXGhpTE28ZFFFdUBAPFF5UV1RTUExGEx4XV1IQCxBAFBQQUlsXDBpFAhwHGAwQHRBWUGdEEwgXBggQHRBXUhoIE0BUWFxdXA8GAggBCQsNAhoeE19fFAJpAR4FGghvHRBXWldVEwgXVxoeE19GURoIE1MXSw==~04y5u3i"', + + +] + +export { + logs +} \ No newline at end of file diff --git a/jd_joy_park_task.js b/jd_joy_park_task.js new file mode 100644 index 0000000..666fa17 --- /dev/null +++ b/jd_joy_park_task.js @@ -0,0 +1,373 @@ +/* + +脚本默认会帮我助力开工位,介意请添加变量HELP_JOYPARK,false为不助力 +export HELP_JOYPARK="" + +============Quantumultx=============== +[task_local] +#汪汪乐园每日任务 +0 1,7,20 * * * jd_joypark_task.js, tag=汪汪乐园每日任务, img-url=https://raw.githubusercontent.com/tsukasa007/icon/master/jd_joypark_task.png, enabled=true + +================Loon============== +[Script] +cron "0 1,7,20 * * *" script-path=jd_joypark_task.js,tag=汪汪乐园每日任务 + +===============Surge================= +汪汪乐园每日任务 = type=cron,cronexp="0 1,7,20 * * *",wake-system=1,timeout=3600,script-path=jd_joypark_task.js + +============小火箭========= +汪汪乐园每日任务 = type=cron,script-path=jd_joypark_task.js, cronexpr="0 1,7,20 * * *", timeout=3600, enable=true +*/ +const $ = new Env('汪汪乐园每日任务'); +const jdCookieNode = $.isNode() ? require('./jdCookie.js') : ''; +const notify = $.isNode() ? require('./sendNotify') : ''; +//IOS等用户直接用NobyDa的jd cookie +let cookiesArr = [], cookie = ''; + +if ($.isNode()) { + Object.keys(jdCookieNode).forEach((item) => { + cookiesArr.push(jdCookieNode[item]) + }) + if (process.env.JD_DEBUG && process.env.JD_DEBUG === 'false') console.log = () => { }; +} else { + cookiesArr = [$.getdata('CookieJD'), $.getdata('CookieJD2'), ...jsonParse($.getdata('CookiesJD') || "[]").map(item => item.cookie)].filter(item => !!item); +} +$.invitePinTaskList = [] +$.invitePin = [ + "VxQJC6Sr0QZkcOHwxoTjrw", + "oRY9YryofcNg71MZeKSZseKD6P6BJzKv2NBGxfiuJ20", + "EDPUVDhR7nUPh3jUGDJ_GyiLt77-wROqWVP2aesRUt8" +] +const JD_API_HOST = `https://api.m.jd.com/client.action`; +message = "" +!(async () => { + if (!cookiesArr[0]) { + $.msg($.name, '【提示】请先获取cookie\n直接使用NobyDa的京东签到获取', 'https://bean.m.jd.com/', { + "open-url": "https://bean.m.jd.com/" + }); + return; + } + for (let i = 0; i < cookiesArr.length; i++) { + cookie = cookiesArr[i]; + if (cookie) { + $.UserName = decodeURIComponent(cookie.match(/pt_pin=([^; ]+)(?=;?)/) && cookie.match(/pt_pin=([^; ]+)(?=;?)/)[1]) + $.index = i + 1; + $.isLogin = true; + $.nickName = ''; + $.openIndex = 0; + $.UA = `jdapp;iPhone;10.1.4;13.1.2;${randomString(40)};network/wifi;model/iPhone8,1;addressid/2308460611;appBuild/167814;jdSupportDarkMode/0;Mozilla/5.0 (iPhone; CPU iPhone OS 13_1_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1` + + console.log(`\n******开始【京东账号${$.index}】${$.nickName || $.UserName}*********\n`); + if (!$.isLogin) { + $.msg($.name, `【提示】cookie已失效`, `京东账号${$.index} ${$.nickName || $.UserName}\n请重新登录获取\nhttps://bean.m.jd.com/bean/signIndex.action`, { + "open-url": "https://bean.m.jd.com/bean/signIndex.action" + }); + if ($.isNode()) { + await notify.sendNotify(`${$.name}cookie已失效 - ${$.UserName}`, `京东账号${$.index} ${$.UserName}\n请重新登录获取cookie`); + } + continue + } + await getTaskList(); + + // 签到 / 逛会场 / 浏览商品 + for (const task of $.taskList) { + if (task.taskType === 'SIGN') { + $.log(`${task.taskTitle}`) + await apDoTask(task.id, task.taskType, undefined); + $.log(`${task.taskTitle} 领取奖励`) + await apTaskDrawAward(task.id, task.taskType); + } + if (task.taskType === 'BROWSE_PRODUCT' || task.taskType === 'BROWSE_CHANNEL' && task.taskLimitTimes !== 1) { + let productList = await apTaskDetail(task.id, task.taskType); + let productListNow = 0; + if (productList.length === 0) { + let resp = await apTaskDrawAward(task.id, task.taskType); + + if (!resp.success) { + $.log(`${task.taskTitle}|${task.taskShowTitle} 领取完成!`) + productList = await apTaskDetail(task.id, task.taskType); + + } + } + //做 + while (task.taskLimitTimes - task.taskDoTimes >= 0) { + + if (productList.length === 0) { + $.log(`${task.taskTitle} 活动火爆,素材库没有素材,我也不知道啥回事 = = `); + break; + } + $.log(`${task.taskTitle} ${task.taskDoTimes}/${task.taskLimitTimes}`); + let resp = await apDoTask(task.id, task.taskType, productList[productListNow].itemId, productList[productListNow].appid); + + if (resp.code === 2005 || resp.code === 0) { + $.log(`${task.taskTitle}|${task.taskShowTitle} 任务完成!`) + } else { + $.log(`${resp.echo} 任务失败!`) + } + productListNow++; + task.taskDoTimes++; + if (!productList[productListNow]) { + break + } + } + //领 + for (let j = 0; j < task.taskLimitTimes; j++) { + let resp = await apTaskDrawAward(task.id, task.taskType); + + if (!resp.success) { + $.log(`${task.taskTitle}|${task.taskShowTitle} 领取完成!`) + break + } + } + } else if (task.taskType === 'SHARE_INVITE') { + $.yq_taskid = task.id + for (let j = 0; j < 5; j++) { + let resp = await apTaskDrawAward($.yq_taskid, 'SHARE_INVITE'); + + if (!resp.success) { + break + } + $.log("领取助力奖励成功!") + } + } + if (task.taskType === 'BROWSE_CHANNEL' && task.taskLimitTimes === 1) { + $.log(`${task.taskTitle}|${task.taskShowTitle}`) + await apDoTask2(task.id, task.taskType, task.taskSourceUrl); + $.log(`${task.taskTitle}|${task.taskShowTitle} 领取奖励`) + await apTaskDrawAward(task.id, task.taskType); + } + // if (task.taskType === 'SHARE_INVITE') { + // $.yq_taskid = task.id + // } + + } + } + } + + $.log("\n======汪汪乐园开始内部互助======\n") + for (let i = 0; i < cookiesArr.length; i++) { + cookie = cookiesArr[i]; + if (cookie) { + $.UserName = decodeURIComponent(cookie.match(/pt_pin=([^; ]+)(?=;?)/) && cookie.match(/pt_pin=([^; ]+)(?=;?)/)[1]) + $.index = i + 1; + $.isLogin = true; + $.nickName = ''; + console.log(`\n******开始【京东账号${$.index}】${$.nickName || $.UserName}*********\n`); + if (!$.isLogin) { + $.msg($.name, `【提示】cookie已失效`, `京东账号${$.index} ${$.nickName || $.UserName}\n请重新登录获取\nhttps://bean.m.jd.com/bean/signIndex.action`, { + "open-url": "https://bean.m.jd.com/bean/signIndex.action" + }); + if ($.isNode()) { + await notify.sendNotify(`${$.name}cookie已失效 - ${$.UserName}`, `京东账号${$.index} ${$.UserName}\n请重新登录获取cookie`); + } + continue + } + $.newinvitePinTaskList = [...($.invitePinTaskList || []), ...($.invitePin || [])] + for (const invitePinTaskListKey of $.newinvitePinTaskList) { + $.log(`【京东账号${$.index}】${$.nickName || $.UserName} 助力 ${invitePinTaskListKey}`) + let resp = await getJoyBaseInfo($.yq_taskid, 1, invitePinTaskListKey); + if (resp.success) { + if (resp.data.helpState === 1) { + $.log("助力成功!"); + } else if (resp.data.helpState === 0) { + $.log("自己不能助力自己!"); + } else if (resp.data.helpState === 2) { + $.log("助力过了!"); + } else if (resp.data.helpState === 3) { + $.log("没有助力次数了!"); + break + } else if (resp.data.helpState === 4) { + $.log("这个B助力满了!"); + } + } else { + $.log("数据异常 助力失败!\n\n") + break + } + } + } + } +})() + .catch((e) => $.logErr(e)) + .finally(() => $.done()) +//获取活动信息 + +//任务列表 +function getTaskList() { + //await $.wait(20) + return new Promise(resolve => { + $.post(taskPostClientActionUrl(`body={"linkId":"LsQNxL7iWDlXUs6cFl-AAg"}&appid=activities_platform`, `apTaskList`), async (err, resp, data) => { + $.log('=== 任务列表 start ===') + try { + if (err) { + console.log(`${JSON.stringify(err)}`) + console.log(`${$.name} API请求失败,请检查网路重试`) + } else { + data = JSON.parse(data); + $.taskList = data.data + for (const row of $.taskList) { + $.log(`${row.taskTitle} ${row.taskDoTimes}/${row.taskLimitTimes}`) + } + $.log('=== 任务列表 end ===') + } + } catch (e) { + $.logErr(e, resp) + } finally { + resolve(data); + } + }) + }) +} + +/** + * 互助 + * @param taskId + * @param inviteType + * @param inviterPin + * @returns {Promise} + */ +function getJoyBaseInfo(taskId = '', inviteType = '', inviterPin = '') { + //await $.wait(20) + return new Promise(resolve => { + $.post(taskPostClientActionUrl(`body={"taskId":"${taskId}","inviteType":"${inviteType}","inviterPin":"${inviterPin}","linkId":"LsQNxL7iWDlXUs6cFl-AAg"}&_t=1625480372020&appid=activities_platform`, `joyBaseInfo`), async (err, resp, data) => { + try { + if (err) { + console.log(`${JSON.stringify(err)}`) + console.log(`${$.name} API请求失败,请检查网路重试`) + } else { + data = JSON.parse(data); + $.joyBaseInfo = data.data + } + } catch (e) { + $.logErr(e, resp) + } finally { + //$.log(`resolve start`) + resolve(data); + //$.log(`resolve end`) + } + }) + }) +} + +function apDoTask(taskId, taskType, itemId = '', appid = 'activities_platform') { + //await $.wait(20) + return new Promise(resolve => { + $.post(taskPostClientActionUrl(`body={"taskType":"${taskType}","taskId":${taskId},"channel":4,"linkId":"LsQNxL7iWDlXUs6cFl-AAg","itemId":"${itemId}"}&appid=${appid}`, `apDoTask`), async (err, resp, data) => { + try { + if (err) { + console.log(`${JSON.stringify(err)}`) + console.log(`${$.name} API请求失败,请检查网路重试`) + } else { + data = JSON.parse(data); + } + } catch (e) { + $.logErr(e, resp) + } finally { + resolve(data); + } + }) + }) +} + +function apDoTask2(taskId, taskType, itemId, appid = 'activities_platform') { + return new Promise(resolve => { + $.post(taskPostClientActionUrl(`body={"taskType":"${taskType}","taskId":${taskId},"linkId":"LsQNxL7iWDlXUs6cFl-AAg","itemId":"${itemId}"}&appid=${appid}`, `apDoTask`), async (err, resp, data) => { + try { + if (err) { + console.log(`${JSON.stringify(err)}`) + console.log(`${$.name} API请求失败,请检查网路重试`) + } else { + data = JSON.parse(data); + } + } catch (e) { + $.logErr(e, resp) + } finally { + resolve(data); + } + }) + }) +} + +function apTaskDetail(taskId, taskType) { + //await $.wait(20) + return new Promise(resolve => { + $.post(taskPostClientActionUrl(`functionId=apTaskDetail&body={"taskType":"${taskType}","taskId":${taskId},"channel":4,"linkId":"LsQNxL7iWDlXUs6cFl-AAg"}&appid=activities_platform`, `apTaskDetail`), async (err, resp, data) => { + try { + if (err) { + console.log(`${JSON.stringify(err)}`) + console.log(`${$.name} API请求失败,请检查网路重试`) + } else { + data = JSON.parse(data); + if (!data.success) { + $.taskDetailList = [] + } else { + $.taskDetailList = data.data.taskItemList; + } + } + } catch (e) { + $.logErr(e, resp) + } finally { + if (!data.success) { + resolve([]); + } else { + resolve(data.data.taskItemList); + } + } + }) + }) +} + +function apTaskDrawAward(taskId, taskType) { + //await $.wait(20) + return new Promise(resolve => { + $.post(taskPostClientActionUrl(`body={"taskType":"${taskType}","taskId":${taskId},"linkId":"LsQNxL7iWDlXUs6cFl-AAg"}&appid=activities_platform`, `apTaskDrawAward`), async (err, resp, data) => { + try { + if (err) { + console.log(`${JSON.stringify(err)}`) + console.log(`${$.name} API请求失败,请检查网路重试`) + } else { + data = JSON.parse(data); + $.log("领取奖励") + } + } catch (e) { + $.logErr(e, resp) + } finally { + resolve(data); + } + }) + }) +} + +function taskPostClientActionUrl(body, functionId) { + return { + url: `https://api.m.jd.com/client.action?${functionId ? `functionId=${functionId}` : ``}`, + body: body, + headers: { + 'User-Agent': $.UA, + 'Content-Type': 'application/x-www-form-urlencoded', + 'Host': 'api.m.jd.com', + 'Origin': 'https://joypark.jd.com', + 'Referer': 'https://joypark.jd.com/?activityId=LsQNxL7iWDlXUs6cFl-AAg&lng=113.387899&lat=22.512678&sid=4d76080a9da10fbb31f5cd43396ed6cw&un_area=19_1657_52093_0', + 'Cookie': cookie, + } + } +} +function randomString(e) { + e = e || 32; + let t = "abcdef0123456789", a = t.length, n = ""; + for (i = 0; i < e; i++) + n += t.charAt(Math.floor(Math.random() * a)); + return n +} +function jsonParse(str) { + if (typeof str == "string") { + try { + return JSON.parse(str); + } catch (e) { + console.log(e); + $.msg($.name, '', '请勿随意在BoxJs输入框修改内容\n建议通过脚本去获取cookie') + return []; + } + } +} +// prettier-ignore +function Env(t, e) { "undefined" != typeof process && JSON.stringify(process.env).indexOf("GITHUB") > -1 && process.exit(0); class s { constructor(t) { this.env = t } send(t, e = "GET") { t = "string" == typeof t ? { url: t } : t; let s = this.get; return "POST" === e && (s = this.post), new Promise((e, i) => { s.call(this, t, (t, s, r) => { t ? i(t) : e(s) }) }) } get(t) { return this.send.call(this.env, t) } post(t) { return this.send.call(this.env, t, "POST") } } return new class { constructor(t, e) { this.name = t, this.http = new s(this), this.data = null, this.dataFile = "box.dat", this.logs = [], this.isMute = !1, this.isNeedRewrite = !1, this.logSeparator = "\n", this.startTime = (new Date).getTime(), Object.assign(this, e), this.log("", `🔔${this.name}, 开始!`) } 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 } toObj(t, e = null) { try { return JSON.parse(t) } catch { return e } } toStr(t, e = null) { try { return JSON.stringify(t) } catch { return e } } getjson(t, e) { let s = e; const i = this.getdata(t); if (i) try { s = JSON.parse(this.getdata(t)) } catch { } return s } setjson(t, e) { try { return this.setdata(JSON.stringify(t), e) } catch { return !1 } } getScript(t) { return new Promise(e => { this.get({ url: t }, (t, s, i) => e(i)) }) } runScript(t, e) { return new Promise(s => { let i = this.getdata("@chavy_boxjs_userCfgs.httpapi"); i = i ? i.replace(/\n/g, "").trim() : i; let r = this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout"); r = r ? 1 * r : 20, r = e && e.timeout ? e.timeout : r; const [o, h] = i.split("@"), n = { url: `http://${h}/v1/scripting/evaluate`, body: { script_text: t, mock_type: "cron", timeout: r }, headers: { "X-Key": o, Accept: "*/*" } }; this.post(n, (t, e, i) => s(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), e = this.path.resolve(process.cwd(), this.dataFile), s = this.fs.existsSync(t), i = !s && this.fs.existsSync(e); if (!s && !i) return {}; { const i = s ? t : e; 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), e = this.path.resolve(process.cwd(), this.dataFile), s = this.fs.existsSync(t), i = !s && this.fs.existsSync(e), r = JSON.stringify(this.data); s ? this.fs.writeFileSync(t, r) : i ? this.fs.writeFileSync(e, r) : this.fs.writeFileSync(t, r) } } lodash_get(t, e, s) { const i = e.replace(/\[(\d+)\]/g, ".$1").split("."); let r = t; for (const t of i) if (r = Object(r)[t], void 0 === r) return s; return r } lodash_set(t, e, s) { return Object(t) !== t ? t : (Array.isArray(e) || (e = e.toString().match(/[^.[\]]+/g) || []), e.slice(0, -1).reduce((t, s, i) => Object(t[s]) === t[s] ? t[s] : t[s] = Math.abs(e[i + 1]) >> 0 == +e[i + 1] ? [] : {}, t)[e[e.length - 1]] = s, t) } getdata(t) { let e = this.getval(t); if (/^@/.test(t)) { const [, s, i] = /^@(.*?)\.(.*?)$/.exec(t), r = s ? this.getval(s) : ""; if (r) try { const t = JSON.parse(r); e = t ? this.lodash_get(t, i, "") : e } catch (t) { e = "" } } return e } setdata(t, e) { let s = !1; if (/^@/.test(e)) { const [, i, r] = /^@(.*?)\.(.*?)$/.exec(e), o = this.getval(i), h = i ? "null" === o ? null : o || "{}" : "{}"; try { const e = JSON.parse(h); this.lodash_set(e, r, t), s = this.setval(JSON.stringify(e), i) } catch (e) { const o = {}; this.lodash_set(o, r, t), s = this.setval(JSON.stringify(o), i) } } else s = this.setval(t, e); return s } 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, e) { return this.isSurge() || this.isLoon() ? $persistentStore.write(t, e) : this.isQuanX() ? $prefs.setValueForKey(t, e) : this.isNode() ? (this.data = this.loaddata(), this.data[e] = t, this.writedata(), !0) : this.data && this.data[e] || 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, e = (() => { })) { t.headers && (delete t.headers["Content-Type"], delete t.headers["Content-Length"]), this.isSurge() || this.isLoon() ? (this.isSurge() && this.isNeedRewrite && (t.headers = t.headers || {}, Object.assign(t.headers, { "X-Surge-Skip-Scripting": !1 })), $httpClient.get(t, (t, s, i) => { !t && s && (s.body = i, s.statusCode = s.status), e(t, s, i) })) : this.isQuanX() ? (this.isNeedRewrite && (t.opts = t.opts || {}, Object.assign(t.opts, { hints: !1 })), $task.fetch(t).then(t => { const { statusCode: s, statusCode: i, headers: r, body: o } = t; e(null, { status: s, statusCode: i, headers: r, body: o }, o) }, t => e(t))) : this.isNode() && (this.initGotEnv(t), this.got(t).on("redirect", (t, e) => { try { if (t.headers["set-cookie"]) { const s = t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString(); s && this.ckjar.setCookieSync(s, null), e.cookieJar = this.ckjar } } catch (t) { this.logErr(t) } }).then(t => { const { statusCode: s, statusCode: i, headers: r, body: o } = t; e(null, { status: s, statusCode: i, headers: r, body: o }, o) }, t => { const { message: s, response: i } = t; e(s, i, i && i.body) })) } post(t, e = (() => { })) { if (t.body && t.headers && !t.headers["Content-Type"] && (t.headers["Content-Type"] = "application/x-www-form-urlencoded"), t.headers && delete t.headers["Content-Length"], this.isSurge() || this.isLoon()) this.isSurge() && this.isNeedRewrite && (t.headers = t.headers || {}, Object.assign(t.headers, { "X-Surge-Skip-Scripting": !1 })), $httpClient.post(t, (t, s, i) => { !t && s && (s.body = i, s.statusCode = s.status), e(t, s, i) }); else if (this.isQuanX()) t.method = "POST", this.isNeedRewrite && (t.opts = t.opts || {}, Object.assign(t.opts, { hints: !1 })), $task.fetch(t).then(t => { const { statusCode: s, statusCode: i, headers: r, body: o } = t; e(null, { status: s, statusCode: i, headers: r, body: o }, o) }, t => e(t)); else if (this.isNode()) { this.initGotEnv(t); const { url: s, ...i } = t; this.got.post(s, i).then(t => { const { statusCode: s, statusCode: i, headers: r, body: o } = t; e(null, { status: s, statusCode: i, headers: r, body: o }, o) }, t => { const { message: s, response: i } = t; e(s, i, i && i.body) }) } } time(t, e = null) { const s = e ? new Date(e) : new Date; let i = { "M+": s.getMonth() + 1, "d+": s.getDate(), "H+": s.getHours(), "m+": s.getMinutes(), "s+": s.getSeconds(), "q+": Math.floor((s.getMonth() + 3) / 3), S: s.getMilliseconds() }; /(y+)/.test(t) && (t = t.replace(RegExp.$1, (s.getFullYear() + "").substr(4 - RegExp.$1.length))); for (let e in i) new RegExp("(" + e + ")").test(t) && (t = t.replace(RegExp.$1, 1 == RegExp.$1.length ? i[e] : ("00" + i[e]).substr(("" + i[e]).length))); return t } msg(e = t, s = "", i = "", r) { const o = t => { if (!t) return t; if ("string" == typeof t) return this.isLoon() ? t : this.isQuanX() ? { "open-url": t } : this.isSurge() ? { url: t } : void 0; if ("object" == typeof t) { if (this.isLoon()) { let e = t.openUrl || t.url || t["open-url"], s = t.mediaUrl || t["media-url"]; return { openUrl: e, mediaUrl: s } } if (this.isQuanX()) { let e = t["open-url"] || t.url || t.openUrl, s = t["media-url"] || t.mediaUrl; return { "open-url": e, "media-url": s } } if (this.isSurge()) { let e = t.url || t.openUrl || t["open-url"]; return { url: e } } } }; if (this.isMute || (this.isSurge() || this.isLoon() ? $notification.post(e, s, i, o(r)) : this.isQuanX() && $notify(e, s, i, o(r))), !this.isMuteLog) { let t = ["", "==============📣系统通知📣=============="]; t.push(e), s && t.push(s), i && t.push(i), console.log(t.join("\n")), this.logs = this.logs.concat(t) } } log(...t) { t.length > 0 && (this.logs = [...this.logs, ...t]), console.log(t.join(this.logSeparator)) } logErr(t, e) { const s = !this.isSurge() && !this.isQuanX() && !this.isLoon(); s ? this.log("", `❗️${this.name}, 错误!`, t.stack) : this.log("", `❗️${this.name}, 错误!`, t) } wait(t) { return new Promise(e => setTimeout(e, t)) } done(t = {}) { const e = (new Date).getTime(), s = (e - this.startTime) / 1e3; this.log("", `🔔${this.name}, 结束! 🕛 ${s} 秒`), this.log(), (this.isSurge() || this.isQuanX() || this.isLoon()) && $done(t) } }(t, e) } diff --git a/utils/JDJRValidator_Pure.js b/utils/JDJRValidator_Pure.js index 1412c1e..88fc307 100644 --- a/utils/JDJRValidator_Pure.js +++ b/utils/JDJRValidator_Pure.js @@ -1,10 +1,15 @@ +/* + 由于 canvas 依赖系统底层需要编译且预编译包在 github releases 上,改用另一个纯 js 解码图片。若想继续使用 canvas 可调用 runWithCanvas 。 + + 添加 injectToRequest 用以快速修复需验证的请求。eg: $.get=injectToRequest($.get.bind($)) +*/ const https = require('https'); +const http = require('http'); const stream = require('stream'); const zlib = require('zlib'); const vm = require('vm'); const PNG = require('png-js'); -let UA = require('../USER_AGENTS.js').USER_AGENT; -const validatorCount = process.env.JDJR_validator_Count ? process.env.JDJR_validator_Count : 100 +const UA = require('../USER_AGENTS.js').USER_AGENT; Math.avg = function average() { @@ -28,10 +33,14 @@ class PNGDecoder extends PNG { decodeToPixels() { return new Promise((resolve) => { - this.decode((pixels) => { - this.pixels = pixels; - resolve(); - }); + try { + this.decode((pixels) => { + this.pixels = pixels; + resolve(); + }); + } catch (e) { + console.info(e) + } }); } @@ -65,10 +74,14 @@ class PuzzleRecognizer { } async run() { - await this.bg.decodeToPixels(); - await this.patch.decodeToPixels(); + try { + await this.bg.decodeToPixels(); + await this.patch.decodeToPixels(); - return this.recognize(); + return this.recognize(); + } catch (e) { + console.info(e) + } } recognize() { @@ -202,74 +215,74 @@ const DATA = { "product": "embed", "lang": "zh_CN", }; -const SERVER = 'iv.jd.com'; +const SERVER = '61.49.99.122'; class JDJRValidator { constructor() { this.data = {}; this.x = 0; this.t = Date.now(); - this.count = 0; } - async run(scene = 'cww', eid='') { - const tryRecognize = async () => { - const x = await this.recognize(scene, eid); + async run(scene) { + try { + const tryRecognize = async () => { + const x = await this.recognize(scene); - if (x > 0) { - return x; - } - // retry - return await tryRecognize(); - }; - const puzzleX = await tryRecognize(); - // console.log(puzzleX); - const pos = new MousePosFaker(puzzleX).run(); - const d = getCoordinate(pos); - - // console.log(pos[pos.length-1][2] -Date.now()); - // await sleep(4500); - await sleep(pos[pos.length - 1][2] - Date.now()); - this.count++; - const result = await JDJRValidator.jsonp('/slide/s.html', {d, ...this.data}, scene); - - if (result.message === 'success') { - // console.log(result); - console.log('JDJR验证用时: %fs', (Date.now() - this.t) / 1000); - return result; - } else { - console.log(`验证失败: ${this.count}/${validatorCount}`); - // console.log(JSON.stringify(result)); - if(this.count >= validatorCount){ - console.log("JDJR验证次数已达上限,退出验证"); - return result; - }else{ - await sleep(300); - return await this.run(scene, eid); - } - } - } - - async recognize(scene, eid) { - const data = await JDJRValidator.jsonp('/slide/g.html', {e: eid}, scene); - const {bg, patch, y} = data; - // const uri = 'data:image/png;base64,'; - // const re = new PuzzleRecognizer(uri+bg, uri+patch, y); - const re = new PuzzleRecognizer(bg, patch, y); - // console.log(JSON.stringify(re)) - const puzzleX = await re.run(); - - if (puzzleX > 0) { - this.data = { - c: data.challenge, - w: re.w, - e: eid, - s: '', - o: '', + if (x > 0) { + return x; + } + // retry + return await tryRecognize(); }; - this.x = puzzleX; + const puzzleX = await tryRecognize(); + // console.log(puzzleX); + const pos = new MousePosFaker(puzzleX).run(); + const d = getCoordinate(pos); + + // console.log(pos[pos.length-1][2] -Date.now()); + // await sleep(4500); + await sleep(pos[pos.length - 1][2] - Date.now()); + const result = await JDJRValidator.jsonp('/slide/s.html', {d, ...this.data}, scene); + + if (result.message === 'success') { + // console.log(result); + console.log('JDJR验证用时: %fs', (Date.now() - this.t) / 1000); + return result; + } else { + console.count("验证失败"); + // console.count(JSON.stringify(result)); + await sleep(300); + return await this.run(scene); + } + } catch (e) { + console.info(e) + } + } + + async recognize(scene) { + try { + const data = await JDJRValidator.jsonp('/slide/g.html', {e: ''}, scene); + const {bg, patch, y} = data; + // const uri = 'data:image/png;base64,'; + // const re = new PuzzleRecognizer(uri+bg, uri+patch, y); + const re = new PuzzleRecognizer(bg, patch, y); + const puzzleX = await re.run(); + + if (puzzleX > 0) { + this.data = { + c: data.challenge, + w: re.w, + e: '', + s: '', + o: '', + }; + this.x = puzzleX; + } + return puzzleX; + } catch (e) { + console.info(e) } - return puzzleX; } async report(n) { @@ -286,7 +299,6 @@ class JDJRValidator { } console.log('验证成功: %f\%', (count / n) * 100); - console.clear() console.timeEnd('PuzzleRecognizer'); } @@ -294,20 +306,19 @@ class JDJRValidator { return new Promise((resolve, reject) => { const fnId = `jsonp_${String(Math.random()).replace('.', '')}`; const extraData = {callback: fnId}; - const query = new URLSearchParams({...DATA,...{"scene": scene}, ...extraData, ...data}).toString(); - const url = `https://${SERVER}${api}?${query}`; + const query = new URLSearchParams({...DATA, ...{"scene": scene}, ...extraData, ...data}).toString(); + const url = `http://${SERVER}${api}?${query}`; const headers = { 'Accept': '*/*', 'Accept-Encoding': 'gzip,deflate,br', - 'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8', + 'Accept-Language': 'zh-CN,en-US', 'Connection': 'keep-alive', - 'Host': "iv.jd.com", + 'Host': SERVER, 'Proxy-Connection': 'keep-alive', - 'Referer': 'https://h5.m.jd.com/', + 'Referer': 'https://h5.m.jd.com/babelDiy/Zeus/2wuqXrZrhygTQzYA7VufBEpj4amH/index.html', 'User-Agent': UA, }; - - const req = https.get(url, {headers}, (response) => { + const req = http.get(url, {headers}, (response) => { let res = response; if (res.headers['content-encoding'] === 'gzip') { const unzipStream = new stream.PassThrough(); @@ -395,7 +406,7 @@ function getCoordinate(c) { return b.join("") } -const HZ = 20; +const HZ = 5; class MousePosFaker { constructor(puzzleX) { @@ -500,32 +511,43 @@ class MousePosFaker { } } -function injectToRequest(fn,scene = 'cww', ua = '') { - if(ua) UA = ua +// new JDJRValidator().run(); +// new JDJRValidator().report(1000); +// console.log(getCoordinate(new MousePosFaker(100).run())); + +function injectToRequest2(fn, scene = 'cww') { return (opts, cb) => { fn(opts, async (err, resp, data) => { - if (err) { - console.error(JSON.stringify(err)); - return; - } - if (data.search('验证') > -1) { - console.log('JDJR验证中......'); - let arr = opts.url.split("&") - let eid = '' - for(let i of arr){ - if(i.indexOf("eid=")>-1){ - eid = i.split("=") && i.split("=")[1] || '' - } - } - const res = await new JDJRValidator().run(scene, eid); - - opts.url += `&validate=${res.validate}`; - fn(opts, cb); - } else { - cb(err, resp, data); + try { + if (err) { + console.error('验证请求失败.'); + return; + } + if (data.search('验证') > -1) { + console.log('JDJR验证中......'); + const res = await new JDJRValidator().run(scene); + if (res) { + opts.url += `&validate=${res.validate}`; + } + fn(opts, cb); + } else { + cb(err, resp, data); + } + } catch (e) { + console.info(e) } }); }; } -exports.injectToRequest = injectToRequest; +async function injectToRequest(scene = 'cww') { + console.log('JDJR验证中......'); + const res = await new JDJRValidator().run(scene); + return `&validate=${res.validate}` +} + +module.exports = { + sleep, + injectToRequest, + injectToRequest2 +} diff --git a/utils/JD_DailyBonus.js b/utils/JD_DailyBonus.js index 19db850..0563f85 100644 --- a/utils/JD_DailyBonus.js +++ b/utils/JD_DailyBonus.js @@ -53,50 +53,50 @@ async function all(cookie, jrBody) { await Promise.all([ JingDongBean(stop), //京东京豆 JingDongStore(stop), //京东超市 - JingRongSteel(stop, jrBody), //金融钢镚 - JingDongTurn(stop), //京东转盘 - JDFlashSale(stop), //京东闪购 - JingDongCash(stop), //京东现金红包 - JDMagicCube(stop, 2), //京东小魔方 - JingDongSubsidy(stop), //京东金贴 + //JingRongSteel(stop, jrBody), //金融钢镚 + //JingDongTurn(stop), //京东转盘 + // JDFlashSale(stop), //京东闪购 + // JingDongCash(stop), //京东现金红包 + // JDMagicCube(stop, 2), //京东小魔方 + //JingDongSubsidy(stop), //京东金贴 JingDongGetCash(stop), //京东领现金 - JingDongShake(stop), //京东摇一摇 - JDSecKilling(stop), //京东秒杀 + //JingDongShake(stop), //京东摇一摇 + //JDSecKilling(stop), //京东秒杀 // JingRongDoll(stop, 'JRDoll', '京东金融-签壹', '4D25A6F482'), // JingRongDoll(stop, 'JRThreeDoll', '京东金融-签叁', '69F5EC743C'), // JingRongDoll(stop, 'JRFourDoll', '京东金融-签肆', '30C4F86264'), // JingRongDoll(stop, 'JRFiveDoll', '京东金融-签伍', '1D06AA3B0F') ]); await Promise.all([ - JDUserSignPre(stop, 'JDUndies', '京东商城-内衣', '4PgpL1xqPSW1sVXCJ3xopDbB1f69'), //京东内衣馆 - JDUserSignPre(stop, 'JDCard', '京东商城-卡包', '7e5fRnma6RBATV9wNrGXJwihzcD'), //京东卡包 + //JDUserSignPre(stop, 'JDUndies', '京东商城-内衣', '4PgpL1xqPSW1sVXCJ3xopDbB1f69'), //京东内衣馆 + //JDUserSignPre(stop, 'JDCard', '京东商城-卡包', '7e5fRnma6RBATV9wNrGXJwihzcD'), //京东卡包 // JDUserSignPre(stop, 'JDCustomized', '京东商城-定制', '2BJK5RBdvc3hdddZDS1Svd5Esj3R'), //京东定制 - JDUserSignPre(stop, 'JDaccompany', '京东商城-陪伴', 'kPM3Xedz1PBiGQjY4ZYGmeVvrts'), //京东陪伴 - JDUserSignPre(stop, 'JDShoes', '京东商城-鞋靴', '4RXyb1W4Y986LJW8ToqMK14BdTD'), //京东鞋靴 - JDUserSignPre(stop, 'JDChild', '京东商城-童装', '3Af6mZNcf5m795T8dtDVfDwWVNhJ'), //京东童装馆 - JDUserSignPre(stop, 'JDBaby', '京东商城-母婴', '3BbAVGQPDd6vTyHYjmAutXrKAos6'), //京东母婴馆 - JDUserSignPre(stop, 'JD3C', '京东商城-数码', '4SWjnZSCTHPYjE5T7j35rxxuMTb6'), //京东数码电器馆 - JDUserSignPre(stop, 'JDWomen', '京东商城-女装', 'DpSh7ma8JV7QAxSE2gJNro8Q2h9'), //京东女装馆 - JDUserSignPre(stop, 'JDBook', '京东商城-图书', '3SC6rw5iBg66qrXPGmZMqFDwcyXi'), //京东图书 + //JDUserSignPre(stop, 'JDaccompany', '京东商城-陪伴', 'kPM3Xedz1PBiGQjY4ZYGmeVvrts'), //京东陪伴 + //JDUserSignPre(stop, 'JDShoes', '京东商城-鞋靴', '4RXyb1W4Y986LJW8ToqMK14BdTD'), //京东鞋靴 + //JDUserSignPre(stop, 'JDChild', '京东商城-童装', '3Af6mZNcf5m795T8dtDVfDwWVNhJ'), //京东童装馆 + //JDUserSignPre(stop, 'JDBaby', '京东商城-母婴', '3BbAVGQPDd6vTyHYjmAutXrKAos6'), //京东母婴馆 + //JDUserSignPre(stop, 'JD3C', '京东商城-数码', '4SWjnZSCTHPYjE5T7j35rxxuMTb6'), //京东数码电器馆 + //JDUserSignPre(stop, 'JDWomen', '京东商城-女装', 'DpSh7ma8JV7QAxSE2gJNro8Q2h9'), //京东女装馆 + //JDUserSignPre(stop, 'JDBook', '京东商城-图书', '3SC6rw5iBg66qrXPGmZMqFDwcyXi'), //京东图书 // JDUserSignPre(stop, 'ReceiveJD', '京东商城-领豆', 'Ni5PUSK7fzZc4EKangHhqPuprn2'), //京东-领京豆 - JingRongDoll(stop, 'JTDouble', '京东金贴-双签', '1DF13833F7'), //京东金融 金贴双签 + //JingRongDoll(stop, 'JTDouble', '京东金贴-双签', '1DF13833F7'), //京东金融 金贴双签 // JingRongDoll(stop, 'XJDouble', '金融现金-双签', 'F68B2C3E71', '', '', '', 'xianjin') //京东金融 现金双签 ]); await Promise.all([ - JDUserSignPre(stop, 'JDStory', '京东失眠-补贴', 'UcyW9Znv3xeyixW1gofhW2DAoz4'), //失眠补贴 - JDUserSignPre(stop, 'JDPhone', '京东手机-小时', '4Vh5ybVr98nfJgros5GwvXbmTUpg'), //手机小时达 - JDUserSignPre(stop, 'JDEsports', '京东商城-电竞', 'CHdHQhA5AYDXXQN9FLt3QUAPRsB'), //京东电竞 - JDUserSignPre(stop, 'JDClothing', '京东商城-服饰', '4RBT3H9jmgYg1k2kBnHF8NAHm7m8'), //京东服饰 - JDUserSignPre(stop, 'JDSuitcase', '京东商城-箱包', 'ZrH7gGAcEkY2gH8wXqyAPoQgk6t'), //京东箱包馆 - JDUserSignPre(stop, 'JDSchool', '京东商城-校园', '2QUxWHx5BSCNtnBDjtt5gZTq7zdZ'), //京东校园 - JDUserSignPre(stop, 'JDHealth', '京东商城-健康', 'w2oeK5yLdHqHvwef7SMMy4PL8LF'), //京东健康 - JDUserSignPre(stop, 'JDShand', '京东拍拍-二手', '3S28janPLYmtFxypu37AYAGgivfp'), //京东拍拍二手 - JDUserSignPre(stop, 'JDClean', '京东商城-清洁', '2Tjm6ay1ZbZ3v7UbriTj6kHy9dn6'), //京东清洁馆 - JDUserSignPre(stop, 'JDCare', '京东商城-个护', '2tZssTgnQsiUqhmg5ooLSHY9XSeN'), //京东个人护理馆 - JDUserSignPre(stop, 'JDJiaDian', '京东商城-家电', '3uvPyw1pwHARGgndatCXddLNUxHw'), // 京东小家电 + //JDUserSignPre(stop, 'JDStory', '京东失眠-补贴', 'UcyW9Znv3xeyixW1gofhW2DAoz4'), //失眠补贴 + //JDUserSignPre(stop, 'JDPhone', '京东手机-小时', '4Vh5ybVr98nfJgros5GwvXbmTUpg'), //手机小时达 + //JDUserSignPre(stop, 'JDEsports', '京东商城-电竞', 'CHdHQhA5AYDXXQN9FLt3QUAPRsB'), //京东电竞 + //JDUserSignPre(stop, 'JDClothing', '京东商城-服饰', '4RBT3H9jmgYg1k2kBnHF8NAHm7m8'), //京东服饰 + // JDUserSignPre(stop, 'JDSuitcase', '京东商城-箱包', 'ZrH7gGAcEkY2gH8wXqyAPoQgk6t'), //京东箱包馆 + //JDUserSignPre(stop, 'JDSchool', '京东商城-校园', '2QUxWHx5BSCNtnBDjtt5gZTq7zdZ'), //京东校园 + //JDUserSignPre(stop, 'JDHealth', '京东商城-健康', 'w2oeK5yLdHqHvwef7SMMy4PL8LF'), //京东健康 + //JDUserSignPre(stop, 'JDShand', '京东拍拍-二手', '3S28janPLYmtFxypu37AYAGgivfp'), //京东拍拍二手 + // JDUserSignPre(stop, 'JDClean', '京东商城-清洁', '2Tjm6ay1ZbZ3v7UbriTj6kHy9dn6'), //京东清洁馆 + // JDUserSignPre(stop, 'JDCare', '京东商城-个护', '2tZssTgnQsiUqhmg5ooLSHY9XSeN'), //京东个人护理馆 + // JDUserSignPre(stop, 'JDJiaDian', '京东商城-家电', '3uvPyw1pwHARGgndatCXddLNUxHw'), // 京东小家电 // JDUserSignPre(stop, 'JDJewels', '京东商城-珠宝', 'zHUHpTHNTaztSRfNBFNVZscyFZU'), //京东珠宝馆 // JDUserSignPre(stop, 'JDMakeup', '京东商城-美妆', '2smCxzLNuam5L14zNJHYu43ovbAP'), //京东美妆馆 - JDUserSignPre(stop, 'JDVege', '京东商城-菜场', 'Wcu2LVCFMkBP3HraRvb7pgSpt64'), //京东菜场 + // JDUserSignPre(stop, 'JDVege', '京东商城-菜场', 'Wcu2LVCFMkBP3HraRvb7pgSpt64'), //京东菜场 // JDUserSignPre(stop, 'JDLive', '京东智能-生活', 'KcfFqWvhb5hHtaQkS4SD1UU6RcQ') //京东智能生活 JDUserSignPre(stop, 'JDPlus', '京东商城-PLUS', '3bhgbFe5HZcFCjEZf2jzp3umx4ZR'), //京东PLUS JDUserSignPre(stop, 'JDStore', '京东超市', 'QPwDgLSops2bcsYqQ57hENGrjgj') //京东超市 @@ -120,36 +120,36 @@ async function all(cookie, jrBody) { // await JingRongDoll(Wait(stop), 'JRFiveDoll', '京东金融-签伍', '1D06AA3B0F'); // await JingRongDoll(Wait(stop), 'JRDoll', '京东金融-签壹', '4D25A6F482'); // await JingRongDoll(Wait(stop), 'XJDouble', '金融现金-双签', 'F68B2C3E71', '', '', '', 'xianjin'); //京东金融 现金双签 - await JingRongDoll(Wait(stop), 'JTDouble', '京东金贴-双签', '1DF13833F7'); //京东金融 金贴双签 - await JDUserSignPre(Wait(stop), 'JDStory', '京东失眠-补贴', 'UcyW9Znv3xeyixW1gofhW2DAoz4'); //失眠补贴 - await JDUserSignPre(Wait(stop), 'JDPhone', '京东手机-小时', '4Vh5ybVr98nfJgros5GwvXbmTUpg'); //手机小时达 - await JDUserSignPre(Wait(stop), 'JDCard', '京东商城-卡包', '7e5fRnma6RBATV9wNrGXJwihzcD'); //京东卡包 - await JDUserSignPre(Wait(stop), 'JDUndies', '京东商城-内衣', '4PgpL1xqPSW1sVXCJ3xopDbB1f69'); //京东内衣馆 - await JDUserSignPre(Wait(stop), 'JDEsports', '京东商城-电竞', 'CHdHQhA5AYDXXQN9FLt3QUAPRsB'); //京东电竞 + // await JingRongDoll(Wait(stop), 'JTDouble', '京东金贴-双签', '1DF13833F7'); //京东金融 金贴双签 + // await JDUserSignPre(Wait(stop), 'JDStory', '京东失眠-补贴', 'UcyW9Znv3xeyixW1gofhW2DAoz4'); //失眠补贴 + // await JDUserSignPre(Wait(stop), 'JDPhone', '京东手机-小时', '4Vh5ybVr98nfJgros5GwvXbmTUpg'); //手机小时达 + // await JDUserSignPre(Wait(stop), 'JDCard', '京东商城-卡包', '7e5fRnma6RBATV9wNrGXJwihzcD'); //京东卡包 + // await JDUserSignPre(Wait(stop), 'JDUndies', '京东商城-内衣', '4PgpL1xqPSW1sVXCJ3xopDbB1f69'); //京东内衣馆 + // await JDUserSignPre(Wait(stop), 'JDEsports', '京东商城-电竞', 'CHdHQhA5AYDXXQN9FLt3QUAPRsB'); //京东电竞 // await JDUserSignPre(Wait(stop), 'JDCustomized', '京东商城-定制', '2BJK5RBdvc3hdddZDS1Svd5Esj3R'); //京东定制 - await JDUserSignPre(Wait(stop), 'JDSuitcase', '京东商城-箱包', 'ZrH7gGAcEkY2gH8wXqyAPoQgk6t'); //京东箱包馆 - await JDUserSignPre(Wait(stop), 'JDClothing', '京东商城-服饰', '4RBT3H9jmgYg1k2kBnHF8NAHm7m8'); //京东服饰 - await JDUserSignPre(Wait(stop), 'JDSchool', '京东商城-校园', '2QUxWHx5BSCNtnBDjtt5gZTq7zdZ'); //京东校园 + // await JDUserSignPre(Wait(stop), 'JDSuitcase', '京东商城-箱包', 'ZrH7gGAcEkY2gH8wXqyAPoQgk6t'); //京东箱包馆 + // await JDUserSignPre(Wait(stop), 'JDClothing', '京东商城-服饰', '4RBT3H9jmgYg1k2kBnHF8NAHm7m8'); //京东服饰 + // await JDUserSignPre(Wait(stop), 'JDSchool', '京东商城-校园', '2QUxWHx5BSCNtnBDjtt5gZTq7zdZ'); //京东校园 await JDUserSignPre(Wait(stop), 'JDHealth', '京东商城-健康', 'w2oeK5yLdHqHvwef7SMMy4PL8LF'); //京东健康 - await JDUserSignPre(Wait(stop), 'JDShoes', '京东商城-鞋靴', '4RXyb1W4Y986LJW8ToqMK14BdTD'); //京东鞋靴 - await JDUserSignPre(Wait(stop), 'JDChild', '京东商城-童装', '3Af6mZNcf5m795T8dtDVfDwWVNhJ'); //京东童装馆 - await JDUserSignPre(Wait(stop), 'JDBaby', '京东商城-母婴', '3BbAVGQPDd6vTyHYjmAutXrKAos6'); //京东母婴馆 - await JDUserSignPre(Wait(stop), 'JD3C', '京东商城-数码', '4SWjnZSCTHPYjE5T7j35rxxuMTb6'); //京东数码电器馆 - await JDUserSignPre(Wait(stop), 'JDWomen', '京东商城-女装', 'DpSh7ma8JV7QAxSE2gJNro8Q2h9'); //京东女装馆 - await JDUserSignPre(Wait(stop), 'JDBook', '京东商城-图书', '3SC6rw5iBg66qrXPGmZMqFDwcyXi'); //京东图书 - await JDUserSignPre(Wait(stop), 'JDShand', '京东拍拍-二手', '3S28janPLYmtFxypu37AYAGgivfp'); //京东拍拍二手 + // await JDUserSignPre(Wait(stop), 'JDShoes', '京东商城-鞋靴', '4RXyb1W4Y986LJW8ToqMK14BdTD'); //京东鞋靴 + // await JDUserSignPre(Wait(stop), 'JDChild', '京东商城-童装', '3Af6mZNcf5m795T8dtDVfDwWVNhJ'); //京东童装馆 + // await JDUserSignPre(Wait(stop), 'JDBaby', '京东商城-母婴', '3BbAVGQPDd6vTyHYjmAutXrKAos6'); //京东母婴馆 + // await JDUserSignPre(Wait(stop), 'JD3C', '京东商城-数码', '4SWjnZSCTHPYjE5T7j35rxxuMTb6'); //京东数码电器馆 + // await JDUserSignPre(Wait(stop), 'JDWomen', '京东商城-女装', 'DpSh7ma8JV7QAxSE2gJNro8Q2h9'); //京东女装馆 + // await JDUserSignPre(Wait(stop), 'JDBook', '京东商城-图书', '3SC6rw5iBg66qrXPGmZMqFDwcyXi'); //京东图书 + // await JDUserSignPre(Wait(stop), 'JDShand', '京东拍拍-二手', '3S28janPLYmtFxypu37AYAGgivfp'); //京东拍拍二手 // await JDUserSignPre(Wait(stop), 'JDMakeup', '京东商城-美妆', '2smCxzLNuam5L14zNJHYu43ovbAP'); //京东美妆馆 - await JDUserSignPre(Wait(stop), 'JDVege', '京东商城-菜场', 'Wcu2LVCFMkBP3HraRvb7pgSpt64'); //京东菜场 + // await JDUserSignPre(Wait(stop), 'JDVege', '京东商城-菜场', 'Wcu2LVCFMkBP3HraRvb7pgSpt64'); //京东菜场 await JDUserSignPre(Wait(stop), 'JDPlus', '京东商城-PLUS', '3bhgbFe5HZcFCjEZf2jzp3umx4ZR'); //京东PLUS - await JDUserSignPre(Wait(stop), 'JDStore', '京东超市', 'QPwDgLSops2bcsYqQ57hENGrjgj'); //京东超市 - await JDUserSignPre(Wait(stop), 'JDaccompany', '京东商城-陪伴', 'kPM3Xedz1PBiGQjY4ZYGmeVvrts'); //京东陪伴 + // await JDUserSignPre(Wait(stop), 'JDStore', '京东超市', 'QPwDgLSops2bcsYqQ57hENGrjgj'); //京东超市 + // await JDUserSignPre(Wait(stop), 'JDaccompany', '京东商城-陪伴', 'kPM3Xedz1PBiGQjY4ZYGmeVvrts'); //京东陪伴 // await JDUserSignPre(Wait(stop), 'JDLive', '京东智能-生活', 'KcfFqWvhb5hHtaQkS4SD1UU6RcQ'); //京东智能生活 - await JDUserSignPre(Wait(stop), 'JDClean', '京东商城-清洁', '2Tjm6ay1ZbZ3v7UbriTj6kHy9dn6'); //京东清洁馆 - await JDUserSignPre(Wait(stop), 'JDCare', '京东商城-个护', '2tZssTgnQsiUqhmg5ooLSHY9XSeN'); //京东个人护理馆 - await JDUserSignPre(Wait(stop), 'JDJiaDian', '京东商城-家电', '3uvPyw1pwHARGgndatCXddLNUxHw'); // 京东小家电馆 + // await JDUserSignPre(Wait(stop), 'JDClean', '京东商城-清洁', '2Tjm6ay1ZbZ3v7UbriTj6kHy9dn6'); //京东清洁馆 + // await JDUserSignPre(Wait(stop), 'JDCare', '京东商城-个护', '2tZssTgnQsiUqhmg5ooLSHY9XSeN'); //京东个人护理馆 + // await JDUserSignPre(Wait(stop), 'JDJiaDian', '京东商城-家电', '3uvPyw1pwHARGgndatCXddLNUxHw'); // 京东小家电馆 // await JDUserSignPre(Wait(stop), 'ReceiveJD', '京东商城-领豆', 'Ni5PUSK7fzZc4EKangHhqPuprn2'); //京东-领京豆 // await JDUserSignPre(Wait(stop), 'JDJewels', '京东商城-珠宝', 'zHUHpTHNTaztSRfNBFNVZscyFZU'); //京东珠宝馆 - await JingRongDoll(Wait(stop), 'JDDouble', '金融京豆-双签', 'F68B2C3E71', '', '', '', 'jingdou'); //京东金融 京豆双签 + //await JingRongDoll(Wait(stop), 'JDDouble', '金融京豆-双签', 'F68B2C3E71', '', '', '', 'jingdou'); //京东金融 京豆双签 break; } await Promise.all([ diff --git a/utils/jd_appopen.js b/utils/jd_appopen.js new file mode 100644 index 0000000..2116c1f --- /dev/null +++ b/utils/jd_appopen.js @@ -0,0 +1,306 @@ +/* + +杀掉后台后打开京东app获取app_open +在脚本日志查看值 + +[MITM] +hostname = api.m.jd.com + +===========Surge================= +[Script] +jd_appopen = type=http-request,pattern=^https:\/\/api\.m\.jd\.com\/openUpgrade, max-size=0, script-path=jd_appopen.js + +===================Quantumult X===================== +[rewrite_local] +# jd_appopen +^https:\/\/api\.m\.jd\.com\/openUpgrade url script-request-header jd_appopen.js + +=====================Loon===================== +[Script] +http-request ^https:\/\/api\.m\.jd\.com\/openUpgrade script-path=jd_appopen.js, timeout=3600, tag=jd_appopen + +*/ + +const $ = new Env("app_open") + +let cookie = $request.headers.Cookie +let pt_key = cookie.match(/(pt_key=[^;]*)/)[1] +let pt_pin = cookie.match(/(pt_pin=[^;]*)/)[1] +console.log('================') +console.log(`${pt_key};${pt_pin};`) +console.log('================') +$.msg("app_open获取成功!", "在运行日志中查看") + +function Env(t, e) { + "undefined" != typeof process && JSON.stringify(process.env).indexOf("GITHUB") > -1 && process.exit(0); + + class s { + constructor(t) { + this.env = t + } + + send(t, e = "GET") { + t = "string" == typeof t ? {url: t} : t; + let s = this.get; + return "POST" === e && (s = this.post), new Promise((e, i) => { + s.call(this, t, (t, s, r) => { + t ? i(t) : e(s) + }) + }) + } + + get(t) { + return this.send.call(this.env, t) + } + + post(t) { + return this.send.call(this.env, t, "POST") + } + } + + return new class { + constructor(t, e) { + this.name = t, this.http = new s(this), this.data = null, this.dataFile = "box.dat", this.logs = [], this.isMute = !1, this.isNeedRewrite = !1, this.logSeparator = "\n", this.startTime = (new Date).getTime(), Object.assign(this, e), this.log("", `🔔${this.name}, 开始!`) + } + + 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 + } + + toObj(t, e = null) { + try { + return JSON.parse(t) + } catch { + return e + } + } + + toStr(t, e = null) { + try { + return JSON.stringify(t) + } catch { + return e + } + } + + getjson(t, e) { + let s = e; + const i = this.getdata(t); + if (i) try { + s = JSON.parse(this.getdata(t)) + } catch { + } + return s + } + + setjson(t, e) { + try { + return this.setdata(JSON.stringify(t), e) + } catch { + return !1 + } + } + + getScript(t) { + return new Promise(e => { + this.get({url: t}, (t, s, i) => e(i)) + }) + } + + runScript(t, e) { + return new Promise(s => { + let i = this.getdata("@chavy_boxjs_userCfgs.httpapi"); + i = i ? i.replace(/\n/g, "").trim() : i; + let r = this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout"); + r = r ? 1 * r : 20, r = e && e.timeout ? e.timeout : r; + const [o, h] = i.split("@"), n = {url: `http://${h}/v1/scripting/evaluate`, body: {script_text: t, mock_type: "cron", timeout: r}, headers: {"X-Key": o, Accept: "*/*"}}; + this.post(n, (t, e, i) => s(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), e = this.path.resolve(process.cwd(), this.dataFile), s = this.fs.existsSync(t), i = !s && this.fs.existsSync(e); + if (!s && !i) return {}; + { + const i = s ? t : e; + 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), e = this.path.resolve(process.cwd(), this.dataFile), s = this.fs.existsSync(t), i = !s && this.fs.existsSync(e), r = JSON.stringify(this.data); + s ? this.fs.writeFileSync(t, r) : i ? this.fs.writeFileSync(e, r) : this.fs.writeFileSync(t, r) + } + } + + lodash_get(t, e, s) { + const i = e.replace(/\[(\d+)\]/g, ".$1").split("."); + let r = t; + for (const t of i) if (r = Object(r)[t], void 0 === r) return s; + return r + } + + lodash_set(t, e, s) { + return Object(t) !== t ? t : (Array.isArray(e) || (e = e.toString().match(/[^.[\]]+/g) || []), e.slice(0, -1).reduce((t, s, i) => Object(t[s]) === t[s] ? t[s] : t[s] = Math.abs(e[i + 1]) >> 0 == +e[i + 1] ? [] : {}, t)[e[e.length - 1]] = s, t) + } + + getdata(t) { + let e = this.getval(t); + if (/^@/.test(t)) { + const [, s, i] = /^@(.*?)\.(.*?)$/.exec(t), r = s ? this.getval(s) : ""; + if (r) try { + const t = JSON.parse(r); + e = t ? this.lodash_get(t, i, "") : e + } catch (t) { + e = "" + } + } + return e + } + + setdata(t, e) { + let s = !1; + if (/^@/.test(e)) { + const [, i, r] = /^@(.*?)\.(.*?)$/.exec(e), o = this.getval(i), h = i ? "null" === o ? null : o || "{}" : "{}"; + try { + const e = JSON.parse(h); + this.lodash_set(e, r, t), s = this.setval(JSON.stringify(e), i) + } catch (e) { + const o = {}; + this.lodash_set(o, r, t), s = this.setval(JSON.stringify(o), i) + } + } else s = this.setval(t, e); + return s + } + + 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, e) { + return this.isSurge() || this.isLoon() ? $persistentStore.write(t, e) : this.isQuanX() ? $prefs.setValueForKey(t, e) : this.isNode() ? (this.data = this.loaddata(), this.data[e] = t, this.writedata(), !0) : this.data && this.data[e] || 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, e = (() => { + })) { + t.headers && (delete t.headers["Content-Type"], delete t.headers["Content-Length"]), this.isSurge() || this.isLoon() ? (this.isSurge() && this.isNeedRewrite && (t.headers = t.headers || {}, Object.assign(t.headers, {"X-Surge-Skip-Scripting": !1})), $httpClient.get(t, (t, s, i) => { + !t && s && (s.body = i, s.statusCode = s.status), e(t, s, i) + })) : this.isQuanX() ? (this.isNeedRewrite && (t.opts = t.opts || {}, Object.assign(t.opts, {hints: !1})), $task.fetch(t).then(t => { + const {statusCode: s, statusCode: i, headers: r, body: o} = t; + e(null, {status: s, statusCode: i, headers: r, body: o}, o) + }, t => e(t))) : this.isNode() && (this.initGotEnv(t), this.got(t).on("redirect", (t, e) => { + try { + if (t.headers["set-cookie"]) { + const s = t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString(); + s && this.ckjar.setCookieSync(s, null), e.cookieJar = this.ckjar + } + } catch (t) { + this.logErr(t) + } + }).then(t => { + const {statusCode: s, statusCode: i, headers: r, body: o} = t; + e(null, {status: s, statusCode: i, headers: r, body: o}, o) + }, t => { + const {message: s, response: i} = t; + e(s, i, i && i.body) + })) + } + + post(t, e = (() => { + })) { + if (t.body && t.headers && !t.headers["Content-Type"] && (t.headers["Content-Type"] = "application/x-www-form-urlencoded"), t.headers && delete t.headers["Content-Length"], this.isSurge() || this.isLoon()) this.isSurge() && this.isNeedRewrite && (t.headers = t.headers || {}, Object.assign(t.headers, {"X-Surge-Skip-Scripting": !1})), $httpClient.post(t, (t, s, i) => { + !t && s && (s.body = i, s.statusCode = s.status), e(t, s, i) + }); else if (this.isQuanX()) t.method = "POST", this.isNeedRewrite && (t.opts = t.opts || {}, Object.assign(t.opts, {hints: !1})), $task.fetch(t).then(t => { + const {statusCode: s, statusCode: i, headers: r, body: o} = t; + e(null, {status: s, statusCode: i, headers: r, body: o}, o) + }, t => e(t)); else if (this.isNode()) { + this.initGotEnv(t); + const {url: s, ...i} = t; + this.got.post(s, i).then(t => { + const {statusCode: s, statusCode: i, headers: r, body: o} = t; + e(null, {status: s, statusCode: i, headers: r, body: o}, o) + }, t => { + const {message: s, response: i} = t; + e(s, i, i && i.body) + }) + } + } + + time(t, e = null) { + const s = e ? new Date(e) : new Date; + let i = {"M+": s.getMonth() + 1, "d+": s.getDate(), "H+": s.getHours(), "m+": s.getMinutes(), "s+": s.getSeconds(), "q+": Math.floor((s.getMonth() + 3) / 3), S: s.getMilliseconds()}; + /(y+)/.test(t) && (t = t.replace(RegExp.$1, (s.getFullYear() + "").substr(4 - RegExp.$1.length))); + for (let e in i) new RegExp("(" + e + ")").test(t) && (t = t.replace(RegExp.$1, 1 == RegExp.$1.length ? i[e] : ("00" + i[e]).substr(("" + i[e]).length))); + return t + } + + msg(e = t, s = "", i = "", r) { + const o = t => { + if (!t) return t; + if ("string" == typeof t) return this.isLoon() ? t : this.isQuanX() ? {"open-url": t} : this.isSurge() ? {url: t} : void 0; + if ("object" == typeof t) { + if (this.isLoon()) { + let e = t.openUrl || t.url || t["open-url"], s = t.mediaUrl || t["media-url"]; + return {openUrl: e, mediaUrl: s} + } + if (this.isQuanX()) { + let e = t["open-url"] || t.url || t.openUrl, s = t["media-url"] || t.mediaUrl; + return {"open-url": e, "media-url": s} + } + if (this.isSurge()) { + let e = t.url || t.openUrl || t["open-url"]; + return {url: e} + } + } + }; + if (this.isMute || (this.isSurge() || this.isLoon() ? $notification.post(e, s, i, o(r)) : this.isQuanX() && $notify(e, s, i, o(r))), !this.isMuteLog) { + let t = ["", "==============📣系统通知📣=============="]; + t.push(e), s && t.push(s), i && t.push(i), console.log(t.join("\n")), this.logs = this.logs.concat(t) + } + } + + log(...t) { + t.length > 0 && (this.logs = [...this.logs, ...t]), console.log(t.join(this.logSeparator)) + } + + logErr(t, e) { + const s = !this.isSurge() && !this.isQuanX() && !this.isLoon(); + s ? this.log("", `❗️${this.name}, 错误!`, t.stack) : this.log("", `❗️${this.name}, 错误!`, t) + } + + wait(t) { + return new Promise(e => setTimeout(e, t)) + } + + done(t = {}) { + const e = (new Date).getTime(), s = (e - this.startTime) / 1e3; + this.log("", `🔔${this.name}, 结束! 🕛 ${s} 秒`), this.log(), (this.isSurge() || this.isQuanX() || this.isLoon()) && $done(t) + } + }(t, e) +} diff --git a/utils/jd_jxmcToken.js b/utils/jd_jxmcToken.js new file mode 100644 index 0000000..16cddaa --- /dev/null +++ b/utils/jd_jxmcToken.js @@ -0,0 +1,91 @@ +function t(n, t) { + var r = (65535 & n) + (65535 & t); + return (n >> 16) + (t >> 16) + (r >> 16) << 16 | 65535 & r +} + +function r(n, t) { + return n << t | n >>> 32 - t +} + +function e(n, e, o, u, c, f) { + return t(r(t(t(e, n), t(u, f)), c), o) +} + +function o(n, t, r, o, u, c, f) { + return e(t & r | ~t & o, n, t, u, c, f) +} + +function u(n, t, r, o, u, c, f) { + return e(t & o | r & ~o, n, t, u, c, f) +} + +function c(n, t, r, o, u, c, f) { + return e(t ^ r ^ o, n, t, u, c, f) +} + +function f(n, t, r, o, u, c, f) { + return e(r ^ (t | ~o), n, t, u, c, f) +} + +function i(n, r) { + n[r >> 5] |= 128 << r % 32, n[14 + (r + 64 >>> 9 << 4)] = r; + var e, i, a, d, h, l = 1732584193, g = -271733879, v = -1732584194, m = 271733878; + for (e = 0; e < n.length; e += 16) i = l, a = g, d = v, h = m, g = f(g = f(g = f(g = f(g = c(g = c(g = c(g = c(g = u(g = u(g = u(g = u(g = o(g = o(g = o(g = o(g, v = o(v, m = o(m, l = o(l, g, v, m, n[e], 7, -680876936), g, v, n[e + 1], 12, -389564586), l, g, n[e + 2], 17, 606105819), m, l, n[e + 3], 22, -1044525330), v = o(v, m = o(m, l = o(l, g, v, m, n[e + 4], 7, -176418897), g, v, n[e + 5], 12, 1200080426), l, g, n[e + 6], 17, -1473231341), m, l, n[e + 7], 22, -45705983), v = o(v, m = o(m, l = o(l, g, v, m, n[e + 8], 7, 1770035416), g, v, n[e + 9], 12, -1958414417), l, g, n[e + 10], 17, -42063), m, l, n[e + 11], 22, -1990404162), v = o(v, m = o(m, l = o(l, g, v, m, n[e + 12], 7, 1804603682), g, v, n[e + 13], 12, -40341101), l, g, n[e + 14], 17, -1502002290), m, l, n[e + 15], 22, 1236535329), v = u(v, m = u(m, l = u(l, g, v, m, n[e + 1], 5, -165796510), g, v, n[e + 6], 9, -1069501632), l, g, n[e + 11], 14, 643717713), m, l, n[e], 20, -373897302), v = u(v, m = u(m, l = u(l, g, v, m, n[e + 5], 5, -701558691), g, v, n[e + 10], 9, 38016083), l, g, n[e + 15], 14, -660478335), m, l, n[e + 4], 20, -405537848), v = u(v, m = u(m, l = u(l, g, v, m, n[e + 9], 5, 568446438), g, v, n[e + 14], 9, -1019803690), l, g, n[e + 3], 14, -187363961), m, l, n[e + 8], 20, 1163531501), v = u(v, m = u(m, l = u(l, g, v, m, n[e + 13], 5, -1444681467), g, v, n[e + 2], 9, -51403784), l, g, n[e + 7], 14, 1735328473), m, l, n[e + 12], 20, -1926607734), v = c(v, m = c(m, l = c(l, g, v, m, n[e + 5], 4, -378558), g, v, n[e + 8], 11, -2022574463), l, g, n[e + 11], 16, 1839030562), m, l, n[e + 14], 23, -35309556), v = c(v, m = c(m, l = c(l, g, v, m, n[e + 1], 4, -1530992060), g, v, n[e + 4], 11, 1272893353), l, g, n[e + 7], 16, -155497632), m, l, n[e + 10], 23, -1094730640), v = c(v, m = c(m, l = c(l, g, v, m, n[e + 13], 4, 681279174), g, v, n[e], 11, -358537222), l, g, n[e + 3], 16, -722521979), m, l, n[e + 6], 23, 76029189), v = c(v, m = c(m, l = c(l, g, v, m, n[e + 9], 4, -640364487), g, v, n[e + 12], 11, -421815835), l, g, n[e + 15], 16, 530742520), m, l, n[e + 2], 23, -995338651), v = f(v, m = f(m, l = f(l, g, v, m, n[e], 6, -198630844), g, v, n[e + 7], 10, 1126891415), l, g, n[e + 14], 15, -1416354905), m, l, n[e + 5], 21, -57434055), v = f(v, m = f(m, l = f(l, g, v, m, n[e + 12], 6, 1700485571), g, v, n[e + 3], 10, -1894986606), l, g, n[e + 10], 15, -1051523), m, l, n[e + 1], 21, -2054922799), v = f(v, m = f(m, l = f(l, g, v, m, n[e + 8], 6, 1873313359), g, v, n[e + 15], 10, -30611744), l, g, n[e + 6], 15, -1560198380), m, l, n[e + 13], 21, 1309151649), v = f(v, m = f(m, l = f(l, g, v, m, n[e + 4], 6, -145523070), g, v, n[e + 11], 10, -1120210379), l, g, n[e + 2], 15, 718787259), m, l, n[e + 9], 21, -343485551), l = t(l, i), g = t(g, a), v = t(v, d), m = t(m, h); + return [l, g, v, m] +} + +function a(n) { + var t, r = "", e = 32 * n.length; + for (t = 0; t < e; t += 8) r += String.fromCharCode(n[t >> 5] >>> t % 32 & 255); + return r +} + +function d(n) { + var t, r = []; + for (r[(n.length >> 2) - 1] = void 0, t = 0; t < r.length; t += 1) r[t] = 0; + var e = 8 * n.length; + for (t = 0; t < e; t += 8) r[t >> 5] |= (255 & n.charCodeAt(t / 8)) << t % 32; + return r +} + +function h(n) { + return a(i(d(n), 8 * n.length)) +} + +function l(n, t) { + var r, e, o = d(n), u = [], c = []; + for (u[15] = c[15] = void 0, o.length > 16 && (o = i(o, 8 * n.length)), r = 0; r < 16; r += 1) u[r] = 909522486 ^ o[r], c[r] = 1549556828 ^ o[r]; + return e = i(u.concat(d(t)), 512 + 8 * t.length), a(i(c.concat(e), 640)) +} + +function g(n) { + var t, r, e = ""; + for (r = 0; r < n.length; r += 1) t = n.charCodeAt(r), e += "0123456789abcdef".charAt(t >>> 4 & 15) + "0123456789abcdef".charAt(15 & t); + return e +} + +function v(n) { + return unescape(encodeURIComponent(n)) +} + +function m(n) { + return h(v(n)) +} + +function p(n) { + return g(m(n)) +} + +function s(n, t) { + return l(v(n), v(t)) +} + +function C(n, t) { + return g(s(n, t)) +} + +function A(n, t, r) { + return t ? r ? s(t, n) : C(t, n) : r ? m(n) : p(n) +} + +module.exports = A \ No newline at end of file diff --git a/utils/magic.js b/utils/magic.js new file mode 100644 index 0000000..8d96505 --- /dev/null +++ b/utils/magic.js @@ -0,0 +1,760 @@ +// noinspection JSUnresolvedFunction,JSUnresolvedVariable + +const axios = require('axios'); +const fs = require("fs"); +const {format} = require("date-fns"); +const notify = require('../sendNotify'); +const jdCookieNode = require('../jdCookie.js'); +const CryptoJS = require("crypto-js"); +const got = require("got"); +let cookies = []; +let testMode = process.env.TEST_MODE?.includes('on') ? true + : __dirname.includes("magic") +Object.keys(jdCookieNode).forEach((item) => { + cookies.push(jdCookieNode[item]) +}) + +const USER_AGENTS = [ + "jdapp;android;10.0.2;10;network/wifi;Mozilla/5.0 (Linux; Android 10; ONEPLUS A5010 Build/QKQ1.191014.012; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.120 MQQBrowser/6.2 TBS/045230 Mobile Safari/537.36", + "jdapp;iPhone;10.0.2;14.3;network/4g;Mozilla/5.0 (iPhone; CPU iPhone OS 14_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1", + "jdapp;android;10.0.2;9;network/4g;Mozilla/5.0 (Linux; Android 9; Mi Note 3 Build/PKQ1.181007.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/66.0.3359.126 MQQBrowser/6.2 TBS/045131 Mobile Safari/537.36", + "jdapp;android;10.0.2;10;network/wifi;Mozilla/5.0 (Linux; Android 10; GM1910 Build/QKQ1.190716.003; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.120 MQQBrowser/6.2 TBS/045230 Mobile Safari/537.36", + "jdapp;android;10.0.2;9;network/wifi;Mozilla/5.0 (Linux; Android 9; 16T Build/PKQ1.190616.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/66.0.3359.126 MQQBrowser/6.2 TBS/044942 Mobile Safari/537.36", + "jdapp;iPhone;10.0.2;13.6;network/wifi;Mozilla/5.0 (iPhone; CPU iPhone OS 13_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1", + "jdapp;iPhone;10.0.2;13.6;network/wifi;Mozilla/5.0 (iPhone; CPU iPhone OS 13_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1", + "jdapp;iPhone;10.0.2;13.5;network/wifi;Mozilla/5.0 (iPhone; CPU iPhone OS 13_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1", + "jdapp;iPhone;10.0.2;14.1;network/wifi;Mozilla/5.0 (iPhone; CPU iPhone OS 14_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1", + "jdapp;iPhone;10.0.2;13.3;network/wifi;Mozilla/5.0 (iPhone; CPU iPhone OS 13_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1", + "jdapp;iPhone;10.0.2;13.7;network/wifi;Mozilla/5.0 (iPhone; CPU iPhone OS 13_7 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1", + "jdapp;iPhone;10.0.2;14.1;network/wifi;Mozilla/5.0 (iPhone; CPU iPhone OS 14_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1", + "jdapp;iPhone;10.0.2;13.3;network/wifi;Mozilla/5.0 (iPhone; CPU iPhone OS 13_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1", + "jdapp;iPhone;10.0.2;13.4;network/wifi;Mozilla/5.0 (iPhone; CPU iPhone OS 13_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1", + "jdapp;iPhone;10.0.2;14.3;network/wifi;Mozilla/5.0 (iPhone; CPU iPhone OS 14_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1", + "jdapp;android;10.0.2;9;network/wifi;Mozilla/5.0 (Linux; Android 9; MI 6 Build/PKQ1.190118.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/66.0.3359.126 MQQBrowser/6.2 TBS/044942 Mobile Safari/537.36", + "jdapp;android;10.0.2;11;network/wifi;Mozilla/5.0 (Linux; Android 11; Redmi K30 5G Build/RKQ1.200826.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.120 MQQBrowser/6.2 TBS/045511 Mobile Safari/537.36", + "jdapp;iPhone;10.0.2;11.4;network/wifi;Mozilla/5.0 (iPhone; CPU iPhone OS 11_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15F79", + "jdapp;android;10.0.2;10;;network/wifi;Mozilla/5.0 (Linux; Android 10; M2006J10C Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.120 MQQBrowser/6.2 TBS/045230 Mobile Safari/537.36", + "jdapp;android;10.0.2;10;network/wifi;Mozilla/5.0 (Linux; Android 10; M2006J10C Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.120 MQQBrowser/6.2 TBS/045230 Mobile Safari/537.36", + "jdapp;android;10.0.2;10;network/wifi;Mozilla/5.0 (Linux; Android 10; ONEPLUS A6000 Build/QKQ1.190716.003; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.120 MQQBrowser/6.2 TBS/045224 Mobile Safari/537.36", + "jdapp;android;10.0.2;9;network/wifi;Mozilla/5.0 (Linux; Android 9; MHA-AL00 Build/HUAWEIMHA-AL00; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/66.0.3359.126 MQQBrowser/6.2 TBS/044942 Mobile Safari/537.36", + "jdapp;android;10.0.2;8.1.0;network/wifi;Mozilla/5.0 (Linux; Android 8.1.0; 16 X Build/OPM1.171019.026; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/66.0.3359.126 MQQBrowser/6.2 TBS/044942 Mobile Safari/537.36", + "jdapp;android;10.0.2;8.0.0;network/wifi;Mozilla/5.0 (Linux; Android 8.0.0; HTC U-3w Build/OPR6.170623.013; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/66.0.3359.126 MQQBrowser/6.2 TBS/044942 Mobile Safari/537.36", + "jdapp;iPhone;10.0.2;14.0.1;network/wifi;Mozilla/5.0 (iPhone; CPU iPhone OS 14_0_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1", + "jdapp;android;10.0.2;10;network/wifi;Mozilla/5.0 (Linux; Android 10; LYA-AL00 Build/HUAWEILYA-AL00L; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.120 MQQBrowser/6.2 TBS/045230 Mobile Safari/537.36", + "jdapp;iPhone;10.0.2;14.2;network/wifi;Mozilla/5.0 (iPhone; CPU iPhone OS 14_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1", + "jdapp;iPhone;10.0.2;14.3;network/wifi;Mozilla/5.0 (iPhone; CPU iPhone OS 14_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1", + "jdapp;iPhone;10.0.2;14.2;network/wifi;Mozilla/5.0 (iPhone; CPU iPhone OS 14_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1", + "jdapp;android;10.0.2;8.1.0;network/wifi;Mozilla/5.0 (Linux; Android 8.1.0; MI 8 Build/OPM1.171019.026; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/66.0.3359.126 MQQBrowser/6.2 TBS/045131 Mobile Safari/537.36", + "jdapp;android;10.0.2;10;network/wifi;Mozilla/5.0 (Linux; Android 10; Redmi K20 Pro Premium Edition Build/QKQ1.190825.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.120 MQQBrowser/6.2 TBS/045227 Mobile Safari/537.36", + "jdapp;iPhone;10.0.2;14.3;network/wifi;Mozilla/5.0 (iPhone; CPU iPhone OS 14_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1", + "jdapp;iPhone;10.0.2;14.3;network/4g;Mozilla/5.0 (iPhone; CPU iPhone OS 14_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1", + "jdapp;android;10.0.2;11;network/wifi;Mozilla/5.0 (Linux; Android 11; Redmi K20 Pro Premium Edition Build/RKQ1.200826.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.120 MQQBrowser/6.2 TBS/045513 Mobile Safari/537.36", + "jdapp;android;10.0.2;10;network/wifi;Mozilla/5.0 (Linux; Android 10; MI 8 Build/QKQ1.190828.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.120 MQQBrowser/6.2 TBS/045227 Mobile Safari/537.36", + "jdapp;iPhone;10.0.2;14.1;network/wifi;Mozilla/5.0 (iPhone; CPU iPhone OS 14_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1", +] + +const $ = axios.create({timeout: 24000}); +$.defaults.headers['Accept'] = '*/*'; +$.defaults.headers['User-Agent'] = USER_AGENTS[randomNumber(0, + USER_AGENTS.length)]; +$.defaults.headers['Connection'] = 'keep-alive'; +$.defaults.headers['Accept-Language'] = "zh-CN,zh-Hans;q=0.9"; +$.defaults.headers['Accept-Encoding'] = "gzip, deflate, br"; + + +function randomNumber(min = 0, max = 100) { + return Math.min(Math.floor(min + Math.random() * (max - min)), max); +} + +class Env { + constructor(name) { + this.name = name + this.username = ''; + this.cookie = ''; + this.cookies = []; + this.index = ''; + this.ext = []; + this.msg = []; + this.delimiter = ''; + this.filename = '' + this.appId = ''; + this.algo = {}; + this.bot = false; + this.expire = false; + } + + async run(data = { + wait: [1000, 2000], + bot: false, + delimiter: '', + o2o: false, + random: false, + once: false, + blacklist: [], + whitelist: [] + }) { + this.filename = process.argv[1]; + console.log(`${this.now()} ${this.name} ${this.filename} 开始运行...`); + this.start = this.timestamp(); + await this.config() + if (data?.delimiter) { + this.delimiter = data?.delimiter + } + if (data?.bot) { + this.bot = data.bot; + } + if (data?.blacklist?.length > 0) { + for (const cki of data.blacklist) { + delete cookies[cki - 1]; + } + } + if (data?.whitelist?.length > 0) { + let cks = [] + for (const cki of data.whitelist) { + if (cki - 1 < cookies.length) { + cks.push(cookies[cki - 1]) + } + } + cookies = cks; + } + if (data?.random) { + cookies = this.randomArray(cookies) + } + await this.verify() + this.cookies = cookies; + if (data?.before) { + for (let i = 0; i <= this.cookies.length; i++) { + if (this.cookies[i] && !this.expire) { + let cookie = this.cookies[i]; + this.cookie = cookie; + this.username = decodeURIComponent( + cookie.match(/pt_pin=([^; ]+)(?=;?)/)[1]); + $.defaults.headers['Cookie'] = this.cookie; + this.index = i + 1; + let me = { + username: this.username, + index: this.index, + cookie: this.cookie + }; + try { + this.ext.push(Object.assign(me, await this.before())); + } catch (e) { + console.log(e) + } + if (data?.wait?.length > 0 && this.index + !== cookies.length) { + await this.wait(data?.wait[0], data?.wait[1]) + } + } + } + } + let once = false; + for (let i = 0; i <= this.cookies.length; i++) { + if (this.cookies[i] && !this.expire) { + this.index = i + 1; + if (data?.once && this.index !== data.once) { + once = true; + continue; + } + let cookie = this.cookies[i]; + this.cookie = cookie; + this.username = decodeURIComponent( + cookie.match(/pt_pin=([^; ]+)(?=;?)/)[1]); + $.defaults.headers['Cookie'] = this.cookie; + this.index = i + 1; + try { + await this.logic() + if (data?.o2o) { + await this.send(); + testMode ? this.log(this.msg.join("\n")) : '' + this.msg = []; + } + if (once) { + break; + } + } catch (e) { + this.log('捕获异常', e) + } + if (data?.wait?.length > 0 && this.index !== cookies.length) { + await this.wait(data?.wait[0], data?.wait[1]) + } + } + } + await this.after() + console.log(`${this.now()} ${this.name} 运行结束,耗时 ${this.timestamp() + - this.start}ms\n`) + testMode && this.msg.length > 0 ? console.log(this.msg.join("\n")) : '' + if (!data?.o2o) { + await this.send(); + } + } + + async config() { + + } + + deleteCookie() { + delete this.cookies[this.index - 1] + return {}; + } + + groupBy(arr, fn) { + const data = {}; + arr.forEach(function (o) { + const k = fn(o); + data[k] = data[k] || [] + data[k].push(o) + }) + + return data; + } + + async send() { + if (this.msg?.length > 0) { + this.msg.push( + '运行时长:' + ((this.timestamp() - this.start) / 1000).toFixed(2) + + 's') + if (this.bot) { + await notify.sendNotify("/" + this.name, + this.msg.join(this.delimiter || '')) + } else { + await notify.sendNotify(this.name, this.msg.join("\n")) + } + } + } + + async verify() { + let fn = this.filename + + function av(s) { + return s.trim().match(/([a-z_])*$/)[0]; + } + + let x = '109M95O106F120V95B', y = '99M102F100O', z = '109H99V', + j = '102N97I99D116T111G114A121B', k = '112C112U', + l = '109N95G106B100K95U', m = '119V120M'; + let reg = /[A-Z]/; + x.concat(y).split(reg).map(o => +o).filter(o => o > 0).forEach( + o => y += String.fromCharCode(o)) + x.concat(z).split(reg).map(o => +o).filter(o => o > 0).forEach( + o => z += String.fromCharCode(o)) + x.concat(j).split(reg).map(o => +o).filter(o => o > 0).forEach( + o => j += String.fromCharCode(o)) + x.concat(k).split(reg).map(o => +o).filter(o => o > 0).forEach( + o => k += String.fromCharCode(o)) + l.concat(m).split(reg).map(o => +o).filter(o => o > 0).forEach( + o => m += String.fromCharCode(o)) + this.appId = fn ? this.name.slice(0, 1) + === String.fromCharCode(77) + ? (fn.includes(av(y)) ? '10032' : + fn.includes(av(z)) ? '10028' : + fn.includes(av(j)) ? '10001' : + fn.includes(av(k)) ? '10038' : + fn.includes(av(m)) ? 'wx' : '') : '' + : ''; + this.appId ? this.algo = await this._algo() : ''; + } + + async wait(min, max) { + if (max) { + return new Promise( + (resolve) => setTimeout(resolve, this.random(min, max))); + } else { + return new Promise((resolve) => setTimeout(resolve, min)); + } + } + + putMsg(msg) { + this.log(msg) + let r = [[' ', ''], ['优惠券', '券'], ['东券', '券'], ['店铺', ''], + ['恭喜', ''], ['获得', '']] + for (let ele of r) { + msg = msg.replace(ele[0], ele[1]) + } + if (this.bot) { + this.msg.push(msg) + } else { + if (this.msg.length > 0 && this.msg[this.msg.length - 1].includes( + this.username)) { + this.msg[this.msg.length - 1] = this.msg[this.msg.length + - 1].split(" ")[0] + ' ' + [this.msg[this.msg.length - 1].split( + " ")[1], msg].join(',') + } else { + this.msg.push(`【当前账号】${this.username} ${msg}`) + } + } + } + + md5(str) { + return CryptoJS.MD5(str).toString() + } + + HmacSHA256(param, key) { + return CryptoJS.HmacSHA256(param, key).toString() + } + + log(...msg) { + this.s ? console.log(...msg) : console.log( + `${this.now()} ${this.username}`, ...msg) + } + + //并 + union(a, b) { + return a.concat(b.filter(o => !a.includes(o))) + } + + //交 + intersection(a, b) { + return a.filter(o => b.includes(o)) + } + + //交 + different(a, b) { + return a.concat(b).filter(o => a.includes(o) && !b.includes(o)) + } + + build(url) { + if (url.match(/&callback=(jsonpCBK(.*))&/)) { + let cb = url.match(/&callback=(jsonpCBK(.*))&/); + url = url.replace(cb[1], this.randomCallback(cb[2].length || 0)) + } + let stk = decodeURIComponent(this.getQueryString(url, '_stk') || ''); + if (stk) { + let ens, hash, st = '', + ts = this.now('yyyyMMddHHmmssSSS').toString(), + tk = this.algo.tk, fp = this.algo.fp, em = this.algo.em; + if (tk && fp && em) { + hash = em(tk, fp, ts, this.appId, CryptoJS).toString( + CryptoJS.enc.Hex) + } else { + const random = '5gkjB6SpmC9s'; + tk = 'tk01wcdf61cb3a8nYUtHcmhSUFFCfddDPRvKvYaMjHkxo6Aj7dhzO+GXGFa9nPXfcgT+mULoF1b1YIS1ghvSlbwhE0Xc'; + fp = '9686767825751161'; + hash = CryptoJS.SHA512( + `${tk}${fp}${ts}${this.appId}${random}`, + tk).toString(CryptoJS.enc.Hex); + } + stk.split(',').map((item, index) => { + st += `${item}:${this.getQueryString(url, item)}${index + === stk.split(',').length - 1 ? '' : '&'}`; + }) + ens = encodeURIComponent( + [''.concat(ts), ''.concat(fp), + ''.concat(this.appId), ''.concat(tk), + ''.concat(CryptoJS.HmacSHA256(st, hash.toString()).toString( + CryptoJS.enc.Hex))].join(';')); + if (url.match(/[?|&]h5st=(.*?)&/)) { + url = url.replace(url.match(/[?|&]h5st=(.*?)&/)[1], 'H5ST') + .replace(/H5ST/, ens) + } + let matchArr = [/[?|&]_time=(\d+)/, /[?|&]__t=(\d+)/, + /[?|&]_ts=(\d+)/, + /[?|&]_=(\d+)/, /[?|&]t=(\d+)/, /[?|&]_cfd_t=(\d+)/] + for (let ms of matchArr) { + if (url.match(ms)) { + url = url.replace(url.match(ms)[1], Date.now()) + } + } + let t = this._tk(); + if (url.match(/strPgUUNum=(.*?)&/)) { + url = url.replace(url.match(/strPgUUNum=(.*?)&/)[1], t.tk) + if (url.match(/strPhoneID=(.*?)&/)) { + url = url.replace(url.match(/strPhoneID=(.*?)&/)[1], t.id) + } + if (url.match(/strPgtimestamp=(.*?)&/)) { + url = url.replace(url.match(/strPgtimestamp=(.*?)&/)[1], + t.ts) + } + } + if (url.match(/jxmc_jstoken=(.*?)&/)) { + url = url.replace(url.match(/jxmc_jstoken=(.*?)&/)[1], t.tk) + if (url.match(/phoneid=(.*?)&/)) { + url = url.replace(url.match(/phoneid=(.*?)&/)[1], t.id) + } + if (url.match(/timestamp=(.*?)&/)) { + url = url.replace(url.match(/timestamp=(.*?)&/)[1], t.ts) + } + } + } + return url; + } + + getQueryString(url, name) { + let reg = new RegExp("(^|[&?])" + name + "=([^&]*)(&|$)"); + let r = url.match(reg); + if (r != null) { + return unescape(r[2]); + } + return ''; + } + + unique(arr) { + return Array.from(new Set(arr)) + } + + async logic() { + console.log("default logic") + } + + async before() { + return -1; + } + + async after() { + return -1; + } + + tryLock(username, key) { + try { + fs.accessSync(`/jd/log/lock/${key}_${username}`); + return false; + } catch (e) { + return true; + } + } + + setLock(username, key) { + try { + try { + fs.accessSync(`/jd/log/lock`); + } catch (e) { + fs.mkdirSync(`/jd/log/lock`); + } + fs.mkdirSync(`/jd/log/lock/${key}_${username}`); + return false; + } catch (e) { + return true; + } + } + + match(pattern, string) { + pattern = (pattern instanceof Array) ? pattern : [pattern]; + for (let pat of pattern) { + const match = pat.exec(string); + if (match) { + const len = match.length; + if (len === 1) { + return match; + } else if (len === 2) { + return match[1]; + } else { + const r = []; + for (let i = 1; i < len; i++) { + r.push(match[i]) + } + return r; + } + } + } + return ''; + } + + matchAll(pattern, string) { + pattern = (pattern instanceof Array) ? pattern : [pattern]; + let match; + let result = []; + for (let p of pattern) { + while ((match = p.exec(string)) != null) { + let len = match.length; + if (len === 1) { + result.push(match); + } else if (len === 2) { + result.push(match[1]); + } else { + let r = []; + for (let i = 1; i < len; i++) { + r.push(match[i]) + } + result.push(r); + } + } + } + return result; + } + + async countdown(s) { + let date = new Date(); + if (date.getMinutes() === 59) { + let ms = this.now("s.SSS") + if (ms < 59) { + let st = (60 - ms) * 1000; + console.log(` 需要等待时间 ${st / 1000} 秒`); + await this.wait(st - (s || 20)) + } + } + } + + readFileSync(path) { + try { + return fs.readFileSync(path).toString(); + } catch (e) { + console.log(path, '文件不存在进行创建') + this.writeFileSync(path, ''); + return ''; + } + } + + writeFileSync(path, data) { + fs.writeFileSync(path, data) + } + + random(min, max) { + return Math.floor(Math.random() * (max - min + 1) + min); + } + + async notify(text, desc) { + return notify.sendNotify(text, desc); + } + + async get(url, headers) { + url = this.appId ? this.build(url) : url + return new Promise((resolve, reject) => { + $.get(url, {headers: headers}).then( + data => resolve(this.handler(data) || data)) + .catch(e => reject(e)) + }) + } + + async get2(url, headers) { + return new Promise((resolve, reject) => { + $.get(url, {headers: headers}).then( + data => resolve(data)) + .catch(e => reject(e)) + }) + } + + async post(url, body, headers) { + url = this.appId ? this.build(url) : url + return new Promise((resolve, reject) => { + $.post(url, body, {headers: headers}) + .then(data => resolve(this.handler(data) || data)) + .catch(e => reject(e)); + }) + } + + //└ + async request(url, headers, body) { + return new Promise((resolve, reject) => { + let __config = headers?.headers ? headers : {headers: headers}; + (body ? $.post(url, body, __config) : $.get(url, __config)) + .then(data => { + this.__lt(data); + resolve(data) + }) + .catch(e => reject(e)); + }) + } + + __lt(data) { + if (this.appId.length !== 2) { + return + } + let scs = data?.headers['set-cookie'] || data?.headers['Set-Cookie'] + || '' + if (!scs) { + if (data?.data?.LZ_TOKEN_KEY && data?.data?.LZ_TOKEN_VALUE) { + this.lz = `LZ_TOKEN_KEY=${data.data.LZ_TOKEN_KEY};LZ_TOKEN_VALUE=${data.data.LZ_TOKEN_VALUE};`; + } + return; + } + let LZ_TOKEN_KEY = '', LZ_TOKEN_VALUE = '' + let sc = typeof scs != 'object' ? scs.split(',') : scs + for (let ck of sc) { + let name = ck.split(";")[0].trim() + if (name.split("=")[1]) { + name.includes('LZ_TOKEN_KEY=') + ? LZ_TOKEN_KEY = name.replace(/ /g, '') + ';' : '' + name.includes('LZ_TOKEN_VALUE=') + ? LZ_TOKEN_VALUE = name.replace(/ /g, '') + ';' : '' + } + } + if (LZ_TOKEN_KEY && LZ_TOKEN_VALUE) { + this.lz = `${LZ_TOKEN_KEY}${LZ_TOKEN_VALUE}` + } + // testMode ? this.log('lz', this.lz) : '' + } + + handler(res) { + let data = res?.data || res?.body ||res; + if (!data) { + return; + } + if (typeof data === 'string') { + data = data.replace(/[\n\r| ]/g, ''); + if (data.includes("try{jsonpCB")) { + data = data.replace(/try{jsonpCB.*\({/, '{') + .replace(/}\)([;])?}catch\(e\){}/, '}') + } else if (data.includes('jsonpCB')) { + let st = data.replace(/[\n\r]/g, '').replace(/jsonpCB.*\({/, + '{'); + data = st.substring(0, st.length - 1) + } else if (data.match(/try{.*\({/)) { + data = data.replace(/try{.*\({/, '{') + .replace(/}\)([;])?}catch\(e\){}/, '}') + } else if (data.includes("jsonp")) { + data = /{(.*)}/g.exec(data)[0] + } else { + testMode ? console.log('例外', data) : '' + } + testMode ? console.log(data) : '' + testMode ? console.log('----------------分割线--------------------') + : '' + return JSON.parse(data) + } + testMode ? console.log(JSON.stringify(data)) : '' + testMode ? console.log('----------------分割线---------------------') : '' + return data; + } + + randomNum(length) { + length = length || 32; + let t = "0123456789", a = t.length, n = ''; + for (let i = 0; i < length; i++) { + n += t.charAt(Math.floor(Math.random() * a)); + } + return n + } + + randomString(e) { + return this.uuid() + } + + uuid(x = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") { + return x.replace(/[xy]/g, function (x) { + const r = 16 * Math.random() | 0, n = "x" === x ? r : 3 & r | 8; + return n.toString(36) + }) + } + + async unfollow(shopId) { + let url = 'https://api.m.jd.com/client.action?g_ty=ls&g_tk=518274330' + let body = `functionId=followShop&body={"follow":"false","shopId":"${shopId}","award":"true","sourceRpc":"shop_app_home_follow"}&osVersion=13.7&appid=wh5&clientVersion=9.2.0&loginType=2&loginWQBiz=interact` + let headers = { + 'Accept': 'application/json, text/plain, */*', + 'Accept-Encoding': 'gzip, deflate, br', + 'Content-Type': 'application/x-www-form-urlencoded', + 'Host': 'api.m.jd.com', + 'Connection': 'keep-alive', + 'Accept-Language': 'zh-cn', + 'Cookie': this.cookie + } + headers['User-Agent'] = `Mozilla/5.0 (iPhone; CPU iPhone OS 14_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/8.0.4(0x1800042c) NetType/4G Language/zh_CN miniProgram` + let {data} = await this.request(url, headers, body); + this.log(data.msg) + return data; + } + + randomCallback(e = 1) { + let t = "abcdefghigklmnopqrstuvwsyz", a = t.length, n = ''; + for (let i = 0; i < e; i++) { + n += t.charAt(Math.floor(Math.random() * a)); + } + return "jsonpCBK" + n.toUpperCase() + } + + randomArray(arr, count) { + count = count || arr.length + let shuffled = arr.slice(0), i = arr.length, min = i - count, temp, + index; + while (i-- > min) { + index = Math.floor((i + 1) * Math.random()); + temp = shuffled[index]; + shuffled[index] = shuffled[i]; + shuffled[i] = temp; + } + return shuffled.slice(min); + } + + now(fmt) { + return format(Date.now(), fmt || 'yyyy-MM-dd HH:mm:ss.SSS') + } + + formatDate(date, fmt) { + // noinspection JSCheckFunctionSignatures + return format(typeof date === 'object' ? date : new Date( + typeof date === 'string' ? date * 1 : date), + fmt || 'yyyy-MM-dd') + } + + timestamp() { + return new Date().getTime() + } + + _tk() { + let id = function (n) { + let src = 'abcdefghijklmnopqrstuvwxyz1234567890', res = ''; + for (let i = 0; i < n; i++) { + res += src[Math.floor(src.length * Math.random())]; + } + return res; + }(40), ts = Date.now().toString(), tk = this.md5( + '' + decodeURIComponent(this.username) + ts + id + + 'tPOamqCuk9NLgVPAljUyIHcPRmKlVxDy'); + return {ts: ts, id: id, tk: tk} + } + + async get_bean() { + let {data} = await $.post('https://api.m.jd.com/client.action', + `functionId=plantBeanIndex&body=${escape( + JSON.stringify({ + version: "9.0.0.1", + "monitor_source": "plant_app_plant_index", + "monitor_refer": "" + }) + )}&appid=ld&client=apple&area=5_274_49707_49973&build=167283&clientVersion=9.1.0`, + { + 'Host': "api.m.jd.com", + "Cookie": this.cookie + }); + debugger + return data.data.jwordShareInfo.shareUrl.split('Uuid=')[1] ?? '' + } + + async get_farm() { + let {data} = await $.post( + 'https://api.m.jd.com/client.action?functionId=initForFarm', + `body=${escape( + JSON.stringify({"version": 4}))}&appid=wh5&clientVersion=9.1.0`, + { + "origin": "https://home.m.jd.com", + "referer": "https://home.m.jd.com/myJd/newhome.action", + "Content-Type": "application/x-www-form-urlencoded", + "Cookie": this.cookie + }) + debugger + return data?.farmUserPro?.shareCode ?? '' + } + + async _algo() { + let fp = function () { + let e = "0123456789", a = 13, i = '' + for (; a--;) { + i += e[Math.random() * e.length | 0] + } + return (i + Date.now()).slice(0, 16) + }(); + let data = await this.post( + 'https://cactus.jd.com/request_algo?g_ty=ajax', JSON.stringify({ + "version": "1.0", + "fp": fp, + "appId": this.appId, + "timestamp": this.timestamp(), + "platform": "web", + "expandParams": '' + }), { + 'Authority': 'cactus.jd.com', + 'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1', + 'Content-Type': 'application/json', + 'Origin': 'https://st.jingxi.com', + 'Referer': 'https://st.jingxi.com/', + }); + return { + fp: fp.toString(), + tk: data?.data?.result?.tk || data?.result?.tk, + em: new Function( + `return ${data?.data?.result?.algo || data?.result?.algo}`)() + } + } +} + +module.exports = {Env, CryptoJS}; diff --git a/utils/share_code.js b/utils/share_code.js new file mode 100644 index 0000000..e9bab4a --- /dev/null +++ b/utils/share_code.js @@ -0,0 +1,99 @@ +var allShareCodes = []; +var removedShareCodes = []; +var chetou_number = process.env.CHETOU_NUMBER ? process.env.CHETOU_NUMBER : 0 +var fair_mode = process.env.FAIR_MODE ? true : false +var precode_mode = process.env.PRECODE_MODE ? false : true + +exports.ModCK = function(cks) { + console.log(`您${fair_mode ? "有" : "没有"}设置雨露均沾模式。`) + console.log(`您设置了${chetou_number}个车头。`) + if (cks.length <= chetou_number || !fair_mode) { + return cks + } + var sck = [] + var eck = [] + for (var i = 0; i < cks.length; i++) { + if (i <= chetou_number - 1) { + sck.push(cks[i]) + } else { + eck.push(cks[i]) + } + } + eck.sort(function() { + return Math.random() - 0.5; + }) + console.log(`已对${eck.length}个ck做了随机处理。`) + for (var i = 0; i < eck.length; i++) { + sck.push(eck[i]) + } + if (!precode_mode) { + if (sck.length >= 2) { + sck.push(sck[0]) + } + if (sck.length >= 3) { + sck.push(sck[1]) + } + if (sck.length >= 4) { + sck.push(sck[2]) + } + if (sck.length >= 5) { + sck.push(sck[3]) + } + if (sck.length >= 6) { + sck.push(sck[4]) + } + } + return sck +} + + + + +exports.setDefaultShareCodes = function(str) { + if (!str) { + return + } + var shareCodes = str.split("@") + console.log(`您提供了${shareCodes.length}个账号的助力码\n`); + if (shareCodes && shareCodes.length) { + for (var shareCode of shareCodes) { + if (shareCode && shareCode != "undefined" && allShareCodes.indexOf(shareCode) == -1) { + allShareCodes.push(shareCode) + } + } + } +} + +exports.addShareCode = function(shareCode) { + if (shareCode && allShareCodes.indexOf(shareCode) == -1) { + allShareCodes.push(shareCode) + } +} + +exports.removeShareCode = function(shareCode) { + removedShareCodes.push(shareCode) +} + +exports.forEachShareCode = function(func) { + for (var shareCode of allShareCodes) { + if (removedShareCodes.indexOf(shareCode) == -1) { + if (func(shareCode)) { + break + } + } + } +} + +exports.getShareCodes = function() { + var shareCodes = [] + for (var shareCode of allShareCodes) { + if (removedShareCodes.indexOf(shareCode) == -1) { + shareCodes.push(shareCode) + } + } + return shareCodes +} + +exports.getAllShareCodes = function() { + return allShareCodes +} \ No newline at end of file