jd_scripts/jd_firecrackers.js

322 lines
18 KiB
JavaScript
Raw Normal View History

2021-01-31 10:36:30 +08:00
/*
她的节享京豆
活动入口
活动地址https://linggame.jd.com/babelDiy/Zeus/3Y7JfoyA2Nwoa4FRqgDY4WpVjfgP/index.html
已支持IOS双京东账号,Node.js支持N个京东账号
脚本兼容: QuantumultX, Surge, Loon, JSBox, Node.js
2021-01-31 10:36:30 +08:00
============Quantumultx===============
[task_local]
#她的节享京豆
2021-03-07 07:49:03 +08:00
10 8,21 * * * https://gitee.com/lxk0301/jd_scripts/raw/master/jd_firecrackers.js, tag=她的节享京豆, img-url=https://raw.githubusercontent.com/Orz-3/mini/master/Color/jd.png, enabled=true
2021-01-31 10:36:30 +08:00
================Loon==============
[Script]
2021-03-07 07:49:03 +08:00
cron "10 8,21 * * *" script-path=https://gitee.com/lxk0301/jd_scripts/raw/master/jd_firecrackers.js,tag=她的节享京豆
2021-01-31 10:36:30 +08:00
===============Surge=================
2021-03-07 07:49:03 +08:00
她的节享京豆 = type=cron,cronexp="10 8,21 * * *",wake-system=1,timeout=3600,script-path=https://gitee.com/lxk0301/jd_scripts/raw/master/jd_firecrackers.js
2021-01-31 10:36:30 +08:00
============小火箭=========
2021-03-07 07:49:03 +08:00
她的节享京豆 = type=cron,script-path=https://gitee.com/lxk0301/jd_scripts/raw/master/jd_firecrackers.js, cronexpr="10 8,21 * * *", timeout=3600, enable=true
2021-01-31 10:36:30 +08:00
*/
const $ = new Env('她的节享京豆');
2021-01-31 10:36:30 +08:00
const notify = $.isNode() ? require('./sendNotify') : '';
2021-03-07 07:49:03 +08:00
let notifyBean = 35
2021-01-31 10:36:30 +08:00
const jdCookieNode = $.isNode() ? require('./jdCookie.js') : '';
//Node.js用户请在jdCookie.js处填写京东ck;
2021-01-31 10:36:30 +08:00
//IOS等用户直接用NobyDa的jd cookie
let cookiesArr = [], cookie = '', message;
2021-01-31 10:36:30 +08:00
if ($.isNode()) {
Object.keys(jdCookieNode).forEach((item) => {
cookiesArr.push(jdCookieNode[item])
})
if (process.env.JD_DEBUG && process.env.JD_DEBUG === 'false') console.log = () => {
};
} else {
2021-02-20 10:41:17 +08:00
cookiesArr = [$.getdata('CookieJD'), $.getdata('CookieJD2'), ...jsonParse($.getdata('CookiesJD') || "[]").map(item => item.cookie)].filter(item => !!item);
2021-01-31 10:36:30 +08:00
}
!(async () => {
if (!cookiesArr[0]) {
$.msg($.name, '【提示】请先获取京东账号一cookie\n直接使用NobyDa的京东签到获取', 'https://bean.m.jd.com/bean/signIndex.action', {"open-url": "https://bean.m.jd.com/bean/signIndex.action"});
return;
}
for (let i = 0; i < cookiesArr.length; i++) {
if (cookiesArr[i]) {
cookie = cookiesArr[i];
$.UserName = decodeURIComponent(cookie.match(/pt_pin=(.+?);/) && cookie.match(/pt_pin=(.+?);/)[1])
$.index = i + 1;
$.isLogin = true;
$.nickName = '';
$.beans = 0
2021-01-31 10:36:30 +08:00
message = '';
await TotalBean();
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 jdFamily()
2021-01-31 10:36:30 +08:00
}
}
})()
.catch((e) => {
$.log('', `${$.name}, 失败! 原因: ${e}!`, '')
})
.finally(() => {
$.done();
})
async function jdFamily() {
$.earn = 0
await getInfo()
await getUserInfo()
await getUserInfo(true)
await showMsg();
2021-01-31 10:36:30 +08:00
}
function showMsg() {
return new Promise(async resolve => {
subTitle = `【京东账号${$.index}${$.nickName}`;
message += `【鞭炮🧨】本次获得 ${$.earn},共计${$.total}\n`
if ($.total && notifyBean) {
for (let item of $.prize) {
if (notifyBean <= item.beansPerNum) { // 符合预定的京豆档位
if ($.total >= item.prizerank) { // 当前鞭炮满足兑换
2021-03-07 07:49:03 +08:00
await draw()
2021-01-31 10:36:30 +08:00
}
}
}
}
$.log(`${$.name}\n\n账号${$.index} - ${$.nickName}\n${subTitle}\n${message}`);
resolve()
2021-01-31 10:36:30 +08:00
})
}
function getInfo() {
2021-01-31 10:36:30 +08:00
return new Promise(resolve => {
$.get({
url: 'https://linggame.jd.com/babelDiy/Zeus/3Y7JfoyA2Nwoa4FRqgDY4WpVjfgP/index.html',
headers: {
Cookie: cookie
}
}, async (err, resp, data) => {
2021-01-31 10:36:30 +08:00
try {
$.info = JSON.parse(data.match(/var snsConfig = (.*)/)[1])
$.prize = JSON.parse($.info.prize)
2021-01-31 10:36:30 +08:00
} catch (e) {
console.log(e)
2021-01-31 10:36:30 +08:00
} finally {
resolve()
2021-01-31 10:36:30 +08:00
}
})
})
}
function getUserInfo(info = false) {
2021-01-31 10:36:30 +08:00
return new Promise(resolve => {
$.get(taskUrl('family_query'), async (err, resp, data) => {
2021-01-31 10:36:30 +08:00
try {
if (err) {
console.log(`${err},${jsonParse(resp.body)['message']}`)
2021-01-31 10:36:30 +08:00
console.log(`${$.name} API请求失败请检查网路重试`)
} else {
$.userInfo = JSON.parse(data.match(/query\((.*)\n/)[1])
if (info) {
$.earn = $.userInfo.tatalprofits - $.total
} else {
for (let task of $.info.config.tasks) {
let vo = $.userInfo.tasklist.filter(vo => vo.taskid === task['_id'])
if (vo.length > 0) {
vo = vo[0]
if (vo['isdo'] === 1) {
if (vo['times'] === 0) {
console.log(`去做任务${task['_id']}`)
let res = await doTask(task['_id'])
if (!res) { // 黑号,不再继续执行任务
break;
}
await $.wait(3000)
} else {
console.log(`${Math.trunc(vo['times'] / 60)}分钟可后做任务${task['_id']}`)
}
}
}
2021-01-31 10:36:30 +08:00
}
}
$.total = $.userInfo.tatalprofits
2021-01-31 10:36:30 +08:00
}
} catch (e) {
$.logErr(e, resp)
} finally {
resolve(data);
2021-01-31 10:36:30 +08:00
}
})
})
}
function doTask(taskId) {
let body = `taskid=${taskId}`
2021-01-31 10:36:30 +08:00
return new Promise(resolve => {
$.get(taskUrl('family_task', body), async (err, resp, data) => {
2021-01-31 10:36:30 +08:00
try {
if (err) {
console.log(`${err},${jsonParse(resp.body)['message']}`)
2021-01-31 10:36:30 +08:00
console.log(`${$.name} API请求失败请检查网路重试`)
} else {
let res = data.match(/query\((.*)\n/)[1];
data = JSON.parse(res);
if (data.ret === 0) {
console.log(`任务完成成功`)
} else if (data.ret === 1001) {
console.log(`任务完成失败,原因:这个账号黑号了!!!`)
resolve(false);
return;
} else {
console.log(`任务完成失败,原因未知`)
2021-01-31 10:36:30 +08:00
}
}
} catch (e) {
$.logErr(e, resp)
} finally {
resolve(data);
2021-01-31 10:36:30 +08:00
}
})
})
}
2021-03-07 07:49:03 +08:00
function draw() {
let body = `level=2&type=2`
return new Promise(resolve => {
$.get(taskUrl('family_draw', body), async (err, resp, data) => {
try {
if (err) {
console.log(`${err},${jsonParse(resp.body)['message']}`)
console.log(`${$.name} API请求失败请检查网路重试`)
} else {
data = JSON.parse(data.match(/query\((.*)\n/)[1])
if (data.ret === 0) {
message += '领奖成功\n'
console.log(`领奖成功`)
} else {
console.log(`领奖失败`)
}
}
} catch (e) {
$.logErr(e, resp)
} finally {
resolve(data);
}
})
})
}
function taskUrl(function_id, body = '') {
body = `activeid=${$.info.activeId}&token=${$.info.actToken}&sceneval=2&shareid=&_=${new Date().getTime()}&callback=query&${body}`
return {
url: `https://wq.jd.com/activep3/family/${function_id}?${body}`,
headers: {
'Host': 'wq.jd.com',
'Accept': 'application/json',
'Accept-Language': 'zh-cn',
'Content-Type': 'application/json;charset=utf-8',
'Origin': 'wq.jd.com',
'User-Agent': 'JD4iPhone/167490 (iPhone; iOS 14.2; Scale/3.00)',
'Referer': `https://anmp.jd.com/babelDiy/Zeus/xKACpgVjVJM7zPKbd5AGCij5yV9/index.html?wxAppName=jd`,
'Cookie': cookie
}
}
2021-01-31 10:36:30 +08:00
}
function taskPostUrl(function_id, body) {
2021-01-31 10:36:30 +08:00
return {
url: `https://lzdz-isv.isvjcloud.com/${function_id}`,
body: body,
2021-01-31 10:36:30 +08:00
headers: {
'Host': 'lzdz-isv.isvjcloud.com',
'Accept': 'application/json',
'Accept-Language': 'zh-cn',
'Content-Type': 'application/x-www-form-urlencoded',
'Origin': 'https://lzdz-isv.isvjcloud.com',
'User-Agent': 'JD4iPhone/167490 (iPhone; iOS 14.2; Scale/3.00)',
'Referer': `https://lzdz-isv.isvjcloud.com/dingzhi/book/develop/activity?activityId=${ACT_ID}`,
'Cookie': `${cookie} isvToken=${$.isvToken};`
2021-01-31 10:36:30 +08:00
}
}
}
function TotalBean() {
return new Promise(async resolve => {
const options = {
"url": `https://wq.jd.com/user/info/QueryJDUserInfo?sceneval=2`,
"headers": {
"Accept": "application/json,text/plain, */*",
"Content-Type": "application/x-www-form-urlencoded",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "zh-cn",
"Connection": "keep-alive",
"Cookie": cookie,
"Referer": "https://wqs.jd.com/my/jingdou/my.shtml?sceneval=2",
"User-Agent": $.isNode() ? (process.env.JD_USER_AGENT ? process.env.JD_USER_AGENT : "jdapp;iPhone;9.2.2;14.2;%E4%BA%AC%E4%B8%9C/9.2.2 CFNetwork/1206 Darwin/20.1.0") : ($.getdata('JDUA') ? $.getdata('JDUA') : "jdapp;iPhone;9.2.2;14.2;%E4%BA%AC%E4%B8%9C/9.2.2 CFNetwork/1206 Darwin/20.1.0")
2021-01-31 10:36:30 +08:00
}
}
$.post(options, (err, resp, data) => {
try {
if (err) {
console.log(`${JSON.stringify(err)}`)
console.log(`${$.name} API请求失败请检查网路重试`)
} else {
if (data) {
data = JSON.parse(data);
if (data['retcode'] === 13) {
$.isLogin = false; //cookie过期
return
}
if (data['retcode'] === 0) {
$.nickName = data['base'].nickname;
} else {
$.nickName = $.UserName
}
2021-01-31 10:36:30 +08:00
} else {
console.log(`京东服务器返回空数据`)
}
}
} catch (e) {
$.logErr(e, resp)
} finally {
resolve();
}
})
})
}
function safeGet(data) {
try {
if (typeof JSON.parse(data) == "object") {
return true;
}
} catch (e) {
console.log(e);
console.log(`京东服务器访问数据为空,请检查自身设备网络情况`);
return false;
}
}
function jsonParse(str) {
if (typeof str == "string") {
try {
return JSON.parse(str);
} catch (e) {
console.log(e);
$.msg($.name, '', '不要在BoxJS手动复制粘贴修改cookie')
2021-01-31 10:36:30 +08:00
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"])