diff --git a/src/main/resources/test_MoreBean.js b/src/main/resources/test_MoreBean.js new file mode 100644 index 0000000..9320ee5 --- /dev/null +++ b/src/main/resources/test_MoreBean.js @@ -0,0 +1,574 @@ +/* +领京豆额外奖励&抢京豆 +脚本自带助力码,介意者可将 29行 helpAuthor 变量设置为 false +活动入口:京东APP首页-领京豆 +更新地址:https://gitee.com/lxk0301/jd_scripts/raw/master/jd_bean_home.js +已支持IOS双京东账号, Node.js支持N个京东账号 +脚本兼容: QuantumultX, Surge, Loon, 小火箭,JSBox, Node.js +============Quantumultx=============== +[task_local] +#领京豆额外奖励 +10 7 * * * https://gitee.com/lxk0301/jd_scripts/raw/master/jd_bean_home.js, tag=领京豆额外奖励, img-url=https://raw.githubusercontent.com/58xinian/icon/master/jd_bean_home.png, enabled=true + +================Loon============== +[Script] +cron "10 7 * * *" script-path=https://gitee.com/lxk0301/jd_scripts/raw/master/jd_bean_home.js, tag=领京豆额外奖励 + +===============Surge================= +领京豆额外奖励 = type=cron,cronexp="10 7 * * *",wake-system=1,timeout=3600,script-path=https://gitee.com/lxk0301/jd_scripts/raw/master/jd_bean_home.js + +============小火箭========= +领京豆额外奖励 = type=cron,script-path=https://gitee.com/lxk0301/jd_scripts/raw/master/jd_bean_home.js, cronexpr="10 7 * * *", timeout=3600, enable=true + */ +const notify = $.isNode() ? require('./sendNotify') : ''; +//Node.js用户请在jdCookie.js处填写京东ck; +const jdCookieNode = $.isNode() ? require('./jdCookie.js') : ''; +let jdNotify = true;//是否关闭通知,false打开通知推送,true关闭通知推送 +const helpAuthor = false; // 是否帮助作者助力,false打开通知推送,true关闭通知推送 +//IOS等用户直接用NobyDa的jd cookie +let cookiesArr = [], cookie = '', message; +let newShareCodes = [] +let roleMap = { + "jd_4521b375ebb5d": "锟子怪", + "jd_542c10c0222bc": "康子怪", + "jd_66dcb31363ef6": "涛子怪", + "jd_45d917547c763": "跑腿小怪", + "417040678_m": "斌子怪", + "jd_73d88459d908e": "杰杰子", + "381550701lol": "漪漪子", + "jd_4333d5dc1ac5f": "舒楠子", + "jd_66ea783827d30": "军子", + "jd_4311ac0ff4456": "居子" +} +let dingtalk = "https://oapi.dingtalk.com/robot/send?access_token=d2b6042cb38f0df63e20797c002208d2710104750c18a1dc84d54106a859a3f0" + + + +if ($.isNode()) { + Object.keys(jdCookieNode).forEach((item) => { + cookiesArr.push(jdCookieNode[item]) + }) + if (process.env.JD_DEBUG && process.env.JD_DEBUG === 'false') that.log = () => { + }; +} else { + cookiesArr = [$.getdata('CookieJD'), $.getdata('CookieJD2'), ...jsonParse($.getdata('CookiesJD') || "[]").map(item => item.cookie)].filter(item => !!item); +} +const JD_API_HOST = 'https://api.m.jd.com/'; +!(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; + } + message += "[通知] 额外领京豆 \n\n" + + 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 = ''; + await TotalBean(); + + if (roleMap[username] != undefined) { + username = roleMap[username] + } + //加上名称 + message = message + "【羊毛姐妹】" + username + " \n\n " + + that.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 jdBeanHome(); + } + + message += "----\n\n" + } + postToDingTalk(message) + message += "[通知] 额外领京豆 \n\n" + + 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]) + that.log(`${$.UserName}去帮助下一个人`) + cookie = cookiesArr[i]; + for (let j = 0; i < newShareCodes.length; j++) { + let code = newShareCodes[j] + await help(code[0], code[1]) + } + } + } +})() + .catch((e) => { + $.log('', `❌ ${$.name}, 失败! 原因: ${e}!`, '') + }) + .finally(() => { + postToDingTalk(message) + $.done(); + }) + +async function jdBeanHome() { + $.doneState = false + do { + await doTask2() + await $.wait(3000) + } while (!$.doneState) + await $.wait(1000) + await award("feeds") + await $.wait(1000) + await getUserInfo() + await $.wait(1000) + await getTaskList(); + await receiveJd2(); + await showMsg(); +} + +function getRandomInt(min, max) { + min = Math.ceil(min); + max = Math.floor(max); + return Math.floor(Math.random() * (max - min)) + min; +} +function doTask2() { + return new Promise(resolve => { + const body = { "awardFlag": false, "skuId": `${getRandomInt(10000000, 20000000)}`, "source": "feeds", "type": '1' }; + $.post(taskUrl('beanHomeTask', body), (err, resp, data) => { + try { + if (err) { + that.log(`${JSON.stringify(err)}`) + that.log(`${$.name} API请求失败,请检查网路重试`) + } else { + if (safeGet(data)) { + data = JSON.parse(data); + if (data.code === '0' && data.data) { + that.log(`任务完成进度:${data.data.taskProgress} / ${data.data.taskThreshold}`) + if (data.data.taskProgress === data.data.taskThreshold) + $.doneState = true + } else if (data.code === '0' && data.errorCode === 'HT201') { + $.doneState = true + } else { + //HT304风控用户 + $.doneState = true + that.log(`做任务异常:${JSON.stringify(data)}`) + } + } + } + } catch (e) { + $.logErr(e, resp) + } finally { + resolve(); + } + }) + }) +} + + +function getUserInfo() { + return new Promise(resolve => { + let body = {} + $.post(taskUrl('signBeanGroupStageIndex', body), async (err, resp, data) => { + try { + if (err) { + that.log(`${JSON.stringify(err)}`) + that.log(`${$.name} API请求失败,请检查网路重试`) + } else { + if (safeGet(data)) { + data = JSON.parse(data); + if (data.data.jklInfo) { + $.actId = data.data.jklInfo.keyId + let { shareCode, groupCode } = data.data + if (!shareCode) { + that.log(`未获取到助力码,去开团`) + await hitGroup() + } else { + that.log(shareCode, groupCode) + // 去做逛会场任务 + if (data.data.beanActivityVisitVenue && data.data.beanActivityVisitVenue.taskStatus === '0') { + await help(shareCode, groupCode, 1) + } + newShareCodes.push([shareCode, groupCode]) + } + } + } + } + } catch (e) { + $.logErr(e, resp) + } finally { + resolve(); + } + }) + }) +} + +function hitGroup() { + return new Promise(resolve => { + const body = { "activeType": 2, }; + $.get(taskGetUrl('signGroupHit', body), async (err, resp, data) => { + try { + if (err) { + that.log(`${JSON.stringify(err)}`) + that.log(`${$.name} API请求失败,请检查网路重试`) + } else { + if (safeGet(data)) { + data = JSON.parse(data); + if (data.data.respCode === "SG150") { + let { shareCode, groupCode } = data.data.signGroupMain + if (shareCode) { + newShareCodes.push([shareCode, groupCode]) + that.log('开团成功') + await help(shareCode, groupCode, 1) + } else { + that.log(`为获取到助力码,错误信息${JSON.stringify(data.data)}`) + } + } else { + that.log(`开团失败,错误信息${JSON.stringify(data.data)}`) + } + } + } + } catch (e) { + $.logErr(e, resp) + } finally { + resolve(); + } + }) + }) +} + +function help(shareCode, groupCode, isTask = 0) { + return new Promise(resolve => { + const body = { + "activeType": 2, + "groupCode": groupCode, + "shareCode": shareCode, + "activeId": $.actId, + }; + if (isTask) { + that.log(`【抢京豆】做任务获取助力`) + body['isTask'] = "1" + } else { + that.log(`【抢京豆】去助力好友${shareCode}`) + + body['source'] = "guest" + } + $.get(taskGetUrl('signGroupHelp', body), async (err, resp, data) => { + try { + if (err) { + that.log(`${JSON.stringify(err)}`) + that.log(`【抢京豆】${$.name} API请求失败,请检查网路重试`) + } else { + if (safeGet(data)) { + data = JSON.parse(data); + that.log(`【抢京豆】${data.data.helpToast}`) + message = message + "【羊毛姐妹】" + `【抢京豆】去助力好友${shareCode}` + " \n\n " + } + } + } catch (e) { + $.logErr(e, resp) + } finally { + resolve(data); + } + }) + }) +} + +function showMsg() { + return new Promise(resolve => { + if (message) $.msg($.name, '', `【京东账号${$.index}】${$.nickName}\n${message}`); + resolve() + }) +} + +function getTaskList() { + return new Promise(resolve => { + const body = { "rnVersion": "4.7", "rnClient": "2", "source": "AppHome" }; + $.post(taskUrl('findBeanHome', body), async (err, resp, data) => { + try { + if (err) { + that.log(`${JSON.stringify(err)}`) + that.log(`${$.name} API请求失败,请检查网路重试`) + } else { + if (safeGet(data)) { + data = JSON.parse(data); + let beanTask = data.data.floorList.filter(vo => vo.floorName === "种豆得豆定制化场景")[0] + if (!beanTask.viewed) { + await receiveTask() + await $.wait(3000) + } + + let tasks = data.data.floorList.filter(vo => vo.floorName === "赚京豆")[0]['stageList'] + for (let i = 0; i < tasks.length; ++i) { + const vo = tasks[i] + if (vo.viewed) continue + await receiveTask(vo.stageId, `4_${vo.stageId}`) + await $.wait(3000) + } + await award() + } + } + } catch (e) { + $.logErr(e, resp) + } finally { + resolve(); + } + }) + }) +} + +function receiveTask(itemId = "zddd", type = "3") { + return new Promise(resolve => { + const body = { "awardFlag": false, "itemId": itemId, "source": "home", "type": type }; + $.post(taskUrl('beanHomeTask', body), (err, resp, data) => { + try { + if (err) { + that.log(`${JSON.stringify(err)}`) + that.log(`${$.name} API请求失败,请检查网路重试`) + } else { + if (safeGet(data)) { + data = JSON.parse(data); + if (data.data) { + that.log(`完成任务成功,进度${data.data.taskProgress}/${data.data.taskThreshold}`) + } else { + that.log(`完成任务失败,${data.errorMessage}`) + } + } + } + } catch (e) { + $.logErr(e, resp) + } finally { + resolve(); + } + }) + }) +} + + +function award(source = "home") { + return new Promise(resolve => { + const body = { "awardFlag": true, "source": source }; + $.post(taskUrl('beanHomeTask', body), (err, resp, data) => { + try { + if (err) { + that.log(`${JSON.stringify(err)}`) + that.log(`${$.name} API请求失败,请检查网路重试`) + } else { + if (safeGet(data)) { + data = JSON.parse(data); + if (data.data) { + that.log(`领奖成功,获得 ${data.data.beanNum} 个京豆`) + message += "" +`领奖成功,获得 ${data.data.beanNum} 个京豆\n` + " \n\n" + + } else { + that.log(`领奖失败,${data.errorMessage}`) + // message += `领奖失败,${data.errorMessage}\n` + } + } + } + } catch (e) { + $.logErr(e, resp) + } finally { + resolve(); + } + }) + }) +} +function receiveJd2() { + var headers = { + 'Host': 'api.m.jd.com', + 'content-type': 'application/x-www-form-urlencoded', + 'accept': '*/*', + 'user-agent': 'JD4iPhone/167515 (iPhone; iOS 14.2; Scale/3.00)', + 'accept-language': 'zh-Hans-JP;q=1, en-JP;q=0.9, zh-Hant-TW;q=0.8, ja-JP;q=0.7, en-US;q=0.6', + 'Cookie': cookie + }; + var dataString = 'body=%7B%7D&build=167576&client=apple&clientVersion=9.4.3&openudid=53f4d9c70c1c81f1c8769d2fe2fef0190a3f60d2&osVersion=14.2&partner=TF&rfs=0000&scope=10&screen=1242%2A2208&sign=19c33b5b9ad4f02c53b6040fc8527119&st=1614701322170&sv=122' + var options = { + url: 'https://api.m.jd.com/client.action?functionId=sceneInitialize', + headers: headers, + body: dataString + }; + return new Promise(resolve => { + $.post(options, (err, resp, data) => { + try { + if (err) { + that.log(`${JSON.stringify(err)}`) + that.log(`${$.name} API请求失败,请检查网路重试`) + } else { + if (safeGet(data)) { + data = JSON.parse(data); + if (data['code'] === '0' && data['data']) { + that.log(`强制开启新版领京豆成功,获得${data['data']['sceneLevelConfig']['beanNum']}京豆\n`); + $.msg($.name, '', `强制开启新版领京豆成功\n获得${data['data']['sceneLevelConfig']['beanNum']}京豆`); + } else { + that.log(`强制开启新版领京豆结果:${JSON.stringify(data)}\n`) + } + } + } + } catch (e) { + $.logErr(e, resp) + } finally { + resolve(); + } + }) + }) +} +function taskGetUrl(function_id, body) { + return { + url: `${JD_API_HOST}client.action?functionId=${function_id}&body=${escape(JSON.stringify(body))}&appid=ld&clientVersion=9.2.0`, + headers: { + 'Cookie': cookie, + 'Host': 'api.m.jd.com', + 'Accept': '*/*', + 'Connection': 'keep-alive', + 'User-Agent': $.isNode() ? (process.env.JD_USER_AGENT ? process.env.JD_USER_AGENT : (require('./USER_AGENTS').USER_AGENT)) : ($.getdata('JDUA') ? $.getdata('JDUA') : "jdapp;iPhone;9.4.4;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"), + 'Accept-Language': 'zh-Hans-CN;q=1,en-CN;q=0.9', + 'Accept-Encoding': 'gzip, deflate, br', + 'Content-Type': "application/x-www-form-urlencoded" + } + } +} + + +function taskUrl(function_id, body) { + body["version"] = "9.0.0.1"; + body["monitor_source"] = "plant_app_plant_index"; + body["monitor_refer"] = ""; + return { + url: JD_API_HOST, + body: `functionId=${function_id}&body=${escape(JSON.stringify(body))}&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': $.isNode() ? (process.env.JD_USER_AGENT ? process.env.JD_USER_AGENT : (require('./USER_AGENTS').USER_AGENT)) : ($.getdata('JDUA') ? $.getdata('JDUA') : "jdapp;iPhone;9.4.4;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"), + 'Accept-Language': 'zh-Hans-CN;q=1,en-CN;q=0.9', + 'Accept-Encoding': 'gzip, deflate, br', + 'Content-Type': "application/x-www-form-urlencoded" + } + } +} + +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 : (require('./USER_AGENTS').USER_AGENT)) : ($.getdata('JDUA') ? $.getdata('JDUA') : "jdapp;iPhone;9.4.4;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") + } + } + $.post(options, (err, resp, data) => { + try { + if (err) { + that.log(`${JSON.stringify(err)}`) + that.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'] && data['base'].nickname) || $.UserName; + } else { + $.nickName = $.UserName + } + } else { + that.log(`京东服务器返回空数据`) + } + } + } catch (e) { + $.logErr(e, resp) + } finally { + resolve(); + } + }) + }) +} + +function safeGet(data) { + try { + if (typeof JSON.parse(data) == "object") { + return true; + } + } catch (e) { + that.log(e); + that.log(`京东服务器访问数据为空,请检查自身设备网络情况`); + return false; + } +} +function jsonParse(str) { + if (typeof str == "string") { + try { + return JSON.parse(str); + } catch (e) { + that.log(e); + $.msg($.name, '', '请勿随意在BoxJs输入框修改内容\n建议通过脚本去获取cookie') + return []; + } + } +} + + + +//我加的函数 +function postToDingTalk(messgae) { + const message1 = "" + messgae + // that.log(messgae) + + const body = { + "msgtype": "markdown", + "markdown": { + "title": "签到领现金", + "text": message1 + }, + "at": { + "atMobiles": [], + "isAtAll": false + } + } + + + $.post(toDingtalk(dingtalk, JSON.stringify(body)), (data, status, xhr) => { + try { + that.log(resp) + that.log(data) + if (err) { + that.log(JSON.stringify(err)); + $.logErr(err); + } else { + if (safeGet(data)) { + $.duckRes = JSON.parse(data); + } + } + } catch (e) { + $.logErr(e, resp) + } finally { + resolve(); + } + }, "json") +} + + +function toDingtalk(urlmain, bodyMain) { + return { + url: urlmain, + body: bodyMain, + headers: { 'Content-Type': 'application/json;charset=utf-8' }, + timeout: 10000, + } +} \ No newline at end of file diff --git a/src/main/resources/test_egg.js b/src/main/resources/test_egg.js deleted file mode 100644 index c842428..0000000 --- a/src/main/resources/test_egg.js +++ /dev/null @@ -1,303 +0,0 @@ -let cookiesArr = [], cookie = ''; -const JD_API_HOST = 'https://ms.jr.jd.com/gw/generic/uc/h5/m'; -const notify = $.isNode() ? require('./sendNotify') : ''; -let message = "" -//Node.js用户请在jdCookie.js处填写动动ck; -const jdCookieNode = $.isNode() ? require('./jdCookie.js') : ''; -if ($.isNode()) { - Object.keys(jdCookieNode).forEach((item) => { - cookiesArr.push(jdCookieNode[item]) - }) - if (process.env.JD_DEBUG && process.env.JD_DEBUG === 'false') that.log = () => {}; -} else { - cookiesArr = [$.getdata('CookieJD'), $.getdata('CookieJD2'), ...jsonParse($.getdata('CookiesJD') || "[]").map(item => item.cookie)].filter(item => !!item); -} -!(async () => { - - message += "[通知] 天天提鹅 \n\n --- \n\n" - 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 = ''; - await TotalBean(); - username = $.UserName - if ($.UserName == "jd_66ea783827d30"){ - username = "跑腿小弟" - } - if ($.UserName == "jd_4521b375ebb5d"){ - username = "锟锟" - } - if ($.UserName == "jd_542c10c0222bc"){ - username = "康康" - } - //加上名称 - message = message + "【羊毛姐妹】" + username + " \n\n " - that.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 jdDailyEgg(); - } - message = message +"----\n\n" - } -})() - .catch((e) => { - $.log('', `❌ ${$.name}, 失败! 原因: ${e}!`, '') - }) - .finally(() => { - that.log(message) - postToDingTalk(message) - $.done(); - }) -async function jdDailyEgg() { - await toDailyHome() - await toWithdraw() - await toGoldExchange(); -} -function toGoldExchange() { - return new Promise(async resolve => { - const body = { - "timeSign": 0, - "environment": "jrApp", - "riskDeviceInfo": "{}" - } - $.post(taskUrl('toGoldExchange', body), (err, resp, data) => { - try { - if (err) { - that.log(`${JSON.stringify(err)}`) - that.log(`${$.name} API请求失败,请检查网路重试`) - } else { - if (data) { - // that.log(data) - data = JSON.parse(data); - if (data.resultCode === 0) { - if (data.resultData.code === '0000') { - that.log(`兑换金币:${data.resultData.data.cnumber}`); - message += "" + `兑换金币:${data.resultData.data.cnumber}` + "\n\n" - that.log(`当前总金币:${data.resultData.data.goldTotal}`); - message += "" + `当前总金币:${data.resultData.data.goldTotal}` +"\n\n" - } else if (data.resultData.code !== '0000') { - that.log(`兑换金币失败:${data.resultData.msg}`) - } - } - } else { - that.log(`动动服务器返回空数据`) - } - } - } catch (e) { - $.logErr(e, resp) - } finally { - resolve(); - } - }) - }) -} -function toWithdraw() { - return new Promise(async resolve => { - const body = { - "timeSign": 0, - "environment": "jrApp", - "riskDeviceInfo": "{}" - } - $.post(taskUrl('toWithdraw', body), (err, resp, data) => { - try { - if (err) { - that.log(`${JSON.stringify(err)}`) - that.log(`${$.name} API请求失败,请检查网路重试`) - } else { - if (data) { - // that.log(data) - data = JSON.parse(data); - if (data.resultCode === 0) { - if (data.resultData.code === '0000') { - message += "" +`收取鹅蛋:${data.resultData.data.eggTotal}个成功` + "\n\n" - message += "" + `当前总鹅蛋数量:${data.resultData.data.userLevelDto.userHaveEggNum}` + "\n\n" - that.log(`收取鹅蛋:${data.resultData.data.eggTotal}个成功`); - that.log(`当前总鹅蛋数量:${data.resultData.data.userLevelDto.userHaveEggNum}`); - } else if (data.resultData.code !== '0000') { - that.log(`收取鹅蛋失败:${data.resultData.msg}`) - message += "" + `收取鹅蛋失败:${data.resultData.msg}` + "\n\n" - } - } - } else { - that.log(`动动服务器返回空数据`) - } - } - } catch (e) { - $.logErr(e, resp) - } finally { - resolve(); - } - }) - }) -} -function toDailyHome() { - return new Promise(async resolve => { - const body = { - "timeSign": 0, - "environment": "jrApp", - "riskDeviceInfo": "{}" - } - $.post(taskUrl('toDailyHome', body), (err, resp, data) => { - try { - if (err) { - that.log(`${JSON.stringify(err)}`) - that.log(`${$.name} API请求失败,请检查网路重试`) - } else { - if (data) { - // that.log(data) - data = JSON.parse(data); - } else { - that.log(`动动服务器返回空数据`) - } - } - } catch (e) { - $.logErr(e, resp) - } finally { - resolve(); - } - }) - }) -} -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-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 : (require('./USER_AGENTS').USER_AGENT)) : ($.getdata('JDUA') ? $.getdata('JDUA') : "jdapp;iPhone;9.4.4;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") - } - } - $.post(options, (err, resp, data) => { - try { - if (err) { - that.log(`${JSON.stringify(err)}`) - that.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'] && data['base'].nickname) || $.UserName; - } else { - $.nickName = $.UserName - } - } else { - that.log(`动动服务器返回空数据`) - } - } - } catch (e) { - $.logErr(e, resp) - } finally { - resolve(); - } - }) - }) -} -function taskUrl(function_id, body) { - return { - url: `${JD_API_HOST}/${function_id}`, - body: `reqData=${encodeURIComponent(JSON.stringify(body))}`, - headers: { - 'Accept' : `application/json`, - 'Origin' : `https://uua.jr.jd.com`, - 'Cookie' : cookie, - 'Content-Type' : `application/x-www-form-urlencoded;charset=UTF-8`, - 'Host' : `ms.jr.jd.com`, - 'Connection' : `keep-alive`, - 'User-Agent' : $.isNode() ? (process.env.JD_USER_AGENT ? process.env.JD_USER_AGENT : (require('./USER_AGENTS').USER_AGENT)) : ($.getdata('JDUA') ? $.getdata('JDUA') : "jdapp;iPhone;9.4.4;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"), - 'Referer' : `https://uua.jr.jd.com/uc-fe-wxgrowing/moneytree/index`, - 'Accept-Language' : `zh-cn` - } - } -} -function jsonParse(str) { - if (typeof str == "string") { - try { - return JSON.parse(str); - } catch (e) { - that.log(e); - $.msg($.name, '', '请勿随意在BoxJs输入框修改内容\n建议通过脚本去获取cookie') - return []; - } - } -} - -//我加的函数 -function postToDingTalk(messgae) { - const dingtalk = "https://oapi.dingtalk.com/robot/send?access_token=18444b555747aad3381bc1d1e3dea72b03158e152a846f818d82a1ca946bd430" - - const message1 = "" + messgae - that.log(messgae) - - const body = { - "msgtype": "markdown", - "markdown": { - "title":"天天提鹅", - "text": message1 - }, - "at": { - "atMobiles": [], - "isAtAll": false - } - } - - - $.post(toDingtalk(dingtalk,JSON.stringify(body)), (data,status,xhr)=>{ - try { - that.log(resp) - that.log(data) - if (err) { - that.log(JSON.stringify(err)); - $.logErr(err); - } else { - if (safeGet(data)) { - $.duckRes = JSON.parse(data); - } - } - } catch (e) { - $.logErr(e, resp) - } finally { - resolve(); - } - },"json") -} - - -function toDingtalk(urlmain, bodyMain) { - return { - url: urlmain, - body:bodyMain, - headers: { 'Content-Type': 'application/json;charset=utf-8' }, - timeout: 10000, - } -} - -function getPic(){ - let code = ["1.gif","2.png","3.png","4.png","5.gif","6.gif","7.gif","8.gif","9.gif","10.png","11.png"] - let address = "\n\n ![screenshot](https://cdn.jsdelivr.net/gh/selfImprHuang/Go-Tool@v1.2/test/emptyDirTest/3/" - - pos = parseInt(11*Math.random()) - address = address + code[pos] + ")" - return address -} \ No newline at end of file diff --git a/src/main/resources/test_getTuanBean.js b/src/main/resources/test_getTuanBean.js new file mode 100644 index 0000000..995b80c --- /dev/null +++ b/src/main/resources/test_getTuanBean.js @@ -0,0 +1,827 @@ +//开团赚京豆 - 赚京豆 +const notify = $.isNode() ? require('./sendNotify') : ''; +//Node.js用户请在jdCookie.js处填写京东ck; +const jdCookieNode = $.isNode() ? require('./jdCookie.js') : ''; +let jdNotify = true;//是否关闭通知,false打开通知推送,true关闭通知推送 +const randomCount = $.isNode() ? 0 : 5; +//IOS等用户直接用NobyDa的jd cookie +let cookiesArr = [], cookie = '', message; +$.tuanList = []; +let roleMap = { + "jd_4521b375ebb5d": "锟子怪", + "jd_542c10c0222bc": "康子怪", + "jd_66dcb31363ef6": "涛子怪", + "jd_45d917547c763": "跑腿小怪", + "417040678_m": "斌子怪", + "jd_73d88459d908e": "杰杰子", + "381550701lol": "漪漪子", + "jd_4333d5dc1ac5f": "舒楠子", + "jd_66ea783827d30": "军子", + "jd_4311ac0ff4456": "居子" +} +let dingtalk = "https://oapi.dingtalk.com/robot/send?access_token=d2b6042cb38f0df63e20797c002208d2710104750c18a1dc84d54106a859a3f0" + +if ($.isNode()) { + Object.keys(jdCookieNode).forEach((item) => { + cookiesArr.push(jdCookieNode[item]) + }) + if (process.env.JD_DEBUG && process.env.JD_DEBUG === 'false') that.log = () => { }; + if (JSON.stringify(process.env).indexOf('GITHUB') > -1) process.exit(0); +} else { + cookiesArr = [$.getdata('CookieJD'), $.getdata('CookieJD2'), ...jsonParse($.getdata('CookiesJD') || "[]").map(item => item.cookie)].filter(item => !!item); +} +const JD_API_HOST = 'https://api.m.jd.com/api'; +!(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; + } + + + message += "[通知] 赚京豆 \n\n" + 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 = ''; + await TotalBean(); + + if (roleMap[username] != undefined) { + username = roleMap[username] + } + //加上名称 + message = message + "【羊毛姐妹】" + username + " \n\n " + + + that.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 main(); + } + message += "----\n\n" + + } + postToDingTalk(message) + message += "[通知] 赚京豆 \n\n" + + that.log(`\n\n内部互助 【赚京豆(微信小程序)-瓜分京豆】活动(优先内部账号互助(需内部cookie数量大于${$.assistNum || 4}个)\n`) + for (let i = 0; i < cookiesArr.length; i++) { + $.canHelp = true + if (cookiesArr[i]) { + cookie = cookiesArr[i]; + $.UserName = decodeURIComponent(cookie.match(/pt_pin=([^; ]+)(?=;?)/) && cookie.match(/pt_pin=([^; ]+)(?=;?)/)[1]) + if ($.canHelp && (cookiesArr.length > $.assistNum)) { + if ($.tuanList.length) that.log(`开始账号内部互助 赚京豆-瓜分京豆 活动,优先内部账号互助`) + for (let j = 0; j < $.tuanList.length; ++j) { + that.log(`账号 ${$.UserName} 开始给 【${$.tuanList[j]['assistedPinEncrypted']}】助力`) + message += "" + `账号 ${$.UserName} 开始给 【${$.tuanList[j]['assistedPinEncrypted']}】助力` + " \n\n" + await helpFriendTuan($.tuanList[j]) + if (!$.canHelp) break + await $.wait(200) + } + } + } + } +})() + .catch((e) => { + $.log('', `❌ ${$.name}, 失败! 原因: ${e}!`, '') + }) + .finally(() => { + postToDingTalk(message) + $.done(); + }) + +function showMsg() { + return new Promise(resolve => { + if (message) $.msg($.name, '', `【京东账号${$.index}】${$.nickName}\n${message}`); + resolve() + }) +} +async function main() { + try { + // await userSignIn();//赚京豆-签到领京豆 + await vvipTask();//赚京豆-加速领京豆 + await distributeBeanActivity();//赚京豆-瓜分京豆 + await showMsg(); + } catch (e) { + $.logErr(e) + } +} +//================赚京豆-签到领京豆=================== +let signFlag = 0; +function userSignIn() { + return new Promise(resolve => { + const body = { "activityId": "ccd8067defcd4787871b7f0c96fcbf5c", "inviterId": "", "channel": "MiniProgram" }; + $.get(taskUrl('userSignIn', body), async (err, resp, data) => { + try { + if (err) { + that.log(`${JSON.stringify(err)}`) + that.log(`${$.name} API请求失败,请检查网路重试`) + } else { + if (safeGet(data)) { + data = JSON.parse(data); + if (data.code === 0) { + signFlag = 0; + that.log(`${$.name}今日签到成功`); + if (data.data) { + let { alreadySignDays, beanTotalNum, todayPrize, eachDayPrize } = data.data; + + message += "" + `【第${alreadySignDays}日签到】成功,获得${todayPrize.beanAmount}京豆 🐶\n` + " \n\n" + if (alreadySignDays === 7) alreadySignDays = 0; + message += "" + `【明日签到】可获得${eachDayPrize[alreadySignDays].beanAmount}京豆 🐶\n` + " \n\n" + message += "" + `【累计获得】${beanTotalNum}京豆 🐶` + " \n\n" + } + } else if (data.code === 81) { + that.log(`【签到】失败,今日已签到`) + // message += `【签到】失败,今日已签到`; + } else if (data.code === 6) { + //此处有时会遇到 服务器繁忙 导致签到失败,故重复三次签到 + $.log(`${$.name}签到失败${signFlag}:${data.msg}`); + if (signFlag < 3) { + signFlag++; + await userSignIn(); + } + } else if (data.code === 66) { + //此处有时会遇到 服务器繁忙 导致签到失败,故重复三次签到 + $.log(`${$.name}签到失败:${data.msg}`); + message += `【签到】失败,${data.msg}`; + } else { + that.log(`异常:${JSON.stringify(data)}`) + } + } + } + } catch (e) { + $.logErr(e, resp) + } finally { + resolve(); + } + }) + }) +} +//================赚京豆-加速领京豆=================== +async function vvipTask() { + try { + $.vvipFlag = false; + $.rewardBeanNum = 0; + await vvipscdp_raffle_auto_send_bean(); + await pg_channel_page_data(); + if (!$.vvipFlag) return + await vviptask_receive_list();//做任务 + await $.wait(1000) + await pg_channel_page_data(); + } catch (e) { + $.logErr(e) + } +} +function pg_channel_page_data() { + return new Promise(resolve => { + const body = { "paramData": { "token": "3b9f3e0d-7a67-4be3-a05f-9b076cb8ed6a" } }; + $.get(taskUrl('pg_channel_page_data', body), async (err, resp, data) => { + try { + if (err) { + that.log(`${JSON.stringify(err)}`) + that.log(`${$.name} API请求失败,请检查网路重试`) + } else { + if (safeGet(data)) { + data = JSON.parse(data); + if (data['success']) { + if (data['data'] && data['data']['floorInfoList']) { + const floorInfo = data['data']['floorInfoList'].filter(vo => !!vo && vo['code'] === "SWAT_RED_PACKET_ACT_INFO")[0]; + if (floorInfo.hasOwnProperty('token') && floorInfo['floorData'].hasOwnProperty('userActivityInfo')) { + $.token = floorInfo['token']; + const { activityExistFlag, redPacketOpenFlag, redPacketRewardTakeFlag, beanAmountTakeMinLimit, currActivityBeanAmount } = floorInfo['floorData']['userActivityInfo']; + if (activityExistFlag) { + if (!redPacketOpenFlag) { + that.log(`【做任务 天天领京豆】 活动未开启,现在去开启此活动\n`) + await openRedPacket($.token); + } else { + if (currActivityBeanAmount < beanAmountTakeMinLimit) $.vvipFlag = true; + if (redPacketRewardTakeFlag) { + that.log(`【做任务 天天领京豆】 ${beanAmountTakeMinLimit}京豆已领取`); + } else { + if (currActivityBeanAmount >= beanAmountTakeMinLimit) { + //领取200京豆 + that.log(`【做任务 天天领京豆】 累计到${beanAmountTakeMinLimit}京豆可领取到京东账户\n【做任务 天天领京豆】当前进度:${currActivityBeanAmount}/${beanAmountTakeMinLimit}`) + that.log(`【做任务 天天领京豆】 当前已到领取京豆条件。开始领取京豆\n`); + await pg_interact_interface_invoke($.token); + } else { + that.log(`【做任务 天天领京豆】 累计到${beanAmountTakeMinLimit}京豆可领取到京东账户\n【做任务 天天领京豆】当前进度:${currActivityBeanAmount}/${beanAmountTakeMinLimit}`) + that.log(`【做任务 天天领京豆】 当前未达到领取京豆条件。开始做任务\n`); + await pg_channel_page_data(); + } + } + } + } else { + that.log(`【做任务 天天领京豆】 活动已下线`) + } + } + } + } else { + that.log(`pg_channel_page_data: ${data.message}`) + } + } + } + } catch (e) { + $.logErr(e, resp) + } finally { + resolve(); + } + }) + }) +} +//抽奖 +function vvipscdp_raffle_auto_send_bean() { + const body = { "channelCode": "swat_system_id" } + const options = { + url: `${JD_API_HOST}api?functionId=vvipscdp_raffle_auto_send_bean&body=${escape(JSON.stringify(body))}&appid=lottery_drew&t=${new Date().getTime() + new Date().getTimezoneOffset() * 60 * 1000 + 8 * 60 * 60 * 1000}`, + headers: { + "Accept": "*/*", + "Accept-Encoding": "gzip, deflate, br", + "Accept-Language": "zh-cn", + "Connection": "keep-alive", + "Content-Type": "application/x-www-form-urlencoded", + "Host": "api.m.jd.com", + "Referer": "https://lottery.m.jd.com/", + "Cookie": cookie, + "User-Agent": $.isNode() ? (process.env.JD_USER_AGENT ? process.env.JD_USER_AGENT : (require('./USER_AGENTS').USER_AGENT)) : ($.getdata('JDUA') ? $.getdata('JDUA') : "jdapp;iPhone;9.4.4;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"), + } + } + return new Promise((resolve) => { + $.post(options, async (err, resp, data) => { + try { + if (err) { + that.log(`${JSON.stringify(err)}`) + that.log(`${$.name} API请求失败,请检查网路重试`) + } else { + if (safeGet(data)) { + data = JSON.parse(data); + if (data['success']) { + if (data.data && data.data['sendBeanAmount']) { + that.log(`【做任务 天天领京豆】 送成功:获得${data.data['sendBeanAmount']}京豆`) + $.rewardBeanNum += data.data['sendBeanAmount']; + } + } else { + that.log("【做任务 天天领京豆】 送京异常:" + data.message) + } + } + } + } catch (e) { + $.logErr(e, resp) + } finally { + resolve(); + } + }) + }) +} +function vviptask_receive_list() { + $.taskData = []; + const body = { "channel": "SWAT_RED_PACKET", "systemId": "19", "withAutoAward": 1 } + const options = { + url: `${JD_API_HOST}?functionId=vviptask_receive_list&body=${escape(JSON.stringify(body))}&appid=swat_miniprogram&fromType=wxapp×tamp=${new Date().getTime() + new Date().getTimezoneOffset() * 60 * 1000 + 8 * 60 * 60 * 1000}`, + headers: { + "Accept": "*/*", + "Accept-Encoding": "gzip, deflate, br", + "Accept-Language": "zh-cn", + "Connection": "keep-alive", + "Content-Type": "application/x-www-form-urlencoded", + "Host": "api.m.jd.com", + "Referer": "https://servicewechat.com/wxa5bf5ee667d91626/108/page-frame.html", + "Cookie": cookie, + "User-Agent": $.isNode() ? (process.env.JD_USER_AGENT ? process.env.JD_USER_AGENT : (require('./USER_AGENTS').USER_AGENT)) : ($.getdata('JDUA') ? $.getdata('JDUA') : "jdapp;iPhone;9.4.4;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"), + } + } + return new Promise((resolve) => { + $.post(options, async (err, resp, data) => { + try { + if (err) { + that.log(`${JSON.stringify(err)}`) + that.log(`${$.name} API请求失败,请检查网路重试`) + } else { + if (safeGet(data)) { + data = JSON.parse(data); + if (data['success']) { + $.taskData = data['data'].filter(vo => !!vo && vo['taskDataStatus'] !== 3); + for (let item of $.taskData) { + that.log(`\n领取 ${item['title']} 任务`) + await vviptask_receive_getone(item['id']); + await $.wait(1000); + that.log(`去完成 ${item['title']} 任务`) + await vviptask_reach_task(item['id']); + that.log(`领取 ${item['title']} 任务奖励\n`) + await vviptask_reward_receive(item['id']); + } + } + } + } + } catch (e) { + $.logErr(e, resp) + } finally { + resolve(); + } + }) + }) +} +//领取任务 +function vviptask_receive_getone(ids) { + const body = { "channel": "SWAT_RED_PACKET", "systemId": "19", ids } + const options = { + url: `${JD_API_HOST}?functionId=vviptask_receive_getone&body=${escape(JSON.stringify(body))}&appid=swat_miniprogram&fromType=wxapp×tamp=${new Date().getTime() + new Date().getTimezoneOffset() * 60 * 1000 + 8 * 60 * 60 * 1000}`, + headers: { + "Accept": "*/*", + "Accept-Encoding": "gzip, deflate, br", + "Accept-Language": "zh-cn", + "Connection": "keep-alive", + "Content-Type": "application/x-www-form-urlencoded", + "Host": "api.m.jd.com", + "Referer": "https://servicewechat.com/wxa5bf5ee667d91626/108/page-frame.html", + "Cookie": cookie, + "User-Agent": $.isNode() ? (process.env.JD_USER_AGENT ? process.env.JD_USER_AGENT : (require('./USER_AGENTS').USER_AGENT)) : ($.getdata('JDUA') ? $.getdata('JDUA') : "jdapp;iPhone;9.4.4;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"), + } + } + return new Promise((resolve) => { + $.post(options, async (err, resp, data) => { + try { + if (err) { + that.log(`${JSON.stringify(err)}`) + that.log(`${$.name} API请求失败,请检查网路重试`) + } else { + + } + } catch (e) { + $.logErr(e, resp) + } finally { + resolve(); + } + }) + }) +} +//做任务 +function vviptask_reach_task(taskIdEncrypted) { + const body = { "channel": "SWAT_RED_PACKET", "systemId": "19", taskIdEncrypted } + const options = { + url: `${JD_API_HOST}?functionId=vviptask_reach_task&body=${escape(JSON.stringify(body))}&appid=swat_miniprogram&fromType=wxapp×tamp=${new Date().getTime() + new Date().getTimezoneOffset() * 60 * 1000 + 8 * 60 * 60 * 1000}`, + headers: { + "Accept": "*/*", + "Accept-Encoding": "gzip, deflate, br", + "Accept-Language": "zh-cn", + "Connection": "keep-alive", + "Content-Type": "application/x-www-form-urlencoded", + "Host": "api.m.jd.com", + "Referer": "https://servicewechat.com/wxa5bf5ee667d91626/108/page-frame.html", + "Cookie": cookie, + "User-Agent": $.isNode() ? (process.env.JD_USER_AGENT ? process.env.JD_USER_AGENT : (require('./USER_AGENTS').USER_AGENT)) : ($.getdata('JDUA') ? $.getdata('JDUA') : "jdapp;iPhone;9.4.4;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"), + } + } + return new Promise((resolve) => { + $.post(options, (err, resp, data) => { + try { + if (err) { + that.log(`${JSON.stringify(err)}`) + that.log(`${$.name} API请求失败,请检查网路重试`) + } else { + // that.log(`做任务任务:${data}`) + // if (safeGet(data)) { + // data = JSON.parse(data); + // if (data['success']) { + // $.taskData = data['data']; + // for (let item of $.taskData) { + // + // } + // } + // } + } + } catch (e) { + $.logErr(e, resp) + } finally { + resolve(); + } + }) + }) +} +//领取做完任务后的奖励 +function vviptask_reward_receive(idEncKey) { + const body = { "channel": "SWAT_RED_PACKET", "systemId": "19", idEncKey } + const options = { + url: `${JD_API_HOST}?functionId=vviptask_reward_receive&body=${escape(JSON.stringify(body))}&appid=swat_miniprogram&fromType=wxapp×tamp=${new Date().getTime() + new Date().getTimezoneOffset() * 60 * 1000 + 8 * 60 * 60 * 1000}`, + headers: { + "Accept": "*/*", + "Accept-Encoding": "gzip, deflate, br", + "Accept-Language": "zh-cn", + "Connection": "keep-alive", + "Content-Type": "application/x-www-form-urlencoded", + "Host": "api.m.jd.com", + "Referer": "https://servicewechat.com/wxa5bf5ee667d91626/108/page-frame.html", + "Cookie": cookie, + "User-Agent": $.isNode() ? (process.env.JD_USER_AGENT ? process.env.JD_USER_AGENT : (require('./USER_AGENTS').USER_AGENT)) : ($.getdata('JDUA') ? $.getdata('JDUA') : "jdapp;iPhone;9.4.4;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"), + } + } + return new Promise((resolve) => { + $.post(options, (err, resp, data) => { + try { + if (err) { + that.log(`${JSON.stringify(err)}`) + that.log(`${$.name} API请求失败,请检查网路重试`) + } else { + // that.log(`做任务任务:${data}`) + // if (safeGet(data)) { + // data = JSON.parse(data); + // if (data['success']) { + // $.taskData = data['data']; + // for (let item of $.taskData) { + // + // } + // } + // } + } + } catch (e) { + $.logErr(e, resp) + } finally { + resolve(); + } + }) + }) +} +//领取200京豆 +function pg_interact_interface_invoke(floorToken) { + const body = { floorToken, "dataSourceCode": "takeReward", "argMap": {} } + const options = { + url: `${JD_API_HOST}?functionId=pg_interact_interface_invoke&body=${escape(JSON.stringify(body))}&appid=swat_miniprogram&fromType=wxapp×tamp=${new Date().getTime() + new Date().getTimezoneOffset() * 60 * 1000 + 8 * 60 * 60 * 1000}`, + headers: { + "Accept": "*/*", + "Accept-Encoding": "gzip, deflate, br", + "Accept-Language": "zh-cn", + "Connection": "keep-alive", + "Content-Type": "application/x-www-form-urlencoded", + "Host": "api.m.jd.com", + "Referer": "https://servicewechat.com/wxa5bf5ee667d91626/108/page-frame.html", + "Cookie": cookie, + "User-Agent": $.isNode() ? (process.env.JD_USER_AGENT ? process.env.JD_USER_AGENT : (require('./USER_AGENTS').USER_AGENT)) : ($.getdata('JDUA') ? $.getdata('JDUA') : "jdapp;iPhone;9.4.4;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"), + } + } + return new Promise((resolve) => { + $.post(options, (err, resp, data) => { + try { + if (err) { + that.log(`${JSON.stringify(err)}`) + that.log(`${$.name} API请求失败,请检查网路重试`) + } else { + if (safeGet(data)) { + data = JSON.parse(data); + if (data['success']) { + that.log(`【做任务 天天领京豆】${data['data']['rewardBeanAmount']}京豆领取成功`); + $.rewardBeanNum += data['data']['rewardBeanAmount']; + message += "" + `【做任务 天天领京豆】${data['data']['rewardBeanAmount']}京豆领取成功` + " \n\n" + } else { + that.log(`【做任务 天天领京豆】${data.message}`); + } + } + } + } catch (e) { + $.logErr(e, resp) + } finally { + resolve(); + } + }) + }) +} +function openRedPacket(floorToken) { + const body = { floorToken, "dataSourceCode": "openRedPacket", "argMap": {} } + const options = { + url: `${JD_API_HOST}?functionId=pg_interact_interface_invoke&body=${escape(JSON.stringify(body))}&appid=swat_miniprogram&fromType=wxapp×tamp=${new Date().getTime() + new Date().getTimezoneOffset() * 60 * 1000 + 8 * 60 * 60 * 1000}`, + headers: { + "Accept": "*/*", + "Accept-Encoding": "gzip, deflate, br", + "Accept-Language": "zh-cn", + "Connection": "keep-alive", + "Content-Type": "application/x-www-form-urlencoded", + "Host": "api.m.jd.com", + "Referer": "https://servicewechat.com/wxa5bf5ee667d91626/108/page-frame.html", + "Cookie": cookie, + "User-Agent": $.isNode() ? (process.env.JD_USER_AGENT ? process.env.JD_USER_AGENT : (require('./USER_AGENTS').USER_AGENT)) : ($.getdata('JDUA') ? $.getdata('JDUA') : "jdapp;iPhone;9.4.4;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"), + } + } + return new Promise((resolve) => { + $.post(options, (err, resp, data) => { + try { + if (err) { + that.log(`${JSON.stringify(err)}`) + that.log(`${$.name} API请求失败,请检查网路重试`) + } else { + if (safeGet(data)) { + data = JSON.parse(data); + if (data['success']) { + that.log(`活动开启成功,初始:${data.data && data.data['activityBeanInitAmount']}京豆`) + $.vvipFlag = true; + } else { + that.log(data.message) + } + } + } + } catch (e) { + $.logErr(e, resp) + } finally { + resolve(); + } + }) + }) +} +//================赚京豆-加速领京豆===========END======== +//================赚京豆开团=========== +async function distributeBeanActivity() { + try { + $.tuan = '' + $.hasOpen = false; + $.assistStatus = 0; + await getUserTuanInfo() + if (!$.tuan && ($.assistStatus === 3 || $.assistStatus === 2 || $.assistStatus === 0) && $.canStartNewAssist) { + that.log(`准备再次开团`) + await openTuan() + if ($.hasOpen) await getUserTuanInfo() + } + if ($.tuan && $.tuan.hasOwnProperty('assistedPinEncrypted') && $.assistStatus !== 3) { + $.tuanList.push($.tuan); + const code = Object.assign($.tuan, { "time": Date.now() }); + $.post({ + url: `http://go.chiang.fun/autocommit`, + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ "act": "zuan", code }), + timeout: 30000 + }, (err, resp, res) => { + that.log("提交开团码:" + res); + }); + } + } catch (e) { + $.logErr(e); + } +} +function helpFriendTuan(body) { + return new Promise(resolve => { + const data = { + "activityIdEncrypted": body['activityIdEncrypted'], + "assistStartRecordId": body['assistStartRecordId'], + "channel": body['channel'], + } + delete body['time']; + $.get(taskTuanUrl("vvipclub_distributeBean_assist", body), async (err, resp, data) => { + try { + if (err) { + that.log(`${JSON.stringify(err)}`) + that.log(`${$.name} API请求失败,请检查网路重试`) + } else { + if (safeGet(data)) { + data = JSON.parse(data); + if (data.success) { + that.log('助力结果:助力成功\n') + } else { + if (data.resultCode === '9200008') that.log('助力结果:不能助力自己\n') + else if (data.resultCode === '9200011') that.log('助力结果:已经助力过\n') + else if (data.resultCode === '2400205') that.log('助力结果:团已满\n') + else if (data.resultCode === '2400203') { that.log('助力结果:助力次数已耗尽\n'); $.canHelp = false } + else if (data.resultCode === '9000000') { that.log('助力结果:活动火爆,跳出\n'); $.canHelp = false } + else that.log(`助力结果:未知错误\n${JSON.stringify(data)}\n\n`) + } + } + } + } catch (e) { + $.logErr(e, resp) + } finally { + resolve(data); + } + }) + }) +} + +function getUserTuanInfo() { + let body = { "paramData": { "channel": "FISSION_BEAN" } } + return new Promise(resolve => { + $.get(taskTuanUrl("distributeBeanActivityInfo", body), async (err, resp, data) => { + try { + if (err) { + that.log(`${JSON.stringify(err)}`) + that.log(`${$.name} API请求失败,请检查网路重试`) + } else { + if (safeGet(data)) { + data = JSON.parse(data); + if (data['success']) { + $.log(`\n\n当前【赚京豆(微信小程序)-瓜分京豆】能否再次开团: ${data.data.canStartNewAssist ? '可以' : '否'}`) + that.log(`assistStatus ${data.data.assistStatus}`) + if (data.data.assistStatus === 1 && !data.data.canStartNewAssist) { + that.log(`已开团(未达上限),但团成员人未满\n\n`) + } else if (data.data.assistStatus === 3 && data.data.canStartNewAssist) { + that.log(`已开团(未达上限),团成员人已满\n\n`) + } else if (data.data.assistStatus === 3 && !data.data.canStartNewAssist) { + that.log(`今日开团已达上限,且当前团成员人已满\n\n`) + } + if (data.data && !data.data.canStartNewAssist) { + $.tuan = { + "activityIdEncrypted": data.data.id, + "assistStartRecordId": data.data.assistStartRecordId, + "assistedPinEncrypted": data.data.encPin, + "channel": "FISSION_BEAN" + } + } + $.tuanActId = data.data.id; + $.assistNum = data['data']['assistNum'] || 4; + $.assistStatus = data['data']['assistStatus']; + $.canStartNewAssist = data['data']['canStartNewAssist']; + } else { + $.tuan = true;//活动火爆 + that.log(`赚京豆(微信小程序)-瓜分京豆】获取【活动信息失败 ${JSON.stringify(data)}\n`) + } + } + } + } catch (e) { + $.logErr(e, resp) + } finally { + resolve(data); + } + }) + }) +} + +function openTuan() { + let body = { "activityIdEncrypted": $.tuanActId, "channel": "FISSION_BEAN" } + return new Promise(resolve => { + $.get(taskTuanUrl("vvipclub_distributeBean_startAssist", body), async (err, resp, data) => { + try { + if (err) { + that.log(`${JSON.stringify(err)}`) + that.log(`${$.name} API请求失败,请检查网路重试`) + } else { + if (safeGet(data)) { + data = JSON.parse(data); + if (data['success']) { + that.log(`【赚京豆(微信小程序)-瓜分京豆】开团成功`) + $.hasOpen = true + } else { + that.log(`\n开团失败:${JSON.stringify(data)}\n`) + } + } + } + } catch (e) { + $.logErr(e, resp) + } finally { + resolve(data); + } + }) + }) +} + + +//======================赚京豆开团===========END===== +function taskUrl(function_id, body = {}) { + return { + url: `${JD_API_HOST}?functionId=${function_id}&body=${escape(JSON.stringify(body))}&appid=swat_miniprogram&osVersion=5.0.0&clientVersion=3.1.3&fromType=wxapp×tamp=${new Date().getTime() + new Date().getTimezoneOffset() * 60 * 1000 + 8 * 60 * 60 * 1000}`, + headers: { + "Accept": "*/*", + "Accept-Encoding": "gzip, deflate, br", + "Accept-Language": "zh-cn", + "Connection": "keep-alive", + "Content-Type": "application/x-www-form-urlencoded", + "Host": "api.m.jd.com", + "Referer": "https://servicewechat.com/wxa5bf5ee667d91626/108/page-frame.html", + "Cookie": cookie, + "User-Agent": $.isNode() ? (process.env.JD_USER_AGENT ? process.env.JD_USER_AGENT : (require('./USER_AGENTS').USER_AGENT)) : ($.getdata('JDUA') ? $.getdata('JDUA') : "jdapp;iPhone;9.4.4;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"), + } + } +} + +function taskTuanUrl(function_id, body = {}) { + return { + url: `${JD_API_HOST}?functionId=${function_id}&body=${escape(JSON.stringify(body))}&appid=swat_miniprogram&osVersion=5.0.0&clientVersion=3.1.3&fromType=wxapp×tamp=${new Date().getTime() + new Date().getTimezoneOffset() * 60 * 1000 + 8 * 60 * 60 * 1000}`, + headers: { + "Accept": "*/*", + "Accept-Encoding": "gzip, deflate, br", + "Accept-Language": "zh-cn", + "Connection": "keep-alive", + "Content-Type": "application/x-www-form-urlencoded", + "Host": "api.m.jd.com", + "Referer": "https://servicewechat.com/wxa5bf5ee667d91626/108/page-frame.html", + "Cookie": cookie, + "User-Agent": $.isNode() ? (process.env.JD_USER_AGENT ? process.env.JD_USER_AGENT : (require('./USER_AGENTS').USER_AGENT)) : ($.getdata('JDUA') ? $.getdata('JDUA') : "jdapp;iPhone;9.4.4;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"), + } + } +} + +function TotalBean() { + return new Promise(async resolve => { + const options = { + url: "https://me-api.jd.com/user_new/info/GetJDUserInfoUnion", + headers: { + Host: "me-api.jd.com", + Accept: "*/*", + Connection: "keep-alive", + Cookie: cookie, + "User-Agent": $.isNode() ? (process.env.JD_USER_AGENT ? process.env.JD_USER_AGENT : (require('./USER_AGENTS').USER_AGENT)) : ($.getdata('JDUA') ? $.getdata('JDUA') : "jdapp;iPhone;9.4.4;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"), + "Accept-Language": "zh-cn", + "Referer": "https://home.m.jd.com/myJd/newhome.action?sceneval=2&ufc=&", + "Accept-Encoding": "gzip, deflate, br" + } + } + $.get(options, (err, resp, data) => { + try { + if (err) { + $.logErr(err) + } else { + if (data) { + data = JSON.parse(data); + if (data['retcode'] === "1001") { + $.isLogin = false; //cookie过期 + return; + } + if (data['retcode'] === "0" && data.data && data.data.hasOwnProperty("userInfo")) { + $.nickName = data.data.userInfo.baseInfo.nickname; + } + } else { + $.log('京东服务器返回空数据'); + } + } + } catch (e) { + $.logErr(e) + } finally { + resolve(); + } + }) + }) +} +function safeGet(data) { + try { + if (typeof JSON.parse(data) == "object") { + return true; + } + } catch (e) { + that.log(e); + that.log(`京东服务器访问数据为空,请检查自身设备网络情况`); + return false; + } +} +function jsonParse(str) { + if (typeof str == "string") { + try { + return JSON.parse(str); + } catch (e) { + that.log(e); + $.msg($.name, '', '请勿随意在BoxJs输入框修改内容\n建议通过脚本去获取cookie') + return []; + } + } +} + + + + +//我加的函数 +function postToDingTalk(messgae) { + const message1 = "" + messgae + // that.log(messgae) + + const body = { + "msgtype": "markdown", + "markdown": { + "title": "签到领现金", + "text": message1 + }, + "at": { + "atMobiles": [], + "isAtAll": false + } + } + + + $.post(toDingtalk(dingtalk, JSON.stringify(body)), (data, status, xhr) => { + try { + that.log(resp) + that.log(data) + if (err) { + that.log(JSON.stringify(err)); + $.logErr(err); + } else { + if (safeGet(data)) { + $.duckRes = JSON.parse(data); + } + } + } catch (e) { + $.logErr(e, resp) + } finally { + resolve(); + } + }, "json") +} + + +function toDingtalk(urlmain, bodyMain) { + return { + url: urlmain, + body: bodyMain, + headers: { 'Content-Type': 'application/json;charset=utf-8' }, + timeout: 10000, + } +} \ No newline at end of file diff --git a/src/main/resources/test_guochuang.js b/src/main/resources/test_guochuang.js deleted file mode 100644 index d58e87e..0000000 --- a/src/main/resources/test_guochuang.js +++ /dev/null @@ -1,386 +0,0 @@ - -const jdCookieNode = $.isNode() ? require('./jdCookie.js') : ''; - -const randomCount = $.isNode() ? 20 : 5; -const notify = $.isNode() ? require('./sendNotify') : ''; -let merge = {} -let codeList = [] -//IOS等用户直接用NobyDa的jd cookie -let cookiesArr = [],message =- "",timeout,l, - cookie = ''; -if ($.isNode()) { - Object.keys(jdCookieNode).forEach((item) => { - cookiesArr.push(jdCookieNode[item]) - }) - if (process.env.JD_DEBUG && process.env.JD_DEBUG === 'false') that.log = () => {}; -} else { - cookiesArr = [$.getdata('CookieJD'), $.getdata('CookieJD2'), ...jsonParse($.getdata('CookiesJD') || "[]").map(item => item.cookie)].filter(item => !!item); -} - -const JD_API_HOST = `https://api.m.jd.com/client.action`; - -!(async () => { - if (!cookiesArr[0]) { - $.msg($.name, '【提示】请先获取cookie\n直接使用NobyDa的动动签到获取', 'https://bean.m.jd.com/', { - "open-url": "https://bean.m.jd.com/" - }); - return; - } - message += "[通知] 动动国创 \n\n --- \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 = ''; - $.beans = 0 - $.cando = true - username = $.UserName - if ($.UserName == "jd_66ea783827d30"){ - username = "跑腿小弟" - } - if ($.UserName == "jd_4521b375ebb5d"){ - username = "锟锟" - } - if ($.UserName == "jd_542c10c0222bc"){ - username = "康康" - } - //加上名称 - message = message + "【羊毛姐妹】" + username + " \n\n " - - that.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 - } - let actdata= await getid("superBrandSecondFloorMainPage","secondfloor") - if($.cando){ - $.actid = actdata.actid - $.enpid = actdata.enpid - //{actid,actname,enpid} - // await doTask("44spR7W6XFhQXzMvPva99WYLTscr", "1000000157", "3") //关注 - // await superBrandTaskLottery() - await getCode() - - await doTask("secondfloor",$.enpid,$.taskList[0].encryptAssignmentId,$.taskList[0].ext.followShop[0].itemId,$.taskList[0].assignmentType) - await doTask("secondfloor",$.enpid,$.taskList[2].encryptAssignmentId,$.taskList[2].ext.brandMemberList[0].itemId,$.taskList[2].assignmentType) - let signdata= await getid("showSecondFloorSignInfo","sign") - await doTask("sign",signdata.enpid,signdata.eid,1,5) - that.log("开始抽奖") - await superBrandTaskLottery() - await superBrandTaskLottery() - await superBrandTaskLottery() - } - - cookie = cookiesArr[i]; - if (cookie) { - $.UserName = decodeURIComponent(cookie.match(/pt_pin=([^; ]+)(?=;?)/) && cookie.match(/pt_pin=([^; ]+)(?=;?)/)[1]) - $.index = i + 1; - $.isLogin = true; - $.nickName = ''; - // $.beans = 0 - // message = '' - - // await shareCodesFormat(); - that.log(`\n******开始【动动账号${$.index}】\n`); - - for (l = 0; l < codeList.length; l++) { - that.log(`为 ${codeList[l]}助力中`) - await doTask("secondfloor",$.enpid,$.inviteenaid, codeList[l], 2) - } - } - - cookie = cookiesArr[i]; - if (cookie) { - $.UserName = decodeURIComponent(cookie.match(/pt_pin=([^; ]+)(?=;?)/) && cookie.match(/pt_pin=([^; ]+)(?=;?)/)[1]) - $.index = i + 1; - $.isLogin = true; - $.nickName = ''; - // await shareCodesFormat(); - that.log(`\n******开始【动动账号${$.index}】抽奖\n`); - await superBrandTaskLottery() - await superBrandTaskLottery() - await superBrandTaskLottery() - // that.log(`共获得${$.beans} 京豆`) - } - message = message + "" + `共获得${$.beans} 京豆\n` + "\n\n" - } - message = message +"----\n\n" - } -})() -.catch((e) => { - $.logErr(e) - message = message + "" + e + "\n\n" - }) - .finally(() => { - message = message + getPic() - that.log(message) - // postToDingTalk(message) - $.done() - }) -//获取活动信息 - -function getid(functionid,source) { - return new Promise(async (resolve) => { - const options = taskPostUrl(functionid, `{"source":"${source}"}`) - // that.log(options) - $.post(options, async (err, resp, data) => { - try { - if (err) { - that.log(`${JSON.stringify(err)}`); - that.log(`${$.name} API请求失败,请检查网路重试`); - } else { - data = JSON.parse(data); - // that.log(data) - if ( data.data && data.code === "0"&&data.data.result) { - let json = {} - let result =data.data.result - json.actid = result.activityBaseInfo.activityId - json.actname= result.activityBaseInfo.activityName - json.enpid = result.activityBaseInfo.encryptProjectId - if(source === "sign"){json.eid=result.activitySign1Info.encryptAssignmentId} - resolve(json) - that.log(`当前活动:${json.actname} ${json.actid}`) - }else{ - that.log("获取失败") - $.cando = false - resolve() - } - - } - } catch (e) { - $.logErr(e, resp); - } finally { - resolve(); - } - }); - }); -} -function getsignid() { - return new Promise(async (resolve) => { - const options = taskPostUrl("superBrandSecondFloorMainPage", `{"source":"secondfloor"}`) - // that.log(options) - $.post(options, async (err, resp, data) => { - try { - if (err) { - that.log(`${JSON.stringify(err)}`); - that.log(`${$.name} API请求失败,请检查网路重试`); - } else { - data = JSON.parse(data); - // that.log(data) - if ( data.data && data.code === "0") { - $.actid = data.data.result.activityBaseInfo.activityId - $.actname=data.data.result.activityBaseInfo.activityName - $.enpid = data.data.result.activityBaseInfo.encryptProjectId - that.log(`当前活动:${actname} ${$.actid}`) - } - - } - } catch (e) { - $.logErr(e, resp); - } finally { - resolve(); - } - }); - }); -} - -function getCode() { - return new Promise(async (resolve) => { - const options = taskPostUrl("superBrandTaskList", `{"source":"secondfloor","activityId":${$.actid},"assistInfoFlag":1}`) - // that.log(options) - $.post(options, async (err, resp, data) => { - try { - if (err) { - that.log(`${JSON.stringify(err)}`); - that.log(`${$.name} API请求失败,请检查网路重试`); - } else { - data = JSON.parse(data); - // that.log(data.data.result) - if (data && data.data && data.code === "0") { - if (data.data.result && data.data.result.taskList && data.data.result.taskList[3]) { - $.taskList = data.data.result.taskList - let result = data.data.result.taskList[3] - let encryptAssignmentId = result.encryptAssignmentId - let itemid = result.ext.assistTaskDetail.itemId - $.inviteenaid=result.encryptAssignmentId - codeList[codeList.length] = itemid - that.log(`获取邀请码成功 ${itemid}`); - } else { - that.log(data) - } - } - - } - } catch (e) { - $.logErr(e, resp); - } finally { - resolve(); - } - }); - }); -} - -function doTask(source,pid,encryptAssignmentId, id, type) { - return new Promise(async (resolve) => { - const options = taskPostUrl(`superBrandDoTask`, `{"source":"${source}","activityId":${$.actid},"encryptProjectId":"${pid}","encryptAssignmentId":"${encryptAssignmentId}","assignmentType":${type},"itemId":"${id}","actionType":0}`) - // that.log(options) - $.post(options, async (err, resp, data) => { - try { - if (err) { - that.log(`${JSON.stringify(err)}`); - that.log(`${$.name} API请求失败,请检查网路重试`); - } else { - // that.log(data) - data = JSON.parse(data); - if (data && data.code === "0") { - if (data.data.bizCode === "0") { - that.log("任务成功啦~") - } else { - that.log(data.data.bizMsg) - } - resolve(data.data.bizCode) - } else { - that.log(data) - } - } - } catch (e) { - $.logErr(e, resp); - } finally { - resolve(); - } - }); - }); -} - -function superBrandTaskLottery() { - return new Promise(async (resolve) => { - const options = taskPostUrl("superBrandTaskLottery", `{"source":"secondfloor","activityId":${$.actid}}`) - $.post(options, async (err, resp, data) => { - try { - if (err) { - that.log(`${JSON.stringify(err)}`); - that.log(`${$.name} API请求失败,请检查网路重试`); - } else { - data = JSON.parse(data); - // that.log(data) - if (data && data.code === "0") { - if (data.data.bizCode === "TK000") { - that.log(`获得 你猜获得了啥🐶 ${data.data.bizMsg}`) - message += "" + `获得 你猜获得了啥🐶 ${data.data.bizMsg}` + "\n\n" - } else { - that.log(data.data.bizMsg) - } - } else { - that.log(data) - } - } - } catch (e) { - $.logErr(e, resp); - } finally { - resolve(); - } - }); - }); -} - - - -function taskPostUrl(functionid, body) { - const time = Date.now(); - return { - url: `https://api.m.jd.com/api?functionId=${functionid}&appid=ProductZ4Brand&client=wh5&t=${time}&body=${encodeURIComponent(body)}`, - body: "", - 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, - Host: "api.m.jd.com", - Referer: "https://prodev.m.jd.com/mall/active/NrHM6Egy96gxeG4eb7vFX7fYXf3/index.html?activityId=1000007&encryptProjectId=cUNnf3E6aMLQcEQbTVxn8AyhjXb&assistEncryptAssignmentId=2jpJFvC9MBNC7Qsqrt8WzEEcVoiT&assistItemId=S5ijz_8ukVww&tttparams=GgS7lUeyJnTGF0IjoiMzMuMjUyNzYyIiwiZ0xuZyI6IjEwNy4xNjA1MDcifQ6%3D%3D&lng=107.147022&lat=33.255229&sid=e5150a3fdd017952350b4b41294b145w&un_area=27_2442_2444_31912", - "User-Agent": "jdapp;android;9.4.4;10;3b78ecc3f490c7ba;network/UNKNOWN;model/M2006J10C;addressid/138543439;aid/3b78ecc3f490c7ba;oaid/7d5870c5a1696881;osVer/29;appBuild/85576;psn/3b78ecc3f490c7ba|541;psq/2;uid/3b78ecc3f490c7ba;adk/;ads/;pap/JA2015_311210|9.2.4|ANDROID 10;osv/10;pv/548.2;jdv/0|iosapp|t_335139774|appshare|CopyURL|1606277982178|1606277986;ref/com.jd.lib.personal.view.fragment.JDPersonalFragment;partner/xiaomi001;apprpd/MyJD_Main;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/045227 Mobile Safari/537.36", - } - } -} - - -function jsonParse(str) { - if (typeof str == "string") { - try { - return JSON.parse(str); - } catch (e) { - that.log(e); - $.msg($.name, '', '请勿随意在BoxJs输入框修改内容\n建议通过脚本去获取cookie') - return []; - } - } -} - -//我加的函数 -function postToDingTalk(messgae) { - const dingtalk = "https://oapi.dingtalk.com/robot/send?access_token=fa87e34729eaa6113fddfa857efebb477dea0a433d6eecfe93b1d3f5e24847b9" - - const message1 = "" + messgae - that.log(messgae) - - const body = { - "msgtype": "markdown", - "markdown": { - "title":"动动国创", - "text": message1 - }, - "at": { - "atMobiles": [], - "isAtAll": false - } - } - - - $.post(toDingtalk(dingtalk,JSON.stringify(body)), (data,status,xhr)=>{ - try { - that.log(resp) - that.log(data) - if (err) { - that.log(JSON.stringify(err)); - $.logErr(err); - } else { - if (safeGet(data)) { - $.duckRes = JSON.parse(data); - } - } - } catch (e) { - $.logErr(e, resp) - } finally { - resolve(); - } - },"json") -} - - -function toDingtalk(urlmain, bodyMain) { - return { - url: urlmain, - body:bodyMain, - headers: { 'Content-Type': 'application/json;charset=utf-8' }, - timeout: 10000, - } -} -function getPic(){ - let code = ["1.gif","2.png","3.png","4.png","5.gif","6.gif","7.gif","8.gif","9.gif","10.png","11.png"] - let address = "\n\n ![screenshot](https://cdn.jsdelivr.net/gh/selfImprHuang/Go-Tool@v1.2/test/emptyDirTest/3/" - - pos = parseInt(11*Math.random()) - address = address + code[pos] + ")" - return address -} diff --git a/src/main/resources/test_jxSign.js b/src/main/resources/test_jxSign.js new file mode 100644 index 0000000..1afa0f9 --- /dev/null +++ b/src/main/resources/test_jxSign.js @@ -0,0 +1,694 @@ +/* +签到领现金,每日2毛~5毛 +可互助,助力码每日不变,只变日期 +活动入口:京东APP搜索领现金进入 +更新时间:2021-06-07 +已支持IOS双京东账号,Node.js支持N个京东账号 +脚本兼容: QuantumultX, Surge, Loon, JSBox, Node.js +cron "32 0,1,2 * * *" jd_cash.js + */ +const $ = new Env('签到领现金'); +const notify = $.isNode() ? require('./sendNotify') : ''; +//Node.js用户请在jdCookie.js处填写京东ck; +const jdCookieNode = $.isNode() ? require('./jdCookie.js') : ''; +let jdNotify = true;//是否关闭通知,false打开通知推送,true关闭通知推送 +//IOS等用户直接用NobyDa的jd cookie +let cookiesArr = [], cookie = '', message; +const randomCount = $.isNode() ? 5 : 5; +let cash_exchange = false;//是否消耗2元红包兑换200京豆,默认否 +let shareCodes = []; //助力码 +let roleMap = { + "jd_4521b375ebb5d": "锟子怪", + "jd_542c10c0222bc": "康子怪", + "jd_66dcb31363ef6": "涛子怪", + "jd_45d917547c763": "跑腿小怪", + "417040678_m": "斌子怪", + "jd_73d88459d908e": "杰杰子", + "381550701lol": "漪漪子", + "jd_4333d5dc1ac5f": "舒楠子", + "jd_66ea783827d30": "军子", + "jd_4311ac0ff4456": "居子" + } + let dingtalk = "https://oapi.dingtalk.com/robot/send?access_token=d2b6042cb38f0df63e20797c002208d2710104750c18a1dc84d54106a859a3f0" + +if ($.isNode()) { + Object.keys(jdCookieNode).forEach((item) => { + cookiesArr.push(jdCookieNode[item]) + }) +} else { + cookiesArr = [$.getdata('CookieJD'), $.getdata('CookieJD2'), ...jsonParse($.getdata('CookiesJD') || "[]").map(item => item.cookie)].filter(item => !!item); +} +const JD_API_HOST = 'https://api.m.jd.com/client.action'; +let allMessage = ''; +!(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; + } + + message += "[通知] 签到领现金 \n\n" + 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 = ''; + await TotalBean(); + + if (roleMap[username] != undefined) { + username = roleMap[username] + } + //加上名称 + message = message + "【羊毛姐妹】" + username + " \n\n " + 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 jdCash() + } + message += "----\n\n" + } + + postToDingTalk(message) + message += "[通知] 签到领现金 \n\n" + + 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 = ''; + await helpFriends() + } + } + +})() + .catch((e) => { + $.log('', `❌ ${$.name}, 失败! 原因: ${e}!`, '') + }) + .finally(() => { + postToDingTalk(message) + $.done(); + }) + + + +async function jdCash() { + $.signMoney = 0; + await appindex() + await index() + $.exchangeBeanNum = 0; + cash_exchange = false; + await appindex(true) +} + +async function appindex(info = false) { + let functionId = "cash_homePage" + let body = "%7B%7D" + let uuid = randomString(16) + let sign = await getSign(functionId, decodeURIComponent(body), uuid) + let url = `${JD_API_HOST}?functionId=${functionId}&build=167774&client=apple&clientVersion=10.1.0&uuid=${uuid}&${sign}` + return new Promise((resolve) => { + $.post(apptaskUrl(url, body), async (err, resp, data) => { + try { + if (err) { + console.log(`${JSON.stringify(err)}`) + console.log(`${$.name} API请求失败,请检查网路重试`) + } else { + if (safeGet(data)) { + data = JSON.parse(data); + if (data.code === 0 && data.data.result) { + if (info) { + if (message) { + allMessage += `京东账号${$.index}${$.nickName}\n${message}${$.index !== cookiesArr.length ? '\n\n' : ''}`; + } + message += "" + `当前现金:${data.data.result.totalMoney}元`+ " \n\n" + console.log(`\n\n当前现金:${data.data.result.totalMoney}元`); + return + } + $.signMoney = data.data.result.totalMoney; + + console.log(`\n【京东账号${$.index}(${$.UserName})的${$.name}好友互助码】${data.data.result.invitedCode}\n`); + let helpInfo = { + 'inviteCode': data.data.result.invitedCode, + 'shareDate': data.data.result.shareDate + } + shareCodes = shareCodes.push(helpInfo) //添加我的助力码 + + for (let task of data.data.result.taskInfos) { + if (task.type === 4) { + for (let i = task.doTimes; i < task.times; ++i) { + console.log(`去做${task.name}任务 ${i + 1}/${task.times}`) + await appdoTask(task.type, task.jump.params.skuId) + await $.wait(5000) + } + } else if (task.type === 2) { + for (let i = task.doTimes; i < task.times; ++i) { + console.log(`去做${task.name}任务 ${i + 1}/${task.times}`) + await appdoTask(task.type, task.jump.params.shopId) + await $.wait(5000) + } + } else if (task.type === 30) { + for (let i = task.doTimes; i < task.times; ++i) { + console.log(`去做${task.name}任务 ${i + 1}/${task.times}`) + await appdoTask(task.type, task.jump.params.path) + await $.wait(5000) + } + } else if (task.type === 16 || task.type === 3 || task.type === 5 || task.type === 17 || task.type === 21) { + for (let i = task.doTimes; i < task.times; ++i) { + console.log(`去做${task.name}任务 ${i + 1}/${task.times}`) + await appdoTask(task.type, task.jump.params.url) + await $.wait(5000) + } + } + } + } + } + } + } catch (e) { + $.logErr(e, resp) + } finally { + resolve(data); + } + }) + }) +} +function index() { + return new Promise((resolve) => { + $.get(taskUrl("cash_mob_home"), async (err, resp, data) => { + try { + if (err) { + console.log(`${JSON.stringify(err)}`) + console.log(`${$.name} API请求失败,请检查网路重试`) + } else { + if (safeGet(data)) { + data = JSON.parse(data); + if (data.code === 0 && data.data.result) { + for (let task of data.data.result.taskInfos) { + if (task.type === 4) { + for (let i = task.doTimes; i < task.times; ++i) { + console.log(`去做${task.name}任务 ${i + 1}/${task.times}`) + await doTask(task.type, task.jump.params.skuId) + await $.wait(5000) + } + } else if (task.type === 2) { + for (let i = task.doTimes; i < task.times; ++i) { + console.log(`去做${task.name}任务 ${i + 1}/${task.times}`) + await doTask(task.type, task.jump.params.shopId) + await $.wait(5000) + } + } else if (task.type === 31) { + for (let i = task.doTimes; i < task.times; ++i) { + console.log(`去做${task.name}任务 ${i + 1}/${task.times}`) + await doTask(task.type, task.jump.params.path) + await $.wait(5000) + } + } else if (task.type === 16 || task.type === 3 || task.type === 5 || task.type === 17 || task.type === 21) { + for (let i = task.doTimes; i < task.times; ++i) { + console.log(`去做${task.name}任务 ${i + 1}/${task.times}`) + await doTask(task.type, task.jump.params.url) + await $.wait(5000) + } + } + } + } + } + } + } catch (e) { + $.logErr(e, resp) + } finally { + resolve(data); + } + }) + }) +} +async function helpFriends() { + $.canHelp = true + for (let code of shareCodes) { + console.log(`去帮助好友${code['inviteCode']}`) + message += "" + `去帮助好友${code['inviteCode']}`+ " \n\n" + await helpFriend(code) + if (!$.canHelp) break + await $.wait(1000) + } +} + +function helpFriend(helpInfo) { + return new Promise((resolve) => { + $.get(taskUrl("cash_mob_assist", { ...helpInfo, "source": 1 }), (err, resp, data) => { + try { + if (err) { + console.log(`${JSON.stringify(err)}`) + console.log(`${$.name} API请求失败,请检查网路重试`) + } else { + if (safeGet(data)) { + data = JSON.parse(data); + if (data.code === 0 && data.data.bizCode === 0) { + + message += "" + `助力成功,获得${data.data.result.cashStr}`+ " \n\n" + console.log(`助力成功,获得${data.data.result.cashStr}`) + // console.log(data.data.result.taskInfos) + } else if (data.data.bizCode === 207) { + console.log(data.data.bizMsg) + $.canHelp = false + } else { + console.log(data.data.bizMsg) + } + } + } + } catch (e) { + $.logErr(e, resp) + } finally { + resolve(data); + } + }) + }) +} + +async function appdoTask(type, taskInfo) { + let functionId = 'cash_doTask' + let body = escape(JSON.stringify({ "type": type, "taskInfo": taskInfo })) + let uuid = randomString(16) + let sign = await getSign(functionId, decodeURIComponent(body), uuid) + let url = `${JD_API_HOST}?functionId=${functionId}&build=167774&client=apple&clientVersion=10.1.0&uuid=${uuid}&${sign}` + return new Promise((resolve) => { + $.post(apptaskUrl(url, body), (err, resp, data) => { + try { + if (err) { + console.log(`${JSON.stringify(err)}`) + console.log(`${$.name} API请求失败,请检查网路重试`) + } else { + if (safeGet(data)) { + data = JSON.parse(data); + if (data.code === 0) { + console.log(`任务完成成功`) + // console.log(data.data.result.taskInfos) + } else { + console.log(JSON.stringify(data)) + } + } + } + } catch (e) { + $.logErr(e, resp) + } finally { + resolve(data); + } + }) + }) +} +function doTask(type, taskInfo) { + return new Promise((resolve) => { + $.get(taskUrl("cash_doTask", { "type": type, "taskInfo": taskInfo }), (err, resp, data) => { + try { + if (err) { + console.log(`${JSON.stringify(err)}`) + console.log(`${$.name} API请求失败,请检查网路重试`) + } else { + if (safeGet(data)) { + data = JSON.parse(data); + if (data.code === 0) { + console.log(`任务完成成功`) + // console.log(data.data.result.taskInfos) + } else { + console.log(data) + } + } + } + } catch (e) { + $.logErr(e, resp) + } finally { + resolve(data); + } + }) + }) +} +function getReward(source = 1) { + return new Promise((resolve) => { + $.get(taskUrl("cash_mob_reward", { "source": Number(source), "rewardNode": "" }), (err, resp, data) => { + try { + if (err) { + console.log(`${JSON.stringify(err)}`) + console.log(`${$.name} API请求失败,请检查网路重试`) + } else { + if (safeGet(data)) { + data = JSON.parse(data); + if (data.code === 0 && data.data.bizCode === 0) { + console.log(`领奖成功,${data.data.result.shareRewardTip}【${data.data.result.shareRewardAmount}】`) + message += "" +`领奖成功,${data.data.result.shareRewardTip}【${data.data.result.shareRewardAmount}元】\n`+ " \n\n" + + // console.log(data.data.result.taskInfos) + } else { + // console.log(`领奖失败,${data.data.bizMsg}`) + } + } + } + } catch (e) { + $.logErr(e, resp) + } finally { + resolve(data); + } + }) + }) +} +function exchange2(node) { + let body = ''; + const data = { node, "configVersion": "1.0" } + if (data['node'] === '-1') { + body = `body=${encodeURIComponent(JSON.stringify(data))}&uuid=8888888&client=apple&clientVersion=9.4.1&st=1619595890027&sign=92a8abba7b6846f274ac9803aa5a283d&sv=102`; + } else if (data['node'] === '0') { + body = `body=${encodeURIComponent(JSON.stringify(data))}&uuid=8888888&client=apple&clientVersion=9.4.1&st=1619597882090&sign=e00bd6c3af2a53820825b94f7a648551&sv=100`; + } else if (data['node'] === '1') { + body = `body=${encodeURIComponent(JSON.stringify(data))}&uuid=8888888&client=apple&clientVersion=9.4.1&st=1619595655007&sign=2e72bbd21e5f5775fe920eac129f89a2&sv=111`; + } else if (data['node'] === '2') { + body = `body=${encodeURIComponent(JSON.stringify(data))}&uuid=8888888&client=apple&clientVersion=9.4.1&st=1619597924095&sign=c04c70370ff68d71890de08a18cac981&sv=112`; + } else if (data['node'] === '3') { + body = `body=${encodeURIComponent(JSON.stringify(data))}&uuid=8888888&client=apple&clientVersion=9.4.1&st=1619597953001&sign=4c36b3d816d4f0646b5c34e7596502f8&sv=122`; + } + return new Promise((resolve) => { + const options = { + url: `${JD_API_HOST}?functionId=cash_exchangeBeans&t=${Date.now()}&${body}`, + body: `body=${escape(JSON.stringify(data))}`, + headers: { + 'Cookie': cookie, + 'Host': 'api.m.jd.com', + 'Connection': 'keep-alive', + 'Content-Type': 'application/x-www-form-urlencoded', + 'User-Agent': $.isNode() ? (process.env.JD_USER_AGENT ? process.env.JD_USER_AGENT : (require('./USER_AGENTS').USER_AGENT)) : ($.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"), + 'Accept-Language': 'zh-cn', + 'Accept-Encoding': 'gzip, deflate, br', + } + } + $.post(options, async (err, resp, data) => { + try { + if (err) { + console.log(`${JSON.stringify(err)}`) + console.log(`${$.name} API请求失败,请检查网路重试`) + } else { + if (safeGet(data)) { + data = JSON.parse(data); + if (data['code'] === 0) { + if (data.data.bizCode === 0) { + console.log(`花费${data.data.result.needMoney}元红包兑换成功!获得${data.data.result.beanName}\n`) + $.exchangeBeanNum += parseInt(data.data.result.needMoney); + $.canLoop = false; + } else { + console.log('花费2元红包兑换200京豆失败:' + data.data.bizMsg) + if (data.data.bizCode === 504) $.canLoop = true; + if (data.data.bizCode === 120) $.canLoop = false; + } + } else { + console.log(`兑换京豆失败:${JSON.stringify(data)}\n`); + } + } + } + } catch (e) { + $.logErr(e, resp) + } finally { + resolve(data); + } + }) + }) +} +function getSign(functionid, body, uuid) { + return new Promise(async resolve => { + let data = { + "functionId": functionid, + "body": body, + "uuid": uuid, + "client": "apple", + "clientVersion": "10.1.0" + } + let options = { + url: `https://cdn.nz.lu/ddo`, + body: JSON.stringify(data), + headers: { + "Host": "jdsign.cf", + "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 Edg/87.0.4280.88" + }, + timeout: 30 * 1000 + } + $.post(options, (err, resp, data) => { + try { + if (err) { + console.log(JSON.stringify(err)) + console.log(`${$.name} getSign API请求失败,请检查网路重试`) + } else { + + } + } catch (e) { + $.logErr(e, resp) + } finally { + resolve(data); + } + }) + }) +} +function randomString(e) { + e = e || 32; + let t = "abcdefghijklmnopqrstuvwxyz0123456789", a = t.length, n = ""; + for (let i = 0; i < e; i++) + n += t.charAt(Math.floor(Math.random() * a)); + return n +} +function showMsg() { + return new Promise(resolve => { + if (!jdNotify) { + $.msg($.name, '', `${message}`); + } else { + $.log(`京东账号${$.index}${$.nickName}\n${message}`); + } + resolve() + }) +} +function readShareCode() { + console.log(`开始`) + return new Promise(async resolve => { + $.get({ url: `http://code.chiang.fun/api/v1/jd/jdcash/read/${randomCount}/`, 'timeout': 30000 }, (err, resp, data) => { + try { + if (err) { + console.log(`${JSON.stringify(err)}`) + console.log(`${$.name} API请求失败,请检查网路重试`) + } else { + if (data) { + console.log(`随机取${randomCount}个码放到您固定的互助码后面(不影响已有固定互助)`) + data = JSON.parse(data); + } + } + } catch (e) { + $.logErr(e, resp) + } finally { + resolve(data); + } + }) + await $.wait(30000); + resolve() + }) +} + +function deepCopy(obj) { + let objClone = Array.isArray(obj) ? [] : {}; + if (obj && typeof obj === "object") { + for (let key in obj) { + if (obj.hasOwnProperty(key)) { + //判断ojb子元素是否为对象,如果是,递归复制 + if (obj[key] && typeof obj[key] === "object") { + objClone[key] = deepCopy(obj[key]); + } else { + //如果不是,简单复制 + objClone[key] = obj[key]; + } + } + } + } + return objClone; +} + +function apptaskUrl(url, body) { + return { + url, + body: `body=${body}`, + headers: { + 'Cookie': cookie, + 'Host': 'api.m.jd.com', + 'Connection': 'keep-alive', + 'Content-Type': 'application/x-www-form-urlencoded', + 'Referer': '', + 'User-Agent': 'JD4iPhone/167774 (iPhone; iOS 14.7.1; Scale/3.00)', + 'Accept-Language': 'zh-Hans-CN;q=1', + 'Accept-Encoding': 'gzip, deflate, br', + } + } +} +function taskUrl(functionId, body = {}) { + return { + url: `${JD_API_HOST}?functionId=${functionId}&body=${escape(JSON.stringify(body))}&appid=CashRewardMiniH5Env&appid=9.1.0`, + headers: { + 'Cookie': cookie, + 'Host': 'api.m.jd.com', + 'Connection': 'keep-alive', + 'Content-Type': 'application/json', + 'Referer': 'http://wq.jd.com/wxapp/pages/hd-interaction/index/index', + 'User-Agent': $.isNode() ? (process.env.JD_USER_AGENT ? process.env.JD_USER_AGENT : (require('./USER_AGENTS').USER_AGENT)) : ($.getdata('JDUA') ? $.getdata('JDUA') : "jdapp;iPhone;9.4.4;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"), + 'Accept-Language': 'zh-cn', + 'Accept-Encoding': 'gzip, deflate, br', + } + } +} + +function getAuthorShareCode(url) { + return new Promise(resolve => { + const options = { + url: `${url}?${new Date()}`, "timeout": 30000, headers: { + "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 Edg/87.0.4280.88" + } + }; + if ($.isNode() && process.env.TG_PROXY_HOST && process.env.TG_PROXY_PORT) { + const tunnel = require("tunnel"); + const agent = { + https: tunnel.httpsOverHttp({ + proxy: { + host: process.env.TG_PROXY_HOST, + port: process.env.TG_PROXY_PORT * 1 + } + }) + } + Object.assign(options, { agent }) + } + $.get(options, async (err, resp, data) => { + try { + if (err) { + } else { + if (data) data = JSON.parse(data) + } + } catch (e) { + // $.logErr(e, resp) + } finally { + resolve(data); + } + }) + }) +} +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 : (require('./USER_AGENTS').USER_AGENT)) : ($.getdata('JDUA') ? $.getdata('JDUA') : "jdapp;iPhone;9.4.4;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") + } + } + $.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'] && data['base'].nickname) || $.UserName; + } else { + $.nickName = $.UserName + } + } 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输入框修改内容\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) } + + + +//我加的函数 +function postToDingTalk(messgae) { + const message1 = "" + messgae + // that.log(messgae) + + const body = { + "msgtype": "markdown", + "markdown": { + "title": "签到领现金", + "text": message1 + }, + "at": { + "atMobiles": [], + "isAtAll": false + } + } + + + $.post(toDingtalk(dingtalk, JSON.stringify(body)), (data, status, xhr) => { + try { + that.log(resp) + that.log(data) + if (err) { + that.log(JSON.stringify(err)); + $.logErr(err); + } else { + if (safeGet(data)) { + $.duckRes = JSON.parse(data); + } + } + } catch (e) { + $.logErr(e, resp) + } finally { + resolve(); + } + }, "json") + } + + + function toDingtalk(urlmain, bodyMain) { + return { + url: urlmain, + body: bodyMain, + headers: { 'Content-Type': 'application/json;charset=utf-8' }, + timeout: 10000, + } + } \ No newline at end of file diff --git a/src/main/resources/test_money_tree.js b/src/main/resources/test_money_tree.js deleted file mode 100644 index b755ebf..0000000 --- a/src/main/resources/test_money_tree.js +++ /dev/null @@ -1,937 +0,0 @@ -const notify = $.isNode() ? require('./sendNotify') : ''; -//Node.js用户请在jdCookie.js处填写京东ck; -const jdCookieNode = $.isNode() ? require('./jdCookie.js') : ''; - -//IOS等用户直接用NobyDa的jd cookie -let cookiesArr = [], cookie = '', allMsg = ``; -if ($.isNode()) { - Object.keys(jdCookieNode).forEach((item) => { - cookiesArr.push(jdCookieNode[item]) - }) - if (process.env.JD_DEBUG && process.env.JD_DEBUG === 'false') that.log = () => {}; -} else { - cookiesArr = [$.getdata('CookieJD'), $.getdata('CookieJD2'), ...jsonParse($.getdata('CookiesJD') || "[]").map(item => item.cookie)].filter(item => !!item); -} - -let jdNotify = true;//是否开启静默运行,默认true -let sellFruit = true;//是否卖出金果得到金币,默认'false' -const JD_API_HOST = 'https://ms.jr.jd.com/gw/generic/uc/h5/m'; -let userInfo = null, taskInfo = [], message = "", subTitle = '', fruitTotal = 0; -!(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"}); - } - message += "[通知] 动动摇钱树 \n\n --- \n\n" - 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 = ''; - - - username = $.UserName - if ($.UserName == "jd_66ea783827d30"){ - username = "跑腿小弟" - } - if ($.UserName == "jd_4521b375ebb5d"){ - username = "锟锟" - } - if ($.UserName == "jd_542c10c0222bc"){ - username = "康康" - } - //加上名称 - message = message + "【羊毛姐妹】" + username + " \n\n " - - - await TotalBean(); - that.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 - } - subTitle = ''; - await jd_moneyTree(); - } - } - if (allMsg) { - jdNotify = $.isNode() ? (process.env.MONEYTREE_NOTIFY_CONTROL ? process.env.MONEYTREE_NOTIFY_CONTROL : jdNotify) : ($.getdata('jdMoneyTreeNotify') ? $.getdata('jdMoneyTreeNotify') : jdNotify); - if (!jdNotify || jdNotify === 'false') { - if ($.isNode()) await notify.sendNotify($.name, allMsg); - $.msg($.name, '', allMsg) - } - } -})() - .catch((e) => { - $.log('', `❌ ${$.name}, 失败! 原因: ${e}!`, '') - }) - .finally(() => { - message += getPic() - taht.log(message) - postToDingTalk(message) - $.done(); - }) - -async function jd_moneyTree() { - try { - const userRes = await user_info(); - if (!userRes || !userRes.realName) return - await signEveryDay(); - await dayWork(); - await harvest(); - await sell(); - await myWealth(); - await stealFriendFruit() - - $.log(`\n${message}\n`); - } catch (e) { - $.logErr(e) - } -} - -function user_info() { - that.log('初始化摇钱树个人信息'); - const params = { - "sharePin": "", - "shareType": 1, - "channelLV": "", - "source": 2, - "riskDeviceParam": { - "eid": "", - "fp": "", - "sdkToken": "", - "token": "", - "jstub": "", - "appType": "2", - } - } - params.riskDeviceParam = JSON.stringify(params.riskDeviceParam); - await $.wait(5000); //歇口气儿, 不然会报操作频繁 - return new Promise((resolve, reject) => { - $.post(taskurl('login', params), async (err, resp, data) => { - try { - if (err) { - that.log("\n摇钱树京东API请求失败 ‼️‼️") - that.log(JSON.stringify(err)); - } else { - if (data) { - const res = JSON.parse(data); - if (res && res.resultCode === 0) { - $.isLogin = true; - that.log('resultCode为0') - if (res.resultData.data) { - userInfo = res.resultData.data; - // userInfo.realName = null; - if (userInfo.realName) { - // that.log(`助力码sharePin为::${userInfo.sharePin}`); - $.treeMsgTime = userInfo.sharePin; - subTitle = `【${userInfo.nick}】${userInfo.treeInfo.treeName}`; - message += "" + `【我的金果数量】${userInfo.treeInfo.fruit}\n` + "\n\n"; - message += "" + `【我的金币数量】${userInfo.treeInfo.coin}\n` + "\n\n"; - message += "" + `【距离${userInfo.treeInfo.level + 1}级摇钱树还差】${userInfo.treeInfo.progressLeft}\n` + "\n\n"; - } else { - $.log(`京东账号${$.index}${$.UserName}运行失败\n此账号未实名认证或者未参与过此活动\n①如未参与活动,请先去京东app参加摇钱树活动\n入口:我的->游戏与互动->查看更多\n②如未实名认证,请进行实名认证`) - // $.msg($.name, `【提示】京东账号${$.index}${$.UserName}运行失败`, '此账号未实名认证或者未参与过此活动\n①如未参与活动,请先去京东app参加摇钱树活动\n入口:我的->游戏与互动->查看更多\n②如未实名认证,请进行实名认证', {"open-url": "openApp.jdMobile://"}); - message += "" + `运行失败\n此账号未实名认证或者未参与过此活动\n①如未参与活动,请先去京东app参加摇钱树活动\n入口:我的->游戏与互动->查看更多\n②如未实名认证,请进行实名认证` + "\n\n" - } - } - } else { - that.log(`其他情况::${JSON.stringify(res)}`); - } - } else { - that.log(`京豆api返回数据为空,请检查自身原因`) - } - } - } catch (eor) { - $.logErr(eor, err) - } finally { - resolve(userInfo) - } - }) - }) -} - -async function dayWork() { - that.log(`开始做任务userInfo了\n`) - return new Promise(async resolve => { - const data = { - "source": 0, - "linkMissionIds": ["666", "667"], - "LinkMissionIdValues": [7, 7], - "riskDeviceParam": { - "eid": "", - "dt": "", - "ma": "", - "im": "", - "os": "", - "osv": "", - "ip": "", - "apid": "", - "ia": "", - "uu": "", - "cv": "", - "nt": "", - "at": "1", - "fp": "", - "token": "" - } - }; - let response = await request('dayWork', data); - // that.log(`获取任务的信息:${JSON.stringify(response)}\n`) - let canTask = []; - taskInfo = []; - if (response && response.resultCode === 0) { - if (response.resultData.code === '200') { - response.resultData.data.map((item) => { - if (item.prizeType === 2) { - canTask.push(item); - } - if (item.workType === 7 && item.prizeType === 0) { - // missionId.push(item.mid); - taskInfo.push(item); - } - // if (item.workType === 7 && item.prizeType === 0) { - // missionId2 = item.mid; - // } - }) - } - } - that.log(`canTask::${JSON.stringify(canTask)}\n`) - that.log(`浏览任务列表taskInfo::${JSON.stringify(taskInfo)}\n`) - for (let item of canTask) { - if (item.workType === 1) { - // 签到任务 - // let signRes = await sign(); - // that.log(`签到结果:${JSON.stringify(signRes)}`); - if (item.workStatus === 0) { - // const data = {"source":2,"workType":1,"opType":2}; - // let signRes = await request('doWork', data); - let signRes = await sign(); - that.log(`三餐签到结果:${JSON.stringify(signRes)}`); - } else if (item.workStatus === 2) { - that.log(`三餐签到任务已经做过`) - } else if (item.workStatus === -1) { - that.log(`三餐签到任务不在时间范围内`) - } - } else if (item.workType === 2) { - // 分享任务 - if (item.workStatus === 0) { - // share(); - const data = {"source": 0, "workType": 2, "opType": 1}; - //开始分享 - // let shareRes = await request('doWork', data); - let shareRes = await share(data); - that.log(`开始分享的动作:${JSON.stringify(shareRes)}`); - const b = {"source": 0, "workType": 2, "opType": 2}; - // let shareResJL = await request('doWork', b); - let shareResJL = await share(b); - that.log(`领取分享后的奖励:${JSON.stringify(shareResJL)}`) - } else if (item.workStatus === 2) { - that.log(`分享任务已经做过`) - } - } - } - for (let task of taskInfo) { - if (task.mid && task.workStatus === 0) { - that.log('开始做浏览任务'); - // yield setUserLinkStatus(task.mid); - let aa = await setUserLinkStatus(task.mid); - that.log(`aaa${JSON.stringify(aa)}`); - } else if (task.mid && task.workStatus === 1) { - that.log(`workStatus === 1开始领取浏览后的奖励:mid:${task.mid}`); - let receiveAwardRes = await receiveAward(task.mid); - that.log(`领取浏览任务奖励成功:${JSON.stringify(receiveAwardRes)}`) - } else if (task.mid && task.workStatus === 2) { - that.log('所有的浏览任务都做完了') - } - } - resolve(); - }); -} - -function harvest() { - if (!userInfo) return - const data = { - "source": 2, - "sharePin": "", - "userId": userInfo.userInfo, - "userToken": userInfo.userToken, - "shareType": 1, - "channel": "", - "riskDeviceParam": { - "eid": "", - "appType": 2, - "fp": "", - "jstub": "", - "sdkToken": "", - "token": "" - } - } - data.riskDeviceParam = JSON.stringify(data.riskDeviceParam); - return new Promise((rs, rj) => { - request('harvest', data).then((harvestRes) => { - if (harvestRes && harvestRes.resultCode === 0 && harvestRes.resultData.code === '200') { - that.log(`\n收获金果成功:${JSON.stringify(harvestRes)}\n`) - let data = harvestRes.resultData.data; - message +="" + `【距离${data.treeInfo.level + 1}级摇钱树还差】${data.treeInfo.progressLeft}\n` + "\n\n"; - fruitTotal = data.treeInfo.fruit; - } else { - that.log(`\n收获金果异常:${JSON.stringify(harvestRes)}`) - } - rs() - // gen.next(); - }) - }) - // request('harvest', data).then((harvestRes) => { - // if (harvestRes.resultCode === 0 && harvestRes.resultData.code === '200') { - // let data = harvestRes.resultData.data; - // message += `【距离${data.treeInfo.level + 1}级摇钱树还差】${data.treeInfo.progressLeft}\n`; - // fruitTotal = data.treeInfo.fruit; - // gen.next(); - // } - // }) -} - -//卖出金果,得到金币 -function sell() { - return new Promise((rs, rj) => { - const params = { - "source": 2, - "jtCount": 7.000000000000001, - "riskDeviceParam": { - "eid": "", - "fp": "", - "sdkToken": "", - "token": "", - "jstub": "", - "appType": 2, - } - } - params.riskDeviceParam = JSON.stringify(params.riskDeviceParam);//这一步,不可省略,否则提交会报错(和login接口一样) - that.log(`目前金果数量${fruitTotal}`) - sellFruit = $.isNode() ? (process.env.MONEY_TREE_SELL_FRUIT ? process.env.MONEY_TREE_SELL_FRUIT : `${sellFruit}`) : ($.getdata('MONEY_TREE_SELL_FRUIT') ? $.getdata('MONEY_TREE_SELL_FRUIT') : `${sellFruit}`); - if (sellFruit && sellFruit === 'false') { - that.log(`\n设置的不卖出金果\n`) - rs() - return - } - if (fruitTotal >= 8000 * 7) { - if (userInfo['jtRest'] === 0) { - that.log(`\n今日已卖出5.6万金果(已达上限),获得0.07金贴\n`) - rs() - return - } - request('sell', params).then((sellRes) => { - if (sellRes && sellRes['resultCode'] === 0) { - if (sellRes['resultData']['code'] === '200') { - if (sellRes['resultData']['data']['sell'] === 0) { - that.log(`卖出金果成功,获得0.07金贴\n`); - allMsg += `账号${$.index}:${$.nickName || $.UserName}\n今日成功卖出5.6万金果,获得0.07金贴${$.index !== cookiesArr.length ? '\n\n' : ''}` - } else { - that.log(`卖出金果失败:${JSON.stringify(sellRes)}\n`) - } - } - } - rs() - }) - } else { - that.log(`当前金果数量不够兑换 0.07金贴\n`); - rs() - } - // request('sell', params).then(response => { - // rs(response); - // }) - }) - // request('sell', params).then((sellRes) => { - // that.log(`卖出金果结果:${JSON.stringify(sellRes)}\n`) - // gen.next(); - // }) -} - -//获取金币和金果数量 -function myWealth() { - return new Promise((resolve) => { - const params = { - "source": 2, - "riskDeviceParam": { - "eid": "", - "dt": "", - "ma": "", - "im": "", - "os": "", - "osv": "", - "ip": "", - "apid": "", - "ia": "", - "uu": "", - "cv": "", - "nt": "", - "at": "1", - "fp": "", - "token": "" - } - } - params.riskDeviceParam = JSON.stringify(params.riskDeviceParam);//这一步,不可省略,否则提交会报错(和login接口一样) - request('myWealth', params).then(res => { - if (res && res.resultCode === 0 && res.resultData.code === '200') { - that.log(`金贴和金果数量::${JSON.stringify(res)}`); - message += "" + `【我的金果数量】${res.resultData.data.gaAmount}\n` + "\n\n"; - message += "" + `【我的金贴数量】${res.resultData.data.gcAmount / 100}\n` + "\n\n"; - } - resolve(); - }) - }); -} - -function sign() { - that.log('开始三餐签到') - const data = {"source": 2, "workType": 1, "opType": 2}; - return new Promise((rs, rj) => { - request('doWork', data).then(response => { - rs(response); - }) - }) -} - -function signIndex() { - const params = { - "source": 0, - "riskDeviceParam": { - "eid": "", - "dt": "", - "ma": "", - "im": "", - "os": "", - "osv": "", - "ip": "", - "apid": "", - "ia": "", - "uu": "", - "cv": "", - "nt": "", - "at": "1", - "fp": "", - "token": "" - } - } - return new Promise((rs, rj) => { - request('signIndex', params).then(response => { - rs(response); - }) - }) -} - -async function signEveryDay() { - return new Promise(async (resolve) => { - try { - let signIndexRes = await signIndex(); - if (signIndexRes.resultCode === 0) { - that.log(`每日签到条件查询:${signIndexRes.resultData.data.canSign === 2 ? '可以签到' : '已经签到过了'}`); - if (signIndexRes.resultData && signIndexRes.resultData.data.canSign == 2) { - that.log('准备每日签到') - let signOneRes = await signOne(signIndexRes.resultData.data.signDay); - that.log(`第${signIndexRes.resultData.data.signDay}日签到结果:${JSON.stringify(signOneRes)}`); - if (signIndexRes.resultData.data.signDay === 7) { - let getSignAwardRes = await getSignAward(); - that.log(`店铺券(49-10)领取结果:${JSON.stringify(getSignAwardRes)}`) - if (getSignAwardRes.resultCode === 0 && getSignAwardRes.data.code === 0) { - message += "" + `【7日签到奖励领取】${getSignAwardRes.datamessage}\n` + "\n\n" - } - } - } - } - } catch (e) { - $.logErr(e); - } finally { - resolve() - } - }) -} - -function signOne(signDay) { - const params = { - "source": 0, - "signDay": signDay, - "riskDeviceParam": { - "eid": "", - "dt": "", - "ma": "", - "im": "", - "os": "", - "osv": "", - "ip": "", - "apid": "", - "ia": "", - "uu": "", - "cv": "", - "nt": "", - "at": "1", - "fp": "", - "token": "" - } - } - return new Promise((rs, rj) => { - request('signOne', params).then(response => { - rs(response); - }) - }) -} - -// 领取七日签到后的奖励(店铺优惠券) -function getSignAward() { - const params = { - "source": 2, - "awardType": 2, - "deviceRiskParam": 1, - "riskDeviceParam": { - "eid": "", - "dt": "", - "ma": "", - "im": "", - "os": "", - "osv": "", - "ip": "", - "apid": "", - "ia": "", - "uu": "", - "cv": "", - "nt": "", - "at": "1", - "fp": "", - "token": "" - } - } - return new Promise((rs, rj) => { - request('getSignAward', params).then(response => { - rs(response); - }) - }) -} - -// 浏览任务 -async function setUserLinkStatus(missionId) { - let index = 0; - do { - const params = { - "missionId": missionId, - "pushStatus": 1, - "keyValue": index, - "riskDeviceParam": { - "eid": "", - "dt": "", - "ma": "", - "im": "", - "os": "", - "osv": "", - "ip": "", - "apid": "", - "ia": "", - "uu": "", - "cv": "", - "nt": "", - "at": "1", - "fp": "", - "token": "" - } - } - let response = await request('setUserLinkStatus', params) - that.log(`missionId为${missionId}::第${index + 1}次浏览活动完成: ${JSON.stringify(response)}`); - // if (resultCode === 0) { - // let sportRevardResult = await getSportReward(); - // that.log(`领取遛狗奖励完成: ${JSON.stringify(sportRevardResult)}`); - // } - index++; - } while (index < 7) //不知道结束的条件,目前写死循环7次吧 - that.log('浏览店铺任务结束'); - that.log('开始领取浏览后的奖励'); - let receiveAwardRes = await receiveAward(missionId); - that.log(`领取浏览任务奖励成功:${JSON.stringify(receiveAwardRes)}`) - return new Promise((resolve, reject) => { - resolve(receiveAwardRes); - }) - // gen.next(); -} - -// 领取浏览后的奖励 -function receiveAward(mid) { - if (!mid) return - mid = mid + ""; - const params = { - "source": 0, - "workType": 7, - "opType": 2, - "mid": mid, - "riskDeviceParam": { - "eid": "", - "dt": "", - "ma": "", - "im": "", - "os": "", - "osv": "", - "ip": "", - "apid": "", - "ia": "", - "uu": "", - "cv": "", - "nt": "", - "at": "1", - "fp": "", - "token": "" - } - } - return new Promise((rs, rj) => { - request('doWork', params).then(response => { - rs(response); - }) - }) -} - -function share(data) { - if (data.opType === 1) { - that.log(`开始做分享任务\n`) - } else { - that.log(`开始做领取分享后的奖励\n`) - } - return new Promise((rs, rj) => { - request('doWork', data).then(response => { - rs(response); - }) - }) -} - -async function stealFriendFruit() { - await friendRank(); - if ($.friendRankList && $.friendRankList.length > 0) { - const canSteal = $.friendRankList.some((item) => { - const boxShareCode = item.steal - return (boxShareCode === true); - }); - if (canSteal) { - $.amount = 0; - for (let item of $.friendRankList) { - if (!item.self && item.steal) { - await friendTreeRoom(item.encryPin); - const stealFruitRes = await stealFruit(item.encryPin, $.friendTree.stoleInfo); - if (stealFruitRes && stealFruitRes.resultCode === 0 && stealFruitRes.resultData.code === '200') { - $.amount += stealFruitRes.resultData.data.amount; - } - } - } - message +="" + `【偷取好友金果】共${$.amount}个\n` + "\n\n"; - } else { - that.log(`今日已偷过好友的金果了,暂无好友可偷,请明天再来\n`) - } - } else { - that.log(`您暂无好友,故跳过`); - } -} - -//获取好友列表API -async function friendRank() { - await $.wait(1000); //歇口气儿, 不然会报操作频繁 - const params = { - "source": 2, - "riskDeviceParam": { - "eid": "", - "dt": "", - "ma": "", - "im": "", - "os": "", - "osv": "", - "ip": "", - "apid": "", - "ia": "", - "uu": "", - "cv": "", - "nt": "", - "at": "1", - "fp": "", - "token": "" - } - } - params.riskDeviceParam = JSON.stringify(params.riskDeviceParam);//这一步,不可省略,否则提交会报错(和login接口一样) - return new Promise((resolve, reject) => { - $.post(taskurl('friendRank', params), (err, resp, data) => { - try { - if (err) { - that.log("\n摇钱树京东API请求失败 ‼️‼️"); - that.log(JSON.stringify(err)); - $.logErr(err); - } else { - if (data) { - data = JSON.parse(data); - $.friendRankList = data.resultData.data; - } else { - that.log(`京豆api返回数据为空,请检查自身原因`) - } - } - } catch (eor) { - $.logErr(eor, err) - } finally { - resolve() - } - }) - }) -} - -// 进入好友房间API -async function friendTreeRoom(friendPin) { - await $.wait(1000); //歇口气儿, 不然会报操作频繁 - const params = { - "source": 2, - "friendPin": friendPin, - "riskDeviceParam": { - "eid": "", - "dt": "", - "ma": "", - "im": "", - "os": "", - "osv": "", - "ip": "", - "apid": "", - "ia": "", - "uu": "", - "cv": "", - "nt": "", - "at": "1", - "fp": "", - "token": "" - } - } - params.riskDeviceParam = JSON.stringify(params.riskDeviceParam);//这一步,不可省略,否则提交会报错(和login接口一样) - return new Promise((resolve, reject) => { - $.post(taskurl('friendTree', params), (err, resp, data) => { - try { - if (err) { - that.log("\n摇钱树京东API请求失败 ‼️‼️"); - that.log(JSON.stringify(err)); - $.logErr(err); - } else { - if (data) { - data = JSON.parse(data); - $.friendTree = data.resultData.data; - } else { - that.log(`京豆api返回数据为空,请检查自身原因`) - } - } - } catch (eor) { - $.logErr(eor, err) - } finally { - resolve() - } - }) - }) -} - -//偷好友金果API -async function stealFruit(friendPin, stoleId) { - await $.wait(1000); //歇口气儿, 不然会报操作频繁 - const params = { - "source": 2, - "friendPin": friendPin, - "stoleId": stoleId, - "riskDeviceParam": { - "eid": "", - "dt": "", - "ma": "", - "im": "", - "os": "", - "osv": "", - "ip": "", - "apid": "", - "ia": "", - "uu": "", - "cv": "", - "nt": "", - "at": "1", - "fp": "", - "token": "" - } - } - params.riskDeviceParam = JSON.stringify(params.riskDeviceParam);//这一步,不可省略,否则提交会报错(和login接口一样) - return new Promise((resolve, reject) => { - $.post(taskurl('stealFruit', params), (err, resp, data) => { - try { - if (err) { - that.log("\n摇钱树京东API请求失败 ‼️‼️"); - that.log(JSON.stringify(err)); - $.logErr(err); - } else { - if (data) { - data = JSON.parse(data); - } else { - that.log(`京豆api返回数据为空,请检查自身原因`) - } - } - } catch (eor) { - $.logErr(eor, err) - } finally { - resolve(data) - } - }) - }) -} - - -async function request(function_id, body = {}) { - await $.wait(1000); //歇口气儿, 不然会报操作频繁 - return new Promise((resolve, reject) => { - $.post(taskurl(function_id, body), (err, resp, data) => { - try { - if (err) { - that.log("\n摇钱树京东API请求失败 ‼️‼️"); - that.log(JSON.stringify(err)); - $.logErr(err); - } else { - if (data) { - data = JSON.parse(data); - } else { - that.log(`京豆api返回数据为空,请检查自身原因`) - } - } - } catch (eor) { - $.msg("摇钱树-初始化个人信息" + eor.name + "‼️", JSON.stringify(eor), eor.message) - } finally { - resolve(data) - } - }) - }) -} - -function taskurl(function_id, body) { - return { - url: JD_API_HOST + '/' + function_id + '?_=' + new Date().getTime() * 1000, - body: `reqData=${function_id === 'harvest' || function_id === 'login' || function_id === 'signIndex' || function_id === 'signOne' || function_id === 'setUserLinkStatus' || function_id === 'dayWork' || function_id === 'getSignAward' || function_id === 'sell' || function_id === 'friendRank' || function_id === 'friendTree' || function_id === 'stealFruit' ? encodeURIComponent(JSON.stringify(body)) : JSON.stringify(body)}`, - headers: { - 'Accept': `application/json`, - 'Origin': `https://uua.jr.jd.com`, - 'Accept-Encoding': `gzip, deflate, br`, - 'Cookie': cookie, - 'Content-Type': `application/x-www-form-urlencoded;charset=UTF-8`, - 'Host': `ms.jr.jd.com`, - 'Connection': `keep-alive`, - 'User-Agent': $.isNode() ? (process.env.JD_USER_AGENT ? process.env.JD_USER_AGENT : (require('./USER_AGENTS').USER_AGENT)) : ($.getdata('JDUA') ? $.getdata('JDUA') : "jdapp;iPhone;9.4.4;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"), - 'Referer': `https://uua.jr.jd.com/uc-fe-wxgrowing/moneytree/index`, - 'Accept-Language': `zh-cn` - } - } -} - -function TotalBean() { - return new Promise(async resolve => { - const options = { - url: "https://me-api.jd.com/user_new/info/GetJDUserInfoUnion", - headers: { - Host: "me-api.jd.com", - Accept: "*/*", - Connection: "keep-alive", - Cookie: cookie, - "User-Agent": $.isNode() ? (process.env.JD_USER_AGENT ? process.env.JD_USER_AGENT : (require('./USER_AGENTS').USER_AGENT)) : ($.getdata('JDUA') ? $.getdata('JDUA') : "jdapp;iPhone;9.4.4;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"), - "Accept-Language": "zh-cn", - "Referer": "https://home.m.jd.com/myJd/newhome.action?sceneval=2&ufc=&", - "Accept-Encoding": "gzip, deflate, br" - } - } - $.get(options, (err, resp, data) => { - try { - if (err) { - $.logErr(err) - } else { - if (data) { - data = JSON.parse(data); - if (data['retcode'] === "1001") { - $.isLogin = false; //cookie过期 - return; - } - if (data['retcode'] === "0" && data.data && data.data.hasOwnProperty("userInfo")) { - $.nickName = data.data.userInfo.baseInfo.nickname; - } - } else { - $.log('京东服务器返回空数据'); - } - } - } catch (e) { - $.logErr(e) - } finally { - resolve(); - } - }) - }) -} - - -function jsonParse(str) { - if (typeof str == "string") { - try { - return JSON.parse(str); - } catch (e) { - that.log(e); - $.msg($.name, '', '请勿随意在BoxJs输入框修改内容\n建议通过脚本去获取cookie') - return []; - } - } -} - - -//我加的函数 -function postToDingTalk(messgae) { - const dingtalk = "https://oapi.dingtalk.com/robot/send?access_token=18444b555747aad3381bc1d1e3dea72b03158e152a846f818d82a1ca946bd430" - - const message1 = "" + messgae - that.log(messgae) - - const body = { - "msgtype": "markdown", - "markdown": { - "title":"动动摇钱树", - "text": message1 - }, - "at": { - "atMobiles": [], - "isAtAll": false - } - } - - - $.post(toDingtalk(dingtalk,JSON.stringify(body)), (data,status,xhr)=>{ - try { - that.log(resp) - that.log(data) - if (err) { - that.log(JSON.stringify(err)); - $.logErr(err); - } else { - if (safeGet(data)) { - $.duckRes = JSON.parse(data); - } - } - } catch (e) { - $.logErr(e, resp) - } finally { - resolve(); - } - },"json") -} - - -function toDingtalk(urlmain, bodyMain) { - return { - url: urlmain, - body:bodyMain, - headers: { 'Content-Type': 'application/json;charset=utf-8' }, - timeout: 10000, - } -} -function getPic(){ - let code = ["1.gif","2.png","3.png","4.png","5.gif","6.gif","7.gif","8.gif","9.gif","10.png","11.png"] - let address = "\n\n ![screenshot](https://cdn.jsdelivr.net/gh/selfImprHuang/Go-Tool@v1.2/test/emptyDirTest/3/" - - pos = parseInt(11*Math.random()) - address = address + code[pos] + ")" - return address -} diff --git a/src/main/resources/test_redPocket.js b/src/main/resources/test_redPocket.js new file mode 100644 index 0000000..d2912b4 --- /dev/null +++ b/src/main/resources/test_redPocket.js @@ -0,0 +1,724 @@ +/* +京东全民开红包 +Last Modified time: 2021-05-19 16:27:18 +活动入口:京东APP首页-领券-锦鲤红包。[活动地址](https://happy.m.jd.com/babelDiy/zjyw/3ugedFa7yA6NhxLN5gw2L3PF9sQC/index.html) +未实现功能:领3张券功能 + +脚本兼容: QuantumultX, Surge, Loon, JSBox, Node.js +================QuantumultX================== +[task_local] +#京东全民开红包 +1 1,2,23 * * * https://raw.githubusercontent.com/Aaron-lv/sync/jd_scripts/jd_redPacket.js, tag=京东全民开红包, img-url=https://raw.githubusercontent.com/58xinian/icon/master/jd_redPacket.png, enabled=true +===================Loon============== +[Script] +cron "1 1,2,23 * * *" script-path=https://raw.githubusercontent.com/Aaron-lv/sync/jd_scripts/jd_redPacket.js, tag=京东全民开红包 +===============Surge=============== +[Script] +京东全民开红包 = type=cron,cronexp="1 1,2,23 * * *",wake-system=1,timeout=3600,script-path=https://raw.githubusercontent.com/Aaron-lv/sync/jd_scripts/jd_redPacket.js +====================================小火箭============================= +京东全民开红包 = type=cron,script-path=https://raw.githubusercontent.com/Aaron-lv/sync/jd_scripts/jd_redPacket.js, cronexpr="1 1,2,23 * * *", timeout=3600, enable=true + */ +const $ = new Env('京东全民开红包'); +const notify = $.isNode() ? require('./sendNotify') : ''; +//Node.js用户请在jdCookie.js处填写京东ck; +const jdCookieNode = $.isNode() ? require('./jdCookie.js') : ''; +//IOS等用户直接用NobyDa的jd cookie +let cookiesArr = [], cookie = ''; +let isLoginInfo = {} +let redPacketId = []; +let roleMap = { + "jd_4521b375ebb5d": "锟子怪", + "jd_542c10c0222bc": "康子怪", + "jd_66dcb31363ef6": "涛子怪", + "jd_45d917547c763": "跑腿小怪", + "417040678_m": "斌子怪", + "jd_73d88459d908e": "杰杰子", + "381550701lol": "漪漪子", + "jd_4333d5dc1ac5f": "舒楠子", + "jd_66ea783827d30": "军子", + "jd_4311ac0ff4456": "居子" +} +let dingtalk = "https://oapi.dingtalk.com/robot/send?access_token=d2b6042cb38f0df63e20797c002208d2710104750c18a1dc84d54106a859a3f0" +let message = "" + +if ($.isNode()) { + Object.keys(jdCookieNode).forEach((item) => { + cookiesArr.push(jdCookieNode[item]) + }) + if (process.env.JD_DEBUG && process.env.JD_DEBUG === 'false') console.log = () => {}; + if (JSON.stringify(process.env).indexOf('GITHUB') > -1) process.exit(0); +} else { + cookiesArr = [$.getdata('CookieJD'), $.getdata('CookieJD2'), ...jsonParse($.getdata('CookiesJD') || "[]").map(item => item.cookie)].filter(item => !!item); +} +const JD_API_HOST = 'https://api.m.jd.com/api'; +!(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; + } + let res = await getAuthorShareCode('https://raw.githubusercontent.com/Aaron-lv/updateTeam/master/shareCodes/jd_red.json') + if (!res) { + $.http.get({url: 'https://purge.jsdelivr.net/gh/Aaron-lv/updateTeam@master/shareCodes/jd_red.json'}).then((resp) => {}).catch((e) => $.log('刷新CDN异常', e)); + await $.wait(1000) + res = await getAuthorShareCode('https://cdn.jsdelivr.net/gh/Aaron-lv/updateTeam@master/shareCodes/jd_red.json') + } + $.authorMyShareIds = [...(res || [])]; + + message += "[通知] 全民开红包 \n\n" + + 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 = ''; + await TotalBean(); + isLoginInfo[$.UserName] = $.isLogin + + if (roleMap[username] != undefined) { + username = roleMap[username] + } + //加上名称 + message = message + "【羊毛姐妹】" + username + " \n\n " + + + 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 + } + $.discount = 0; + await redPacket(); + await showMsg(); + } + + message += "----\n\n" + } + postToDingTalk(message) + message += "[通知] 全民开红包 \n\n" + + + for (let i = 0; i < cookiesArr.length; i++) { + cookie = cookiesArr[i]; + $.index = i + 1; + $.UserName = decodeURIComponent(cookie.match(/pt_pin=([^; ]+)(?=;?)/) && cookie.match(/pt_pin=([^; ]+)(?=;?)/)[1]); + $.canHelp = true; + if (!isLoginInfo[$.UserName]) continue + if (cookiesArr && cookiesArr.length >= 2) { + console.log(`\n\n自己账号内部互助`); + for (let j = 0; j < redPacketId.length && $.canHelp; j++) { + console.log(`账号 ${$.index} ${$.UserName} 开始给 ${redPacketId[j]} 进行助力`) + $.max = false; + message += "" +`开始给${redPacketId[j]}助力`+ " \n\n" + await jinli_h5assist(redPacketId[j]); + await $.wait(2000) + if ($.max) { + // $.redPacketId.splice(j, 1) + j-- + continue + } + } + } + } +})() + .catch((e) => { + $.log('', `❌ ${$.name}, 失败! 原因: ${e}!`, '') + }) + .finally(() => { + postToDingTalk(message) + $.done(); + }) + +async function redPacket() { + try { + await doLuckDrawFun();//券后9.9抽奖 + await taskHomePage();//查询任务列表 + await doTask();//领取任务,做任务,领取红包奖励 + await h5activityIndex();//查询红包基础信息 + await red();//红包任务(发起助力红包,领取助力红包等) + await h5activityIndex(); + } catch (e) { + $.logErr(e); + } +} +function showMsg() { + console.log(`\n\n${$.name}获得红包:${$.discount}元\n\n`); + // $.msg($.name, '', `${$.name}:${$.discount}元`) +} +async function doLuckDrawFun() { + for (let i = 0; i < 3; i++) { + await doLuckDrawEntrance(); + } +} +function doLuckDrawEntrance() { + return new Promise(resolve => { + const options = { + url: 'https://api.m.jd.com/client.action?functionId=doLuckDrawEntrance&body=%7B%22platformType%22%3A%221%22%7D&appid=XPMSGC2019&client=m&clientVersion=1.0.0&area=19_1601_50258_62858&geo=%5Bobject%20Object%5D&uuid=88732f840b77821b345bf07fd71f609e6ff12f43', + headers: { + "Host": "api.m.jd.com", + "Origin": "https://h5.m.jd.com", + "Cookie": cookie, + "Content-Length": "0", + "Connection": "keep-alive", + "Accept": "application/json, text/plain, */*", + "User-Agent": "jdapp;iPhone;9.5.4;14.3;88732f840b77821b345bf07fd71f609e6ff12f43;network/4g;model/iPhone11,8;addressid/2005183373;appBuild/167668;jdSupportDarkMode/0;Mozilla/5.0 (iPhone; CPU iPhone OS 14_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1", + "Accept-Language": "zh-cn", + "Referer": "https://h5.m.jd.com/babelDiy/Zeus/yj8mbcm6roENn7qhNdhiekyeqtd/index.html", + "Accept-Encoding": "gzip, deflate, br" + } + } + $.post(options, async (err, resp, data) => { + try { + if (err) { + console.log(`${JSON.stringify(err)}`) + console.log(`${$.name} API请求失败,请检查网路重试`) + } else { + if (data) { + data = JSON.parse(data); + if (data.code === '0' && data.busiCode === '0') { + if (data.result.luckyDrawData.actId) { + if (data.result.luckyDrawData.redPacketId) { + message += "" +`券后9.9抽奖获得【红包】:${data.result.luckyDrawData.quota}元` + " \n\n" + console.log(`券后9.9抽奖获得【红包】:${data.result.luckyDrawData.quota}元`); + } else { + message += "" + `券后9.9抽奖获得【优惠券】:${data.result.luckyDrawData.discount}元:${data.result.luckyDrawData.prizeName},${data.result.luckyDrawData.quotaDesc}` + " \n\n" + console.log(`券后9.9抽奖获得【优惠券】:${data.result.luckyDrawData.discount}元:${data.result.luckyDrawData.prizeName},${data.result.luckyDrawData.quotaDesc}`); + } + } else { + console.log(`券后9.9抽奖获失败:今日3次抽奖机会已用完\n`) + } + } + } + } + } catch (e) { + $.logErr(e, resp) + } finally { + resolve(); + } + }) + }) +} +async function doTask() { + if ($.taskHomePageData && $.taskHomePageData.code === 0) { + $.taskInfo = $.taskHomePageData.data.result.taskInfos; + if ($.taskInfo && $.taskInfo.length > 0) { + console.log(` 任务 状态 红包是否领取`); + for (let item of $.taskInfo) { + console.log(`${item.title.slice(-6)} ${item.alreadyReceivedCount ? item.alreadyReceivedCount: 0}/${item.requireCount} ${item.innerStatus === 4 ? '是':'否'}`) + } + for (let item of $.taskInfo) { + //innerStatus=4已领取红包,3:任务已完成,红包未领取,2:任务已领取,但未完成,7,未领取任务 + if (item.innerStatus === 4) { + console.log(`[${item.title}] 已经领取奖励`) + } else if (item.innerStatus === 3) { + await receiveTaskRedpacket(item.taskType); + } else if (item.innerStatus === 2) { + if (item.taskType !== 0 && item.taskType !== 1) { + console.log(`开始做【${item.title}】任务`); + await active(item.taskType); + console.log(`开始领取【${item.title}】任务所得红包奖励`); + await receiveTaskRedpacket(item.taskType); + } else if (item.taskType === 1) { + //浏览10秒任务 + console.log(`开始做【${item.title}】任务`); + await doAppTask(); + } else { + //TODO 领3张优惠券 + console.log(`[${item.title}] 功能未开发`) + } + } else if (item.innerStatus !== 4) { + console.log(`\n开始领取【${item.title}】任务`); + await startTask(item.taskType); + if (item.taskType !== 0 && item.taskType !== 1) { + console.log(`开始做【${item.title}】任务`); + await active(item.taskType); + console.log(`开始领取【${item.title}】任务所得红包奖励`); + await receiveTaskRedpacket(item.taskType); + } else if (item.taskType === 1) { + //浏览10秒任务 + console.log(`开始做【${item.title}】任务`); + await doAppTask(); + } else { + //TODO 领3张优惠券 + console.log(`[${item.title}] 功能未开发`) + } + } + } + } + } else { + console.log(`\n获取任务列表异常:${JSON.stringify($.taskHomePageData)}\n`) + } +} +async function red() { + $.hasSendNumber = 0; + $.assistants = 0; + $.waitOpenTimes = 0; + if ($.h5activityIndex && $.h5activityIndex.data && $.h5activityIndex.data.result) { + const rewards = $.h5activityIndex.data.result.rewards || []; + $.hasSendNumber = $.h5activityIndex.data.result.hasSendNumber; + if ($.h5activityIndex.data.result.redpacketConfigFillRewardInfo) { + for (let key of Object.keys($.h5activityIndex.data.result.redpacketConfigFillRewardInfo)) { + let vo = $.h5activityIndex.data.result.redpacketConfigFillRewardInfo[key] + $.assistants += vo.hasAssistNum + if (vo.packetStatus === 1) { + $.waitOpenTimes += 1 + } + } + } + } + if ($.h5activityIndex && $.h5activityIndex.data && $.h5activityIndex.data.biz_code === 10002) { + //可发起拆红包活动 + await h5launch(); + } else if ($.h5activityIndex && $.h5activityIndex.data && ($.h5activityIndex.data.biz_code === 20001)) { + //20001:红包活动正在进行,可拆 + const redPacketId1 = $.h5activityIndex.data.result.redpacketInfo.id; + if (redPacketId1) redPacketId.push(redPacketId1); + console.log(`\n\n当前待拆红包ID:${$.h5activityIndex.data.result.redpacketInfo.id},进度:再邀${$.h5activityIndex.data.result.redpacketConfigFillRewardInfo[$.hasSendNumber].requireAssistNum - $.h5activityIndex.data.result.redpacketConfigFillRewardInfo[$.hasSendNumber].hasAssistNum}个好友,开第${$.hasSendNumber + 1}个红包。当前已拆红包:${$.hasSendNumber}个,剩余${$.h5activityIndex.data.result.remainRedpacketNumber}个红包待开,已有${$.assistants}好友助力\n\n`) + console.log(`当前可拆红包个数:${$.waitOpenTimes}`) + message += "" +`当前可拆红包个数:${$.waitOpenTimes}` + " \n\n" + if ($.waitOpenTimes > 0) { + for (let i = 0; i < $.waitOpenTimes; i++) { + await h5receiveRedpacketAll(); + await $.wait(500); + } + } + } else if ($.h5activityIndex && $.h5activityIndex.data && $.h5activityIndex.data.biz_code === 20002) { + console.log(`\n${$.h5activityIndex.data.biz_msg}\n`); + } +} +//获取任务列表API +function taskHomePage() { + return new Promise((resolve) => { + $.post(taskUrl(arguments.callee.name.toString(), {"clientInfo":{}}), (err, resp, data) => { + try { + if (err) { + console.log(`\n${$.name}: API查询请求失败 ‼️‼️`); + console.log(JSON.stringify(err)); + } else { + $.taskHomePageData = JSON.parse(data); + } + } catch (e) { + $.logErr(e, resp); + } finally { + resolve(data); + } + }) + }) +} +//领取任务API,需token +function startTask(taskType) { + // 从taskHomePage返回的数据里面拿taskType + let data = {taskType}; + data['token'] = $.md5($.md5("j" + JSON.stringify(data) + "D")) + return new Promise((resolve) => { + $.post(taskUrl(arguments.callee.name.toString(), data), (err, resp, data) => { + try { + if (err) { + console.log(`\n${$.name}: API查询请求失败 ‼️‼️`); + console.log(JSON.stringify(err)); + } else { + console.log(`领取任务:${data}`) + data = JSON.parse(data); + } + } catch (e) { + $.logErr(e, resp); + } finally { + resolve(data); + } + }) + }) +} + +//做任务fun +async function active(taskType) { + const getTaskDetailForColorRes = await getTaskDetailForColor(taskType); + if (getTaskDetailForColorRes && getTaskDetailForColorRes.code === 0) { + if (getTaskDetailForColorRes.data && getTaskDetailForColorRes.data.result) { + const { advertDetails } = getTaskDetailForColorRes.data.result; + for (let item of advertDetails) { + await $.wait(1000); + if (item.id && item.status === 0) { + await taskReportForColor(taskType, item.id); + } + } + } else { + console.log(`任务列表为空,手动进入app内检查 是否存在[从京豆首页进领券中心逛30秒]的任务,如存在,请手动完成再运行脚本`) + $.msg(`${$.name}`, '', '手动进入app内检查\n是否存在[从京豆首页进领券中心逛30秒]的任务\n如存在,请手动完成再运行脚本'); + if ($.isNode()) await notify.sendNotify(`${$.name} - 账号${$.index} - ${$.nickName}`, `执行脚本出现异常\n请手动进入app内检查\n是否存在[从京豆首页进领券中心逛30秒]的任务\n如存在,请手动完成再运行脚本`) + } + } else { + console.log(`---具体任务详情---${JSON.stringify(getTaskDetailForColorRes)}`); + } +} + +//获取具体任务详情API +function getTaskDetailForColor(taskType) { + const data = {"clientInfo":{}, taskType}; + return new Promise((resolve) => { + $.post(taskUrl(arguments.callee.name.toString(), data), (err, resp, data) => { + try { + if (err) { + console.log(`\n${$.name}: API查询请求失败 ‼️‼️`); + console.log(JSON.stringify(err)); + } else { + // console.log('getTaskDetailForColor', data); + data = JSON.parse(data); + } + } catch (e) { + $.logErr(e, resp); + } finally { + resolve(data); + } + }) + }) +} +//做成任务API +function taskReportForColor(taskType, detailId) { + const data = {taskType, detailId}; + data['token'] = $.md5($.md5("j" + JSON.stringify(data) + "D")) + //console.log(`活动id:::${detailId}\n`) + return new Promise((resolve) => { + $.post(taskUrl(arguments.callee.name.toString(), data), (err, resp, data) => { + try { + if (err) { + console.log(`\n${$.name}: API查询请求失败 ‼️‼️`); + console.log(JSON.stringify(err)); + } else { + // console.log(`taskReportForColor`, data); + data = JSON.parse(data); + } + } catch (e) { + $.logErr(e, resp); + } finally { + resolve(data); + } + }) + }) +} +//领取做完任务后的红包 +function receiveTaskRedpacket(taskType) { + const body = {"clientInfo":{}, taskType}; + return new Promise((resolve) => { + $.post(taskUrl('h5receiveRedpacketAll', body), (err, resp, data) => { + try { + if (err) { + console.log(`\n${$.name}: API查询请求失败 ‼️‼️`); + console.log(JSON.stringify(err)); + } else { + data = JSON.parse(data); + if (data.data.success && data.data.biz_code === 0) { + console.log(`红包领取成功,获得${data.data.result.discount}元\n`) + message += "" +`红包领取成功,获得${data.data.result.discount}元\n`+ " \n\n" + $.discount += Number(data.data.result.discount); + } + } + } catch (e) { + $.logErr(e, resp); + } finally { + resolve(data); + } + }) + }) +} +//助力API +function jinli_h5assist(redPacketId) { + //一个人一天只能助力两次,助力码redPacketId 每天都变 + const body = {"clientInfo":{},redPacketId,"followShop":0,"promUserState":""}; + const options = taskUrl(arguments.callee.name.toString(), body) + return new Promise((resolve) => { + $.post(options, (err, resp, data) => { + try { + if (err) { + console.log(`\n${$.name}: API查询请求失败 ‼️‼️`); + console.log(JSON.stringify(err)); + } else { + data = JSON.parse(data); + if (data && data.data && data.data.biz_code === 0) { + // status ,0:助力成功,1:不能重复助力,3:助力次数耗尽,8:不能为自己助力 + console.log(`助力结果:${data.data.result.statusDesc}`) + if (data.data.result.status === 2) $.max = true; + if (data.data.result.status === 3) $.canHelp = false; + if (data.data.result.status === 9) $.canHelp = false; + } else { + console.log(`助力异常:${JSON.stringify(data)}`); + } + } + } catch (e) { + $.logErr(e, resp); + } finally { + resolve(); + } + }) + }) +} +//领取红包API +function h5receiveRedpacketAll() { + const options = taskUrl(arguments.callee.name.toString(), {"clientInfo":{}}) + return new Promise((resolve) => { + $.post(options, (err, resp, data) => { + try { + if (err) { + console.log(`\n${$.name}: API查询请求失败 ‼️‼️`); + console.log(JSON.stringify(err)); + } else { + data = JSON.parse(data); + if (data && data.data && data.data.biz_code === 0) { + message += "" +`拆红包获得:${data.data.result.discount}元`+ " \n\n" + console.log(`拆红包获得:${data.data.result.discount}元`) + } else { + console.log(`领红包失败:${JSON.stringify(data)}`) + } + } + } catch (e) { + $.logErr(e, resp); + } finally { + resolve(data); + } + }) + }) +} +//发起助力红包API +function h5launch() { + const body = {"clientInfo":{},"followShop":0,"promUserState":""}; + const options = taskUrl(arguments.callee.name.toString(), body) + return new Promise((resolve) => { + $.post(options, (err, resp, data) => { + try { + if (err) { + console.log(`\n${$.name}: API查询请求失败 ‼️‼️`); + console.log(JSON.stringify(err)); + } else { + data = JSON.parse(data); + if (data && data.data && data.data.biz_code === 0) { + if (data.data.result.redPacketId) { + console.log(`\n\n发起助力红包 成功:红包ID ${data.data.result.redPacketId}`) + redPacketId.push(data.data.result.redPacketId); + } else { + console.log(`\n\n发起助力红包 失败:${data.data.result.statusDesc}`) + } + } else { + console.log(`发起助力红包 失败:${JSON.stringify(data)}`) + } + } + } catch (e) { + $.logErr(e, resp); + } finally { + resolve(data); + } + }) + }) +} +function h5activityIndex() { + const body = {"clientInfo":{},"isjdapp":1}; + const options = taskUrl(arguments.callee.name.toString(), body); + return new Promise((resolve) => { + $.post(options, async (err, resp, data) => { + try { + if (err) { + console.log(`\n${$.name}: API查询请求失败 ‼️‼️`); + console.log(JSON.stringify(err)); + } else { + data = JSON.parse(data); + $.h5activityIndex = data; + $.discount = 0; + if ($.h5activityIndex && $.h5activityIndex.data && $.h5activityIndex.data.result) { + const rewards = $.h5activityIndex.data.result.rewards || []; + for (let item of rewards) { + $.discount += item.packetSum; + } + if ($.discount) $.discount = $.discount.toFixed(2); + } + } + } catch (e) { + $.logErr(e, resp); + } finally { + resolve(); + } + }) + }) +} +async function doAppTask(type = '1') { + let body = { + "pageClickKey": "CouponCenter", + "childActivityUrl": "openapp.jdmobile%3a%2f%2fvirtual%3fparams%3d%7b%5c%22category%5c%22%3a%5c%22jump%5c%22%2c%5c%22des%5c%22%3a%5c%22couponCenter%5c%22%7d", + "lat": "", + "globalLat": "", + "lng": "", + "globalLng": "" + } + await getCcTaskList('getCcTaskList', body, type); + body = { + "globalLng": "", + "globalLat": "", + "monitorSource": "ccgroup_ios_index_task", + "monitorRefer": "", + "taskType": "1", + "childActivityUrl": "openapp.jdmobile%3a%2f%2fvirtual%3fparams%3d%7b%5c%22category%5c%22%3a%5c%22jump%5c%22%2c%5c%22des%5c%22%3a%5c%22couponCenter%5c%22%7d", + "pageClickKey": "CouponCenter", + "lat": "", + "taskId": "727", + "lng": "", + } + await $.wait(10500); + await getCcTaskList('reportCcTask', body, type); +} +function getCcTaskList(functionId, body, type = '1') { + let url = ''; + return new Promise(resolve => { + if (functionId === 'getCcTaskList') { + url = `https://api.m.jd.com/client.action?functionId=${functionId}&body=${escape(JSON.stringify(body))}&uuid=8888888&client=apple&clientVersion=9.4.1&st=1617158358007&sign=a15f78e5846f9b0178dcabb1093a6a7f&sv=100` + } else if (functionId === 'reportCcTask') { + url = `https://api.m.jd.com/client.action?functionId=${functionId}&body=${escape(JSON.stringify(body))}&uuid=8888888&client=apple&clientVersion=9.4.1&st=1617158435079&sign=7eff07437dd817dbfa348c209fd5c129&sv=120` + } + const options = { + url, + body: `body=${escape(JSON.stringify(body))}`, + headers: { + "Accept": "application/json, text/plain, */*", + "Accept-Encoding": "gzip, deflate, br", + "Accept-Language": "zh-cn", + "Connection": "keep-alive", + "Content-Length": "63", + "Content-Type": "application/x-www-form-urlencoded", + "Host": "api.m.jd.com", + "Origin": "https://h5.m.jd.com", + "Cookie": cookie, + "Referer": "https://h5.m.jd.com/babelDiy/Zeus/4ZK4ZpvoSreRB92RRo8bpJAQNoTq/index.html", + "User-Agent": $.isNode() ? (process.env.JD_USER_AGENT ? process.env.JD_USER_AGENT : (require('./USER_AGENTS').USER_AGENT)) : ($.getdata('JDUA') ? $.getdata('JDUA') : "jdapp;iPhone;9.4.4;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"), + } + } + $.post(options, async (err, resp, data) => { + try { + if (err) { + console.log(`${JSON.stringify(err)}`) + console.log(`${$.name} API请求失败,请检查网路重试`) + } else { + if (data) { + // data = JSON.parse(data); + if (type === '1' && functionId === 'reportCcTask') console.log(`京东首页点击“领券”逛10s任务:${data}`) + } + } + } catch (e) { + $.logErr(e, resp) + } finally { + resolve(); + } + }) + }) +} +function getAuthorShareCode(url) { + return new Promise(resolve => { + const options = { + url: `${url}?${new Date()}`, "timeout": 10000, headers: { + "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 Edg/87.0.4280.88" + } + }; + if ($.isNode() && process.env.TG_PROXY_HOST && process.env.TG_PROXY_PORT) { + const tunnel = require("tunnel"); + const agent = { + https: tunnel.httpsOverHttp({ + proxy: { + host: process.env.TG_PROXY_HOST, + port: process.env.TG_PROXY_PORT * 1 + } + }) + } + Object.assign(options, { agent }) + } + $.get(options, async (err, resp, data) => { + try { + if (err) { + } else { + if (data) data = JSON.parse(data) + } + } catch (e) { + // $.logErr(e, resp) + } finally { + resolve(data); + } + }) + }) +} + +function taskUrl(functionId, body = {}) { + return { + url: `${JD_API_HOST}?appid=jinlihongbao&functionId=${functionId}&loginType=2&client=jinlihongbao&clientVersion=10.1.0&osVersion=iOS&d_brand=iPhone&d_model=iPhone&t=${new Date().getTime() * 1000}`, + body: `body=${escape(JSON.stringify(body))}`, + headers: { + "Host": "api.m.jd.com", + "Content-Type": "application/x-www-form-urlencoded", + "Origin": "https://happy.m.jd.com", + "Accept-Encoding": "gzip, deflate, br", + "Cookie": cookie, + "Connection": "keep-alive", + "Accept": "*/*", + "User-Agent": $.isNode() ? (process.env.JD_USER_AGENT ? process.env.JD_USER_AGENT : (require('./USER_AGENTS').USER_AGENT)) : ($.getdata('JDUA') ? $.getdata('JDUA') : "jdapp;iPhone;9.4.4;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"), + "Referer": "https://happy.m.jd.com/babelDiy/zjyw/3ugedFa7yA6NhxLN5gw2L3PF9sQC/index.html", + "Content-Length": "56", + "Accept-Language": "zh-cn" + } + } +} + +function TotalBean() { + return new Promise(async resolve => { + const options = { + url: "https://wq.jd.com/user_new/info/GetJDUserInfoUnion?sceneval=2", + headers: { + Host: "wq.jd.com", + Accept: "*/*", + Connection: "keep-alive", + Cookie: cookie, + "User-Agent": $.isNode() ? (process.env.JD_USER_AGENT ? process.env.JD_USER_AGENT : (require('./USER_AGENTS').USER_AGENT)) : ($.getdata('JDUA') ? $.getdata('JDUA') : "jdapp;iPhone;9.4.4;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"), + "Accept-Language": "zh-cn", + "Referer": "https://home.m.jd.com/myJd/newhome.action?sceneval=2&ufc=&", + "Accept-Encoding": "gzip, deflate, br" + } + } + $.get(options, (err, resp, data) => { + try { + if (err) { + $.logErr(err) + } else { + if (data) { + data = JSON.parse(data); + if (data['retcode'] === 1001) { + $.isLogin = false; //cookie过期 + return; + } + if (data['retcode'] === 0 && data.data && data.data.hasOwnProperty("userInfo")) { + $.nickName = data.data.userInfo.baseInfo.nickname; + } + } else { + console.log('京东服务器返回空数据'); + } + } + } catch (e) { + $.logErr(e) + } finally { + resolve(); + } + }) + }) +} + +function jsonParse(str) { + if (typeof str == "string") { + try { + return JSON.parse(str); + } catch (e) { + console.log(e); + $.msg($.name, '', '请勿随意在BoxJs输入框修改内容\n建议通过脚本去获取cookie') + return []; + } + } +} +// md5 +!function(n){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<>>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<>>9<<4)]=r;var e,i,a,d,h,l=1732584193,g=-271733879,v=-1732584194,m=271733878;for(e=0;e>5]>>>t%32&255)}return r}function d(n){var t,r=[];for(r[(n.length>>2)-1]=void 0,t=0;t>5]|=(255&n.charCodeAt(t/8))<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>>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)}$.md5=A}(this); +// 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)} \ No newline at end of file diff --git a/src/main/resources/test_shakeBean.js b/src/main/resources/test_shakeBean.js new file mode 100644 index 0000000..3177616 --- /dev/null +++ b/src/main/resources/test_shakeBean.js @@ -0,0 +1,1554 @@ +/* +* @Author: lxk0301 +* @Date: 2020-11-03 20:35:07 +* @Last Modified by: lxk0301 +* @Last Modified time: 2021-5-11 09:27:09 +*/ +/* +活动入口:京东APP首页-领京豆-摇京豆/京东APP首页-我的-京东会员-摇京豆 +增加京东APP首页超级摇一摇(不定时有活动) +增加超级品牌日做任务及抽奖 +增加 京东小魔方 抽奖 +Modified from https://github.com/Zero-S1/JD_tools/blob/master/JD_vvipclub.py +已支持IOS双京东账号,Node.js支持N个京东账号 +脚本兼容: QuantumultX, Surge, Loon, JSBox, Node.js +============QuantumultX============== +[task_local] +#摇京豆 +5 0,23 * * * https://gitee.com/lxk0301/jd_scripts/raw/master/jd_club_lottery.js, tag=摇京豆, img-url=https://raw.githubusercontent.com/58xinian/icon/master/jdyjd.png, enabled=true +=================Loon=============== +[Script] +cron "5 0,23 * * *" script-path=https://gitee.com/lxk0301/jd_scripts/raw/master/jd_club_lottery.js,tag=摇京豆 +=================Surge============== +[Script] +摇京豆 = type=cron,cronexp="5 0,23 * * *",wake-system=1,timeout=3600,script-path=https://gitee.com/lxk0301/jd_scripts/raw/master/jd_club_lottery.js + +============小火箭========= +摇京豆 = type=cron,script-path=https://gitee.com/lxk0301/jd_scripts/raw/master/jd_club_lottery.js, cronexpr="5 0,23 * * *", timeout=3600, enable=true +*/ + +const $ = new Env('摇京豆'); +const notify = $.isNode() ? require('./sendNotify') : ''; +//Node.js用户请在jdCookie.js处填写京东ck; +const jdCookieNode = $.isNode() ? require('./jdCookie.js') : ''; + +let roleMap = { + "jd_4521b375ebb5d": "锟子怪", + "jd_542c10c0222bc": "康子怪", + "jd_66dcb31363ef6": "涛子怪", + "jd_45d917547c763": "跑腿小怪", + "417040678_m": "斌子怪", + "jd_73d88459d908e": "杰杰子", + "381550701lol": "漪漪子", + "jd_4333d5dc1ac5f": "舒楠子", + "jd_66ea783827d30": "军子", + "jd_4311ac0ff4456": "居子" +} +let dingtalk = "https://oapi.dingtalk.com/robot/send?access_token=d2b6042cb38f0df63e20797c002208d2710104750c18a1dc84d54106a859a3f0" + + +//IOS等用户直接用NobyDa的jd cookie +let cookiesArr = [], cookie = '', message = '', allMessage = ''; +let assigFirends = []; +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); +} +let superShakeBeanConfig = { + "superShakeUlr": "",//超级摇一摇活动链接 + "superShakeBeanFlag": false, + "superShakeTitle": "", + "taskVipName": "", +} +$.brandActivityId = '';//超级品牌日活动ID +$.brandActivityId2 = '2vSNXCeVuBy8mXTL2hhG3mwSysoL';//超级品牌日活动ID2 +const JD_API_HOST = 'https://api.m.jd.com/client.action'; +!(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; + } + await welcomeHome() + if ($.superShakeUrl) { + await getActInfo($.superShakeUrl); + } + message += "[通知] 摇京豆 \n\n" + + 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; + $.freeTimes = 0; + $.prizeBeanCount = 0; + $.totalBeanCount = 0; + $.superShakeBeanNum = 0; + $.moFangBeanNum = 0; + $.isLogin = true; + $.nickName = ''; + await TotalBean(); + + if (roleMap[username] != undefined) { + username = roleMap[username] + } + //加上名称 + message = message + "【羊毛姐妹】" + username + " \n\n " + + + 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 clubLottery(); + // await showMsg(); + } + + message += "----\n\n" + } + postToDingTalk(message) + + message += "[通知] 摇京豆 \n\n" + + //开始助力 + for (let v = 0; v < cookiesArr.length; v++) { + cookie = cookiesArr[v]; + $.index = v + 1; + $.UserName = decodeURIComponent(cookie.match(/pt_pin=([^; ]+)(?=;?)/) && cookie.match(/pt_pin=([^; ]+)(?=;?)/)[1]); + $.canHelp = true; + if ($.canHelp && $.activityId) { + assigFirends = assigFirends.concat({ + "encryptAssignmentId": assigFirends[0] && assigFirends[0]['encryptAssignmentId'], + "assignmentType": 2, + "itemId": "SZm_olqSxIOtH97BATGmKoWraLaw", + }) + for (let item of assigFirends) { + if (item['encryptAssignmentId'] && item['assignmentType'] && item['itemId']) { + console.log(`\n账号 ${$.index} ${$.UserName} 开始给 ${item['itemId']} 进行助力`) + await superBrandDoTask({ + "activityId": $.activityId, + "encryptProjectId": $.encryptProjectId, + "encryptAssignmentId": item['encryptAssignmentId'], + "assignmentType": item['assignmentType'], + "itemId": item['itemId'], + "actionType": 0, + "source": "main" + }); + if (!$.canHelp) { + console.log(`次数已用完,跳出助力`) + break + } + } + } + //账号内部助力后,继续抽奖 + for (let i = 0; i < new Array(4).fill('').length; i++) { + await superBrandTaskLottery(); + await $.wait(400); + } + } + } + if (allMessage) { + if ($.isNode()) await notify.sendNotify($.name, allMessage); + } + if (superShakeBeanConfig.superShakeUlr) { + const scaleUl = { "category": "jump", "des": "m", "url": superShakeBeanConfig['superShakeUlr'] }; + const openjd = `openjd://virtual?params=${encodeURIComponent(JSON.stringify(scaleUl))}`; + $.msg($.name, '', `【${superShakeBeanConfig['superShakeTitle'] || '超级摇一摇'}】活动再次开启\n【${superShakeBeanConfig['taskVipName'] || '开通品牌会员'}】请点击弹窗直达活动页面\n${superShakeBeanConfig['superShakeUlr']}`, { 'open-url': openjd }); + if ($.isNode()) await notify.sendNotify($.name, `【${superShakeBeanConfig['superShakeTitle']}】活动再次开启\n【${superShakeBeanConfig['taskVipName'] || '开通品牌会员'}】请点击链接直达活动页面\n${superShakeBeanConfig['superShakeUlr']}`, { url: openjd }); + } +})() + .catch((e) => { + $.log('', `❌ ${$.name}, 失败! 原因: ${e}!`, '') + }) + .finally(() => { + postToDingTalk(message) + $.done(); + }) + +async function clubLottery() { + try { + await doTasks();//做任务 + await getFreeTimes();//获取摇奖次数 + await vvipclub_receive_lottery_times();//京东会员:领取一次免费的机会 + await vvipclub_shaking_info();//京东会员:查询多少次摇奖次数 + await shaking();//开始摇奖 + await shakeSign();//京东会员签到 + await superShakeBean();//京东APP首页超级摇一摇 + await superbrandShakeBean();//京东APP首页超级品牌日 + // await mofang();//小魔方 + } catch (e) { + $.logErr(e) + } +} +async function doTasks() { + const browseTaskRes = await getTask('browseTask'); + if (browseTaskRes.success) { + const { totalPrizeTimes, currentFinishTimes, taskItems } = browseTaskRes.data[0]; + const taskTime = totalPrizeTimes - currentFinishTimes; + if (taskTime > 0) { + let taskID = []; + taskItems.map(item => { + if (!item.finish) { + taskID.push(item.id); + } + }); + if (taskID.length > 0) console.log(`开始做浏览页面任务`) + for (let i = 0; i < new Array(taskTime).fill('').length; i++) { + await $.wait(1000); + await doTask('browseTask', taskID[i]); + } + } + } else { + console.log(`${JSON.stringify(browseTaskRes)}`) + } + const attentionTaskRes = await getTask('attentionTask'); + if (attentionTaskRes.success) { + const { totalPrizeTimes, currentFinishTimes, taskItems } = attentionTaskRes.data[0]; + const taskTime = totalPrizeTimes - currentFinishTimes; + if (taskTime > 0) { + let taskID = []; + taskItems.map(item => { + if (!item.finish) { + taskID.push(item.id); + } + }); + console.log(`开始做关注店铺任务`) + for (let i = 0; i < new Array(taskTime).fill('').length; i++) { + await $.wait(1000); + await doTask('attentionTask', taskID[i].toString()); + } + } + } +} +async function shaking() { + for (let i = 0; i < new Array($.leftShakingTimes).fill('').length; i++) { + console.log(`开始 【京东会员】 摇奖`) + await $.wait(1000); + const newShakeBeanRes = await vvipclub_shaking_lottery(); + if (newShakeBeanRes.success) { + console.log(`京东会员-剩余摇奖次数:${newShakeBeanRes.data.remainLotteryTimes}`) + if (newShakeBeanRes.data && newShakeBeanRes.data.rewardBeanAmount) { + $.prizeBeanCount += newShakeBeanRes.data.rewardBeanAmount; + console.log(`恭喜你,京东会员中奖了,获得${newShakeBeanRes.data.rewardBeanAmount}京豆\n`) + } else { + console.log(`未中奖\n`) + } + } + } + for (let i = 0; i < new Array($.freeTimes).fill('').length; i++) { + console.log(`开始 【摇京豆】 摇奖`) + await $.wait(1000); + const shakeBeanRes = await shakeBean(); + if (shakeBeanRes.success) { + console.log(`剩余摇奖次数:${shakeBeanRes.data.luckyBox.freeTimes}`) + if (shakeBeanRes.data && shakeBeanRes.data.prizeBean) { + console.log(`恭喜你,中奖了,获得${shakeBeanRes.data.prizeBean.count}京豆\n`) + $.prizeBeanCount += shakeBeanRes.data.prizeBean.count; + $.totalBeanCount = shakeBeanRes.data.luckyBox.totalBeanCount; + } else if (shakeBeanRes.data && shakeBeanRes.data.prizeCoupon) { + console.log(`获得优惠券:${shakeBeanRes.data.prizeCoupon['limitStr']}\n`) + } else { + console.log(`摇奖其他未知结果:${JSON.stringify(shakeBeanRes)}\n`) + } + } + } + if ($.prizeBeanCount > 0) message += `摇京豆:获得${$.prizeBeanCount}京豆`; +} +function showMsg() { + return new Promise(resolve => { + if (message) { + $.msg(`${$.name}`, `京东账号${$.index} ${$.nickName}`, message); + } + resolve(); + }) +} +//====================API接口================= +//查询剩余摇奖次数API +function vvipclub_shaking_info() { + return new Promise(resolve => { + const options = { + url: `https://api.m.jd.com/?t=${Date.now()}&appid=sharkBean&functionId=vvipclub_shaking_info`, + headers: { + "accept": "application/json", + "accept-encoding": "gzip, deflate, br", + "accept-language": "zh-CN,zh;q=0.9", + "cookie": cookie, + "origin": "https://skuivip.jd.com", + "referer": "https://skuivip.jd.com/", + "User-Agent": $.isNode() ? (process.env.JD_USER_AGENT ? process.env.JD_USER_AGENT : (require('./USER_AGENTS').USER_AGENT)) : ($.getdata('JDUA') ? $.getdata('JDUA') : "jdapp;iPhone;9.4.4;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") + } + } + $.get(options, (err, resp, data) => { + try { + if (err) { + console.log(`\n${$.name}: API查询请求失败 ‼️‼️`) + $.logErr(err); + } else { + // console.log(data) + data = JSON.parse(data); + if (data.success) { + $.leftShakingTimes = data.data.leftShakingTimes;//剩余抽奖次数 + console.log(`京东会员——摇奖次数${$.leftShakingTimes}`); + } + } + } catch (e) { + $.logErr(e, resp); + } finally { + resolve(data); + } + }) + }) +} +//京东会员摇奖API +function vvipclub_shaking_lottery() { + return new Promise(resolve => { + const options = { + url: `https://api.m.jd.com/?t=${Date.now()}&appid=sharkBean&functionId=vvipclub_shaking_lottery&body=%7B%7D`, + headers: { + "accept": "application/json", + "accept-encoding": "gzip, deflate, br", + "accept-language": "zh-CN,zh;q=0.9", + "cookie": cookie, + "origin": "https://skuivip.jd.com", + "referer": "https://skuivip.jd.com/", + "User-Agent": $.isNode() ? (process.env.JD_USER_AGENT ? process.env.JD_USER_AGENT : (require('./USER_AGENTS').USER_AGENT)) : ($.getdata('JDUA') ? $.getdata('JDUA') : "jdapp;iPhone;9.4.4;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") + } + } + $.get(options, (err, resp, data) => { + try { + if (err) { + console.log(`\n${$.name}: API查询请求失败 ‼️‼️`) + $.logErr(err); + } else { + // console.log(data) + data = JSON.parse(data); + } + } catch (e) { + $.logErr(e, resp); + } finally { + resolve(data); + } + }) + }) +} +//领取京东会员本摇一摇一次免费的次数 +function vvipclub_receive_lottery_times() { + return new Promise(resolve => { + const options = { + url: `https://api.m.jd.com/?t=${Date.now()}&appid=sharkBean&functionId=vvipclub_receive_lottery_times`, + headers: { + "accept": "application/json", + "accept-encoding": "gzip, deflate, br", + "accept-language": "zh-CN,zh;q=0.9", + "cookie": cookie, + "origin": "https://skuivip.jd.com", + "referer": "https://skuivip.jd.com/", + "User-Agent": $.isNode() ? (process.env.JD_USER_AGENT ? process.env.JD_USER_AGENT : (require('./USER_AGENTS').USER_AGENT)) : ($.getdata('JDUA') ? $.getdata('JDUA') : "jdapp;iPhone;9.4.4;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") + } + } + $.get(options, (err, resp, data) => { + try { + if (err) { + console.log(`\n${$.name}: API查询请求失败 ‼️‼️`) + $.logErr(err); + } else { + // console.log(data) + data = JSON.parse(data); + } + } catch (e) { + $.logErr(e, resp); + } finally { + resolve(data); + } + }) + }) +} +//查询多少次机会 +function getFreeTimes() { + return new Promise(resolve => { + $.get(taskUrl('vvipclub_luckyBox', { "info": "freeTimes" }), (err, resp, data) => { + try { + if (err) { + console.log(`\n${$.name}: API查询请求失败 ‼️‼️`) + $.logErr(err); + } else { + // console.log(data) + data = JSON.parse(data); + if (data.success) { + $.freeTimes = data.data.freeTimes; + console.log(`摇京豆——摇奖次数${$.freeTimes}`); + } + } + } catch (e) { + $.logErr(e, resp); + } finally { + resolve(); + } + }) + }) +} +function getTask(info) { + return new Promise(resolve => { + $.get(taskUrl('vvipclub_lotteryTask', { info, "withItem": true }), (err, resp, data) => { + try { + if (err) { + console.log(`\n${$.name}: API查询请求失败 ‼️‼️`) + $.logErr(err); + } else { + // console.log(data) + data = JSON.parse(data); + } + } catch (e) { + $.logErr(e, resp); + } finally { + resolve(data); + } + }) + }) +} +function doTask(taskName, taskItemId) { + return new Promise(resolve => { + $.get(taskUrl('vvipclub_doTask', { taskName, taskItemId }), (err, resp, data) => { + try { + if (err) { + console.log(`\n${$.name}: API查询请求失败 ‼️‼️`) + $.logErr(err); + } else { + // console.log(data) + data = JSON.parse(data); + } + } catch (e) { + $.logErr(e, resp); + } finally { + resolve(data); + } + }) + }) +} +function shakeBean() { + return new Promise(resolve => { + $.get(taskUrl('vvipclub_shaking', { "type": '0' }), (err, resp, data) => { + try { + if (err) { + console.log(`\n${$.name}: API查询请求失败 ‼️‼️`) + $.logErr(err); + } else { + // console.log(`摇奖结果:${data}`) + data = JSON.parse(data); + } + } catch (e) { + $.logErr(e, resp); + } finally { + resolve(data); + } + }) + }) +} +//新版超级本摇一摇 +async function superShakeBean() { + await superBrandMainPage(); + if ($.activityId && $.encryptProjectId) { + await superBrandTaskList(); + await superBrandDoTaskFun(); + await superBrandMainPage(); + await lo(); + } + if ($.ActInfo) { + await fc_getHomeData($.ActInfo);//获取任务列表 + await doShakeTask($.ActInfo);//做任务 + await fc_getHomeData($.ActInfo, true);//做完任务后查询多少次摇奖次数 + await superShakeLottery($.ActInfo);//开始摇奖 + } else { + console.log(`\n\n京东APP首页超级摇一摇:目前暂无活动\n\n`) + } +} +function welcomeHome() { + return new Promise(resolve => { + const data = { + "homeAreaCode": "", + "identity": "88732f840b77821b345bf07fd71f609e6ff12f43", + "fQueryStamp": "", + "globalUIStyle": "9.0.0", + "showCate": "1", + "tSTimes": "", + "geoLast": "", + "geo": "", + "cycFirstTimeStamp": "", + "displayVersion": "9.0.0", + "geoReal": "", + "controlMaterials": "", + "xviewGuideFloor": "index,category,find,cart,home", + "fringe": "", + "receiverGeo": "" + } + const options = { + url: `https://api.m.jd.com/client.action?functionId=welcomeHome`, + // url: `https://api.m.jd.com/client.action?functionId=welcomeHome&body=${escape(JSON.stringify(data))}&uuid=8888888&client=apple&clientVersion=9.4.1&st=1618538579097&sign=e29d09be25576be52ec22a3bb74d4f86&sv=100`, + // body: `body=${escape(JSON.stringify(data))}`, + body: `body=%7B%22homeAreaCode%22%3A%220%22%2C%22identity%22%3A%2288732f840b77821b345bf07fd71f609e6ff12f43%22%2C%22cycNum%22%3A1%2C%22fQueryStamp%22%3A%221619741900009%22%2C%22globalUIStyle%22%3A%229.0.0%22%2C%22showCate%22%3A%221%22%2C%22tSTimes%22%3A%220%22%2C%22geoLast%22%3A%22K3%252BcQaJxm9FzAm8%252BYHBwQKEMnguxItJAtNhFQOgUkktO5Vmidb%252BfKedLYq%252Fjlnc%252BK0ZsoA8jI8yXkYA6M2L5NYrGdBxZPbV%252FzT%252BU%252BHaCeNg%253D%22%2C%22geo%22%3A%22CZQirfKpZqpcvvBN0KadX76P55F3UdFoB2C3P0ZyHOXZWjeifB1aM0xH3BWx0YRlyu4eaUsfA3KpuoAraiffcw%253D%253D%22%2C%22cycFirstTimeStamp%22%3A%221619740961090%22%2C%22displayVersion%22%3A%229.0.0%22%2C%22geoReal%22%3A%22CZQirfKpZqpcvvBN0KadX76P55F3UdFoB2C3P0ZyHOXtnAGs7wzWHMkTSTIEj7qi%22%2C%22controlMaterials%22%3A%22null%22%2C%22xviewGuideFloor%22%3A%22index%2Ccategory%2Cfind%2Ccart%2Chome%22%2C%22fringe%22%3A%221%22%2C%22receiverGeo%22%3A%22mTBeEjk2Q83Kb3%252Fylt2Amm7iguwnhvKDgDnR18TktRpedJcPIHjALOIwGuNKAgau%22%7D&client=apple&clientVersion=9.4.6&d_brand=apple&isBackground=N&joycious=104&lang=zh_CN&networkType=4g&networklibtype=JDNetworkBaseAF&openudid=88732f840b77821b345bf07fd71f609e6ff12f43&osVersion=14.3&partner=apple&rfs=0000&scope=11&screen=828%2A1792&sign=69cc68677ae63b0a8737602766a0a340&st=1619741900013&sv=111&uts=0f31TVRjBSujckcdxhii7gq9cidRV4uxtCNZpaQs9IOuG5PD2oGme36aUnsUBSyCtrnCzcJjRQzsekOXnNu9XyW4W2UAsnnZ06POovikHhGabI9pwW8ZeJ2vmOBTWqWjA66DWDvRHGVeJeXzsm5xolz7r%2FX0APYfhg8I5QBwgKJfD3hzoXkHcnsGfMhHncRzuC4iOtgVG8L%2FnQyyNwXAJQ%3D%3D&uuid=hjudwgohxzVu96krv%2FT6Hg%3D%3D&wifiBssid=unknown`, + headers: { + "Accept": "*/*", + "Accept-Encoding": "gzip, deflate, br", + "Accept-Language": "zh-Hans-CN;q=1, zh-Hant-CN;q=0.9", + "Connection": "keep-alive", + "Content-Length": "1761", + "Content-Type": "application/x-www-form-urlencoded", + "Host": "api.m.jd.com", + "User-Agent": "JD4iPhone/167588 (iPhone; iOS 14.3; Scale/2.00)" + } + } + $.post(options, async (err, resp, data) => { + try { + if (err) { + console.log(`${JSON.stringify(err)}`) + console.log(`${$.name} welcomeHome API请求失败,请检查网路重试`) + } else { + if (data) { + data = JSON.parse(data); + if (data['floorList'] && data['floorList'].length) { + const shakeFloorNew = data['floorList'].filter(vo => !!vo && vo.type === 'shakeFloorNew')[0]; + const shakeFloorNew2 = data['floorList'].filter(vo => !!vo && vo.type === 'float')[0]; + // console.log('shakeFloorNew2', JSON.stringify(shakeFloorNew2)) + if (shakeFloorNew) { + const jump = shakeFloorNew['jump']; + if (jump && jump.params && jump['params']['url']) { + $.superShakeUrl = jump.params.url;//有活动链接,但活动可能已过期,需做进一步判断 + console.log(`【超级摇一摇】活动链接:${jump.params.url}`); + } + } + if (shakeFloorNew2) { + const jump = shakeFloorNew2['jump']; + if (jump && jump.params && jump['params']['url'].includes('https://h5.m.jd.com/babelDiy/Zeus/2PTXhrEmiMEL3mD419b8Gn9bUBiJ/index.html')) { + console.log(`【超级品牌日】活动链接:${jump.params.url}`); + $.superbrandUrl = jump.params.url; + } + } + } + } + } + } catch (e) { + $.logErr(e, resp); + } finally { + resolve(); + } + }) + }) +} +//=========老版本超级摇一摇================ +function getActInfo(url) { + return new Promise(resolve => { + $.get({ + url, + headers: { + // 'Cookie': cookie, + 'User-Agent': $.isNode() ? (process.env.JD_USER_AGENT ? process.env.JD_USER_AGENT : (require('./USER_AGENTS').USER_AGENT)) : ($.getdata('JDUA') ? $.getdata('JDUA') : "jdapp;iPhone;9.4.4;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"), + }, + timeout: 10000 + }, async (err, resp, data) => { + try { + if (err) { + console.log(`${JSON.stringify(err)}`) + console.log(`${$.name} API请求失败,请检查网路重试`) + } else { + data = data && data.match(/window\.__FACTORY__TAOYIYAO__STATIC_DATA__ = (.*)}/) + if (data) { + data = JSON.parse(data[1] + '}'); + if (data['pageConfig']) superShakeBeanConfig['superShakeTitle'] = data['pageConfig']['htmlTitle']; + if (data['taskConfig']) { + $.ActInfo = data['taskConfig']['taskAppId']; + console.log(`\n获取【${superShakeBeanConfig['superShakeTitle']}】活动ID成功:${$.ActInfo}\n`); + } + } + } + } catch (e) { + console.log(e) + } + finally { + resolve() + } + }) + }) +} +function fc_getHomeData(appId, flag = false) { + return new Promise(resolve => { + const body = { appId } + const options = taskPostUrl('fc_getHomeData', body) + $.taskVos = []; + $.lotteryNum = 0; + $.post(options, async (err, resp, data) => { + try { + if (err) { + console.log(`${JSON.stringify(err)}`) + console.log(`${$.name} fc_getHomeData API请求失败,请检查网路重试`) + } else { + if (data) { + data = JSON.parse(data); + if (data['code'] === 0) { + if (data['data']['bizCode'] === 0) { + const taskVos = data['data']['result']['taskVos'] || []; + if (flag && $.index === 1) { + superShakeBeanConfig['superShakeBeanFlag'] = true; + superShakeBeanConfig['taskVipName'] = taskVos.filter(vo => !!vo && vo['taskType'] === 21)[0]['taskName']; + } + superShakeBeanConfig['superShakeUlr'] = $.superShakeUrl; + $.taskVos = taskVos.filter(item => !!item && item['status'] === 1) || []; + $.lotteryNum = parseInt(data['data']['result']['lotteryNum']); + $.lotTaskId = parseInt(data['data']['result']['lotTaskId']); + } else if (data['data']['bizCode'] === 101) { + console.log(`京东APP首页超级摇一摇: ${data['data']['bizMsg']}`); + } + } else { + console.log(`获取超级摇一摇任务数据异常: ${JSON.stringify(data)}`) + } + } + } + } catch (e) { + $.logErr(e, resp); + } finally { + resolve(); + } + }) + }) +} +async function doShakeTask(appId) { + for (let vo of $.taskVos) { + if (vo['taskType'] === 21) { + console.log(`超级摇一摇 ${vo['taskName']} 跳过`); + continue + } + if (vo['taskType'] === 9) { + console.log(`开始做 ${vo['taskName']},等10秒`); + const shoppingActivityVos = vo['shoppingActivityVos']; + for (let task of shoppingActivityVos) { + await fc_collectScore({ + appId, + "taskToken": task['taskToken'], + "taskId": vo['taskId'], + "itemId": task['itemId'], + "actionType": 1 + }) + await $.wait(10000) + await fc_collectScore({ + appId, + "taskToken": task['taskToken'], + "taskId": vo['taskId'], + "itemId": task['itemId'], + "actionType": 0 + }) + } + } + if (vo['taskType'] === 1) { + console.log(`开始做 ${vo['taskName']}, 等8秒`); + const followShopVo = vo['followShopVo']; + for (let task of followShopVo) { + await fc_collectScore({ + appId, + "taskToken": task['taskToken'], + "taskId": vo['taskId'], + "itemId": task['itemId'], + "actionType": 1 + }) + await $.wait(9000) + await fc_collectScore({ + appId, + "taskToken": task['taskToken'], + "taskId": vo['taskId'], + "itemId": task['itemId'], + "actionType": 0 + }) + } + } + } +} +function fc_collectScore(body) { + return new Promise(resolve => { + const options = taskPostUrl('fc_collectScore', body) + $.post(options, (err, resp, data) => { + try { + if (err) { + console.log(`${JSON.stringify(err)}`) + console.log(`${$.name} fc_collectScore API请求失败,请检查网路重试`) + } else { + if (data) { + data = JSON.parse(data); + console.log(`${JSON.stringify(data)}`) + } + } + } catch (e) { + $.logErr(e, resp); + } finally { + resolve(); + } + }) + }) +} +async function superShakeLottery(appId) { + if ($.lotteryNum) console.log(`\n\n开始京东APP首页超级摇一摇 摇奖`); + for (let i = 0; i < new Array($.lotteryNum).fill('').length; i++) { + await fc_getLottery(appId);//抽奖 + await $.wait(1000) + } + if ($.superShakeBeanNum > 0) { + + message += "" + `${superShakeBeanConfig['superShakeTitle']}:获得${$.superShakeBeanNum}京豆` + " \n\n" + + allMessage += `京东账号${$.index}${$.nickName || $.UserName}\n${superShakeBeanConfig['superShakeTitle']}:获得${$.superShakeBeanNum}京豆${$.index !== cookiesArr.length ? '\n\n' : ''}`; + } +} +function fc_getLottery(appId) { + return new Promise(resolve => { + const body = { appId, "taskId": $.lotTaskId } + const options = taskPostUrl('fc_getLotteryResult', body) + $.post(options, (err, resp, data) => { + try { + if (err) { + console.log(`${JSON.stringify(err)}`) + console.log(`${$.name} fc_collectScore API请求失败,请检查网路重试`) + } else { + if (data) { + data = JSON.parse(data); + if (data && data['data']['bizCode'] === 0) { + $.myAwardVo = data['data']['result']['myAwardVo']; + if ($.myAwardVo) { + console.log(`超级摇一摇 抽奖结果:${JSON.stringify($.myAwardVo)}`) + if ($.myAwardVo['type'] === 2) { + $.superShakeBeanNum = $.superShakeBeanNum + parseInt($.myAwardVo['jBeanAwardVo']['quantity']); + } + } + } else { + console.log(`超级摇一摇 抽奖异常: ${JSON.stringify(data)}`) + } + } + } + } catch (e) { + $.logErr(e, resp); + } finally { + resolve(); + } + }) + }) +} +//===================新版超级本摇一摇============== +function superBrandMainPage() { + return new Promise(resolve => { + const body = { "source": "main" }; + const options = superShakePostUrl('superBrandMainPage', body) + $.post(options, (err, resp, data) => { + try { + if (err) { + console.log(`${JSON.stringify(err)}`) + console.log(`${$.name} superBrandTaskList API请求失败,请检查网路重试`) + } else { + if (data) { + data = JSON.parse(data); + if (data['code'] === '0') { + if (data['data']['bizCode'] === '0') { + //superShakeBeanConfig['superShakeUlr'] = jump.params.url; + //console.log(`【超级摇一摇】活动链接:${superShakeBeanConfig['superShakeUlr']}`); + superShakeBeanConfig['superShakeUlr'] = $.superShakeUrl; + $.activityId = data['data']['result']['activityBaseInfo']['activityId']; + $.encryptProjectId = data['data']['result']['activityBaseInfo']['encryptProjectId']; + $.activityName = data['data']['result']['activityBaseInfo']['activityName']; + $.userStarNum = Number(data['data']['result']['activityUserInfo']['userStarNum']) || 0; + superShakeBeanConfig['superShakeTitle'] = $.activityName; + console.log(`${$.activityName} 当前共有积分:${$.userStarNum},可抽奖:${parseInt($.userStarNum / 100)}次(最多4次摇奖机会)\n`); + } else { + console.log(`\n【新版本 超级摇一摇】获取信息失败:${data['data']['bizMsg']}\n`); + } + } else { + console.log(`获取超级摇一摇信息异常:${JSON.stringify(data)}\n`); + } + } + } + } catch (e) { + $.logErr(e, resp); + } finally { + resolve(); + } + }) + }) +} +function superBrandTaskList() { + return new Promise(resolve => { + $.taskList = []; + const body = { "activityId": $.activityId, "assistInfoFlag": 4, "source": "main" }; + const options = superShakePostUrl('superBrandTaskList', body) + $.post(options, (err, resp, data) => { + try { + if (err) { + console.log(`${JSON.stringify(err)}`) + console.log(`${$.name} superBrandTaskList API请求失败,请检查网路重试`) + } else { + if (data) { + // console.log(data); + data = JSON.parse(data); + if (data['code'] === '0' && data['data']['bizCode'] === '0') { + $.taskList = data['data']['result']['taskList']; + $.canLottery = $.taskList.filter(vo => !!vo && vo['assignmentTimesLimit'] === 4)[0]['completionFlag'] + } else { + console.log(`获取超级摇一摇任务异常:${JSON.stringify(data)}`); + } + } + } + } catch (e) { + $.logErr(e, resp); + } finally { + resolve(); + } + }) + }) +} +async function superBrandDoTaskFun() { + $.taskList = $.taskList.filter(vo => !!vo && !vo['completionFlag'] && (vo['assignmentType'] !== 6 && vo['assignmentType'] !== 7 && vo['assignmentType'] !== 0 && vo['assignmentType'] !== 30)); + for (let item of $.taskList) { + if (item['assignmentType'] === 1) { + const { ext } = item; + console.log(`开始做 ${item['assignmentName']},需等待${ext['waitDuration']}秒`); + const shoppingActivity = ext['shoppingActivity']; + for (let task of shoppingActivity) { + await superBrandDoTask({ + "activityId": $.activityId, + "encryptProjectId": $.encryptProjectId, + "encryptAssignmentId": item['encryptAssignmentId'], + "assignmentType": item['assignmentType'], + "itemId": task['itemId'], + "actionType": 1, + "source": "main" + }) + await $.wait(1000 * ext['waitDuration']) + await superBrandDoTask({ + "activityId": $.activityId, + "encryptProjectId": $.encryptProjectId, + "encryptAssignmentId": item['encryptAssignmentId'], + "assignmentType": item['assignmentType'], + "itemId": task['itemId'], + "actionType": 0, + "source": "main" + }) + } + } + if (item['assignmentType'] === 3) { + const { ext } = item; + console.log(`开始做 ${item['assignmentName']}`); + const followShop = ext['followShop']; + for (let task of followShop) { + await superBrandDoTask({ + "activityId": $.activityId, + "encryptProjectId": $.encryptProjectId, + "encryptAssignmentId": item['encryptAssignmentId'], + "assignmentType": item['assignmentType'], + "itemId": task['itemId'], + "actionType": 0, + "source": "main" + }) + } + } + if (item['assignmentType'] === 2) { + const { ext } = item; + const assistTaskDetail = ext['assistTaskDetail']; + console.log(`${item['assignmentName']}好友邀请码: ${assistTaskDetail['itemId']}`) + if (assistTaskDetail['itemId']) assigFirends.push({ + itemId: assistTaskDetail['itemId'], + encryptAssignmentId: item['encryptAssignmentId'], + assignmentType: item['assignmentType'], + }); + } + } +} +function superBrandDoTask(body) { + return new Promise(resolve => { + const options = superShakePostUrl('superBrandDoTask', body) + $.post(options, (err, resp, data) => { + try { + if (err) { + console.log(`${JSON.stringify(err)}`) + console.log(`${$.name} superBrandTaskList API请求失败,请检查网路重试`) + } else { + if (data) { + if (body['assignmentType'] === 2) { + console.log(`助力好友 ${body['itemId']}结果 ${data}`); + } else { + console.log('做任务结果', data); + } + data = JSON.parse(data); + if (data && data['code'] === '0' && data['data']['bizCode'] === '108') { + $.canHelp = false; + } + } + } + } catch (e) { + $.logErr(e, resp); + } finally { + resolve(); + } + }) + }) +} +async function lo() { + const num = parseInt(($.userStarNum || 0) / 100); + if (!$.canLottery) { + for (let i = 0; i < new Array(num).fill('').length; i++) { + await $.wait(1000); + await superBrandTaskLottery(); + } + } + if ($.superShakeBeanNum > 0) { + message += "" + `${$.activityName || '超级摇一摇'}:获得${$.superShakeBeanNum}京豆\n` + " \n\n" + allMessage += `京东账号${$.index}${$.nickName || $.UserName}\n${superShakeBeanConfig['superShakeTitle']}:获得${$.superShakeBeanNum}京豆${$.index !== cookiesArr.length ? '\n\n' : ''}`; + } +} +function superBrandTaskLottery() { + return new Promise(resolve => { + const body = { "activityId": $.activityId, "source": "main" } + const options = superShakePostUrl('superBrandTaskLottery', body) + $.post(options, (err, resp, data) => { + try { + if (err) { + console.log(`${JSON.stringify(err)}`) + console.log(`${$.name} superBrandDoTaskLottery API请求失败,请检查网路重试`) + } else { + if (data) { + data = JSON.parse(data); + if (data && data['code'] === '0') { + if (data['data']['bizCode'] === "TK000") { + $.rewardComponent = data['data']['result']['rewardComponent']; + if ($.rewardComponent) { + console.log(`超级摇一摇 抽奖结果:${JSON.stringify($.rewardComponent)}`) + if ($.rewardComponent.beanList && $.rewardComponent.beanList.length) { + console.log(`获得${$.rewardComponent.beanList[0]['quantity']}京豆`) + $.superShakeBeanNum += parseInt($.rewardComponent.beanList[0]['quantity']); + } + } + } else if (data['data']['bizCode'] === "TK1703") { + console.log(`超级摇一摇 抽奖失败:${data['data']['bizMsg']}`); + } else { + console.log(`超级摇一摇 抽奖失败:${data['data']['bizMsg']}`); + } + } else { + console.log(`超级摇一摇 抽奖异常: ${JSON.stringify(data)}`) + } + } + } + } catch (e) { + $.logErr(e, resp); + } finally { + resolve(); + } + }) + }) +} +//============超级品牌日============== +async function superbrandShakeBean() { + $.bradCanLottery = true;//是否有超级品牌日活动 + $.bradHasLottery = false;//是否已抽奖 + await qryCompositeMaterials("advertGroup", "04405074", "Brands");//获取品牌活动ID + await superbrand_getHomeData(); + if (!$.bradCanLottery) { + console.log(`【${$.stageName} 超级品牌日】:活动不在进行中`) + return + } + if ($.bradHasLottery) { + console.log(`【${$.stageName} 超级品牌日】:已完成抽奖`) + return + } + await superbrand_getMaterial();//获取完成任务所需的一些ID + await qryCompositeMaterials();//做任务 + await superbrand_getGift();//抽奖 +} +function superbrand_getMaterial() { + return new Promise(resolve => { + const body = { "brandActivityId": $.brandActivityId } + const options = superShakePostUrl('superbrand_getMaterial', body) + $.post(options, (err, resp, data) => { + try { + if (err) { + console.log(`${JSON.stringify(err)}`) + console.log(`${$.name} superbrand_getMaterial API请求失败,请检查网路重试`) + } else { + if (data) { + data = JSON.parse(data) + if (data['code'] === 0) { + if (data['data']['bizCode'] === 0) { + const { result } = data['data']; + $.cmsTaskShopId = result['cmsTaskShopId']; + $.cmsTaskLink = result['cmsTaskLink']; + $.cmsTaskGroupId = result['cmsTaskGroupId']; + console.log(`【cmsTaskGroupId】:${result['cmsTaskGroupId']}`) + } else { + console.log(`超级超级品牌日 ${data['data']['bizMsg']}`) + } + } else { + console.log(`超级超级品牌日 异常: ${JSON.stringify(data)}`) + } + } + } + } catch (e) { + $.logErr(e, resp); + } finally { + resolve(); + } + }) + }) +} +function qryCompositeMaterials(type = "productGroup", id = $.cmsTaskGroupId, mapTo = "Tasks0") { + return new Promise(resolve => { + const t1 = { type, id, mapTo } + const qryParam = JSON.stringify([t1]); + const body = { + qryParam, + "activityId": $.brandActivityId2, + "pageId": "1411763", + "reqSrc": "jmfe", + "geo": { "lng": "", "lat": "" } + } + const options = taskPostUrl('qryCompositeMaterials', body) + $.post(options, async (err, resp, data) => { + try { + if (err) { + console.log(`${JSON.stringify(err)}`) + console.log(`${$.name} qryCompositeMaterials API请求失败,请检查网路重试`) + } else { + if (data) { + data = JSON.parse(data); + if (data['code'] === '0') { + if (mapTo === 'Brands') { + $.stageName = data.data.Brands.stageName; + console.log(`\n\n【${$.stageName} brandActivityId】:${data.data.Brands.list[0].extension.copy1}`) + $.brandActivityId = data.data.Brands.list[0].extension.copy1 || $.brandActivityId; + } else { + const { list } = data['data']['Tasks0']; + console.log(`超级品牌日,做关注店铺 任务`) + let body = { "brandActivityId": $.brandActivityId, "taskType": "1", "taskId": $.cmsTaskShopId } + await superbrand_doMyTask(body); + console.log(`超级品牌日,逛品牌会场 任务`) + body = { "brandActivityId": $.brandActivityId, "taskType": "2", "taskId": $.cmsTaskLink } + await superbrand_doMyTask(body); + console.log(`超级品牌日,浏览下方指定商品 任务`) + for (let item of list.slice(0, 3)) { + body = { "brandActivityId": $.brandActivityId, "taskType": "3", "taskId": item['skuId'] }; + await superbrand_doMyTask(body); + } + } + } else { + console.log(`qryCompositeMaterials异常: ${JSON.stringify(data)}`) + } + } + } + } catch (e) { + $.logErr(e, resp); + } finally { + resolve(); + } + }) + }) +} +//做任务API +function superbrand_doMyTask(body) { + return new Promise(resolve => { + const options = superShakePostUrl('superbrand_doMyTask', body) + $.post(options, (err, resp, data) => { + try { + if (err) { + console.log(`${JSON.stringify(err)}`) + console.log(`${$.name} superbrand_doMyTask API请求失败,请检查网路重试`) + } else { + if (data) { + // data = JSON.parse(data) + console.log(`超级品牌日活动做任务结果:${data}\n`) + } + } + } catch (e) { + $.logErr(e, resp); + } finally { + resolve(); + } + }) + }) +} +function superbrand_getGift() { + return new Promise(resolve => { + const body = { "brandActivityId": $.brandActivityId } + const options = superShakePostUrl('superbrand_getGift', body) + $.post(options, (err, resp, data) => { + try { + if (err) { + console.log(`${JSON.stringify(err)}`) + console.log(`${$.name} superbrand_getGift API请求失败,请检查网路重试`) + } else { + if (data) { + data = JSON.parse(data) + if (data['code'] === 0) { + if (data['data']['bizCode'] === 0) { + const { result } = data['data']; + $.jpeasList = result['jpeasList']; + if ($.jpeasList && $.jpeasList.length) { + for (let item of $.jpeasList) { + console.log(`超级品牌日 抽奖 获得:${item['quantity']}京豆🐶`); + message += "" + `【超级品牌日】获得:${item['quantity']}京豆🐶\n` + " \n\n" + + if ($.superShakeBeanNum === 0) { + allMessage += `京东账号${$.index}${$.nickName || $.UserName}\n【超级品牌日】获得:${item['quantity']}京豆🐶\n`; + } else { + allMessage += `【超级品牌日】获得:${item['quantity']}京豆🐶\n`; + } + } + } + } else { + console.log(`超级超级品牌日 抽奖失败: ${data['data']['bizMsg']}`) + } + } else { + console.log(`超级超级品牌日 抽奖 异常: ${JSON.stringify(data)}`) + } + } + } + } catch (e) { + $.logErr(e, resp); + } finally { + resolve(); + } + }) + }) +} +function superbrand_getHomeData() { + return new Promise(resolve => { + const body = { "brandActivityIds": $.brandActivityId } + const options = superShakePostUrl('superbrand_getHomeData', body) + $.get(options, (err, resp, data) => { + try { + if (err) { + console.log(`${JSON.stringify(err)}`) + console.log(`${$.name} superbrand_getHomeData API请求失败,请检查网路重试`) + } else { + if (data) { + data = JSON.parse(data) + if (data['code'] === 0) { + if (data['data']['bizCode'] === 0) { + const { result } = data['data']; + if (result && result.length) { + if (result[0]['activityStatus'] === "2" && result[0]['taskVos'].length) $.bradHasLottery = true; + } + } else { + console.log(`超级超级品牌日 getHomeData 失败: ${data['data']['bizMsg']}`) + if (data['data']['bizCode'] === 101) { + $.bradCanLottery = false; + } + } + } else { + console.log(`超级超级品牌日 getHomeData 异常: ${JSON.stringify(data)}`) + } + } + } + } catch (e) { + $.logErr(e, resp); + } finally { + resolve(); + } + }) + }) +} +//=================京东小魔方================= +async function mofang() { + try { + await getInteractionInfo(); + await executeNewInteractionTaskFun(); + await getInteractionInfo(false); + for (let i = 0; i < new Array($.lotteryNum).fill('').length; i++) { + await getNewLotteryInfo(); + await $.wait(200); + } + if ($.moFangBeanNum > 0) { + message += "" + `京东小魔方:获得${$.moFangBeanNum}京豆\n` + " \n\n" + allMessage += `京东账号${$.index}${$.nickName || $.UserName}\n京东小魔方:获得${$.moFangBeanNum}京豆${$.index !== cookiesArr.length ? '\n\n' : ''}`; + } + } catch (e) { + $.logErr(e) + } +} +function getInteractionInfo(info = true) { + $.taskSkuInfo = []; + $.taskList = []; + $.shopInfoList = []; + $.lotteryNum = 0; + return new Promise(resolve => { + const body = {} + const options = superShakePostUrl('getInteractionInfo', body) + $.get(options, (err, resp, data) => { + try { + if (err) { + console.log(`${JSON.stringify(err)}`) + console.log(`${$.name} 小魔方 getInteractionInfo API请求失败,请检查网路重试`) + } else { + if (data) { + data = JSON.parse(data) + if (data['result'] && data['result']['code'] === 0) { + const { result } = data; + if (info) console.log(`\n\n京东小魔方:${result['brandName']}`) + $.taskSkuInfo = result['taskSkuInfo'] || []; + $.taskList = result['taskPoolInfo']['taskList'] || []; + $.taskPoolId = result['taskPoolInfo']['taskPoolId']; + $.taskSkuNum = result['taskSkuNum']; + $.interactionId = result['interactionId']; + $.shopInfoList = result['shopInfoList'] || []; + $.lotteryNum = result['lotteryInfo']['lotteryNum'] || 0; + if (!info) console.log(`京东小魔方当前抽奖次数:${$.lotteryNum}\n`) + } else { + console.log(`小魔方 getInteractionInfo 异常: ${JSON.stringify(data)}`) + } + } + } + } catch (e) { + $.logErr(e, resp); + } finally { + resolve(); + } + }) + }) +} +async function executeNewInteractionTaskFun() { + $.taskList = $.taskList.filter(vo => !!vo && vo['taskStatus'] === 0) + for (let item of $.taskList) { + if (item['taskId'] === 9) { + console.log(`开始做:【${item['taskTitle']}】任务`) + const body = { "interactionId": $.interactionId, "taskPoolId": $.taskPoolId, "taskType": item['taskId'] } + await executeNewInteractionTask(body); + } else if (item['taskId'] === 4) { + $.taskSkuInfo = $.taskSkuInfo.filter(vo => !!vo && vo['browseStatus'] === 0); + console.log(`开始做:【${item['taskTitle']}】任务`) + for (let v of $.taskSkuInfo) { + const body = { "sku": v['skuId'], "interactionId": $.interactionId, "taskPoolId": $.taskPoolId, "taskType": item['taskId'] }; + await executeNewInteractionTask(body); + await $.wait(100); + } + } else { + $.shopInfoList = $.shopInfoList.filter(vo => !!vo && vo['browseStatus'] === 0); + for (let v of $.shopInfoList) { + console.log(`开始做:【${item['taskTitle']}】任务,需等待${v['browseTime']}秒`); + let body = { + "shopId": v['shopId'], + "interactionId": $.interactionId, + "taskPoolId": $.taskPoolId, + "taskType": item['taskId'], + "action": 1 + }; + await executeNewInteractionTask(body); + await $.wait(v['browseTime'] * 1000); + body = { + "shopId": v['shopId'], + "interactionId": $.interactionId, + "taskPoolId": $.taskPoolId, + "taskType": item['taskId'] + }; + await executeNewInteractionTask(body); + } + } + } +} +function executeNewInteractionTask(body) { + return new Promise(resolve => { + const options = superShakePostUrl('executeNewInteractionTask', body) + $.get(options, (err, resp, data) => { + try { + if (err) { + console.log(`${JSON.stringify(err)}`) + console.log(`${$.name} 小魔方 executeNewInteractionTask API请求失败,请检查网路重试`) + } else { + if (data) { + data = JSON.parse(data) + if (data['result'] && data['result']['code'] === 0) { + const { result } = data; + if (result['toast'] && result['lotteryNum']) console.log(`${result['toast']},当前抽奖次数:${result['lotteryNum']}\n`); + } else { + console.log(`小魔方 executeNewInteractionTask 异常: ${JSON.stringify(data)}`) + } + } + } + } catch (e) { + $.logErr(e, resp); + } finally { + resolve(); + } + }) + }) +} +function getNewLotteryInfo() { + return new Promise(resolve => { + const body = { "interactionId": $.interactionId }; + const options = superShakePostUrl('getNewLotteryInfo', body) + $.get(options, (err, resp, data) => { + try { + if (err) { + console.log(`${JSON.stringify(err)}`) + console.log(`${$.name} 小魔方 getNewLotteryInfo API请求失败,请检查网路重试`) + } else { + if (data) { + data = JSON.parse(data) + if (data['result'] && data['result']['code'] === 0) { + const { result } = data; + if (result['isLottery'] === 0) { + console.log(`京东小魔方抽奖:${result['toast']}`); + } else if (result['isLottery'] === 1) { + console.log(`京东小魔方抽奖:${result['lotteryInfo']['quantity']}京豆`); + // allMessage += `【京东小魔方】获得:${result['lotteryInfo']['quantity']}京豆\n`; + $.moFangBeanNum += parseInt(result['lotteryInfo']['quantity']); + } else { + console.log(`京东小魔方抽奖:${JSON.stringify(data)}`); + } + } else { + console.log(`小魔方 getNewLotteryInfo 异常: ${JSON.stringify(data)}`) + } + } + } + } catch (e) { + $.logErr(e, resp); + } finally { + resolve(); + } + }) + }) +} +//=======================京东会员签到======================== +async function shakeSign() { + await pg_channel_page_data(); + if ($.token && $.currSignCursor && $.signStatus === -1) { + const body = { "floorToken": $.token, "dataSourceCode": "signIn", "argMap": { "currSignCursor": $.currSignCursor } }; + const signRes = await pg_interact_interface_invoke(body); + console.log(`京东会员第${$.currSignCursor}天签到结果;${JSON.stringify(signRes)}`) + let beanNum = 0; + if (signRes.success && signRes['data']) { + console.log(`京东会员第${$.currSignCursor}天签到成功。获得${signRes['data']['rewardVos'] && signRes['data']['rewardVos'][0]['jingBeanVo'] && signRes['data']['rewardVos'][0]['jingBeanVo']['beanNum']}京豆\n`) + beanNum = signRes['data']['rewardVos'] && signRes['data']['rewardVos'][0]['jingBeanVo'] && signRes['data']['rewardVos'][0]['jingBeanVo']['beanNum'] + } + if (beanNum) { + message += "" + `京东会员签到:获得${beanNum}京豆` + " \n\n" + + } + } else { + console.log(`京东会员第${$.currSignCursor}天已签到`) + } +} +function pg_channel_page_data() { + const body = { + "paramData": { "token": "dd2fb032-9fa3-493b-8cd0-0d57cd51812d" } + } + return new Promise(resolve => { + const options = { + url: `https://api.m.jd.com/?t=${Date.now()}&appid=sharkBean&functionId=pg_channel_page_data&body=${escape(JSON.stringify(body))}`, + headers: { + "Accept": "application/json", + "Accept-Encoding": "gzip, deflate, br", + "Accept-Language": "zh-cn", + "Connection": "keep-alive", + "Host": "api.m.jd.com", + "Cookie": cookie, + "Origin": "https://spa.jd.com", + "Referer": "https://spa.jd.com/home", + "User-Agent": $.isNode() ? (process.env.JD_USER_AGENT ? process.env.JD_USER_AGENT : (require('./USER_AGENTS').USER_AGENT)) : ($.getdata('JDUA') ? $.getdata('JDUA') : "jdapp;iPhone;9.4.4;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") + } + } + $.get(options, (err, resp, data) => { + try { + if (err) { + console.log(`\n${$.name}: API查询请求失败 ‼️‼️`) + $.logErr(err); + } else { + data = JSON.parse(data); + if (data.success) { + const SIGN_ACT_INFO = data['data']['floorInfoList'].filter(vo => !!vo && vo['code'] === 'SIGN_ACT_INFO')[0] + $.token = SIGN_ACT_INFO['token']; + if (SIGN_ACT_INFO['floorData']) { + $.currSignCursor = SIGN_ACT_INFO['floorData']['signActInfo']['currSignCursor']; + $.signStatus = SIGN_ACT_INFO['floorData']['signActInfo']['signActCycles'].filter(item => !!item && item['signCursor'] === $.currSignCursor)[0]['signStatus']; + } + // console.log($.token, $.currSignCursor, $.signStatus) + } + } + } catch (e) { + $.logErr(e, resp); + } finally { + resolve(data || {}); + } + }) + }) +} +function pg_interact_interface_invoke(body) { + return new Promise(resolve => { + const options = { + url: `https://api.m.jd.com/?appid=sharkBean&functionId=pg_interact_interface_invoke&body=${escape(JSON.stringify(body))}`, + headers: { + 'User-Agent': $.isNode() ? (process.env.JD_USER_AGENT ? process.env.JD_USER_AGENT : (require('./USER_AGENTS').USER_AGENT)) : ($.getdata('JDUA') ? $.getdata('JDUA') : "jdapp;iPhone;9.4.4;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"), + "Cookie": cookie, + "Accept": "application/json", + "Accept-Encoding": "gzip, deflate, br", + "Accept-Language": "zh-cn", + "Connection": "keep-alive", + "Content-Length": "0", + "Host": "api.m.jd.com", + "Origin": "https://spa.jd.com", + "Referer": "https://spa.jd.com/home" + } + } + $.post(options, (err, resp, data) => { + try { + if (err) { + console.log(`\n${$.name}: API查询请求失败 ‼️‼️`) + $.logErr(err); + } else { + data = JSON.parse(data); + } + } catch (e) { + $.logErr(e, resp); + } finally { + resolve(data || {}); + } + }) + }) +} + + +function TotalBean() { + return new Promise(async resolve => { + const options = { + url: "https://me-api.jd.com/user_new/info/GetJDUserInfoUnion", + headers: { + Host: "me-api.jd.com", + Accept: "*/*", + Connection: "keep-alive", + Cookie: cookie, + "User-Agent": $.isNode() ? (process.env.JD_USER_AGENT ? process.env.JD_USER_AGENT : (require('./USER_AGENTS').USER_AGENT)) : ($.getdata('JDUA') ? $.getdata('JDUA') : "jdapp;iPhone;9.4.4;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"), + "Accept-Language": "zh-cn", + "Referer": "https://home.m.jd.com/myJd/newhome.action?sceneval=2&ufc=&", + "Accept-Encoding": "gzip, deflate, br" + } + } + $.get(options, (err, resp, data) => { + try { + if (err) { + $.logErr(err) + } else { + if (data) { + data = JSON.parse(data); + if (data['retcode'] === "1001") { + $.isLogin = false; //cookie过期 + return; + } + if (data['retcode'] === "0" && data.data && data.data.hasOwnProperty("userInfo")) { + $.nickName = data.data.userInfo.baseInfo.nickname; + } + } else { + $.log('京东服务器返回空数据'); + } + } + } catch (e) { + $.logErr(e) + } finally { + resolve(); + } + }) + }) +} +function jsonParse(str) { + if (typeof str == "string") { + try { + return JSON.parse(str); + } catch (e) { + console.log(e); + $.msg($.name, '', '请勿随意在BoxJs输入框修改内容\n建议通过脚本去获取cookie') + return []; + } + } +} +function taskUrl(function_id, body = {}, appId = 'vip_h5') { + return { + url: `${JD_API_HOST}?functionId=${function_id}&appid=${appId}&body=${escape(JSON.stringify(body))}&_=${Date.now()}`, + headers: { + 'Cookie': cookie, + 'Host': 'api.m.jd.com', + 'User-Agent': $.isNode() ? (process.env.JD_USER_AGENT ? process.env.JD_USER_AGENT : (require('./USER_AGENTS').USER_AGENT)) : ($.getdata('JDUA') ? $.getdata('JDUA') : "jdapp;iPhone;9.4.4;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"), + 'Referer': 'https://vip.m.jd.com/newPage/reward/123dd/slideContent?page=focus', + } + } +} +function taskPostUrl(function_id, body) { + return { + url: `https://api.m.jd.com/client.action?functionId=${function_id}&body=${escape(JSON.stringify(body))}&client=wh5&clientVersion=1.0.0`, + headers: { + 'Cookie': cookie, + 'Host': 'api.m.jd.com', + 'User-Agent': $.isNode() ? (process.env.JD_USER_AGENT ? process.env.JD_USER_AGENT : (require('./USER_AGENTS').USER_AGENT)) : ($.getdata('JDUA') ? $.getdata('JDUA') : "jdapp;iPhone;9.4.4;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"), + 'Referer': 'https://h5.m.jd.com/babelDiy/Zeus/4SXuJSqKganGpDSEMEkJWyBrBHcM/index.html', + } + } +} +function superShakePostUrl(function_id, body) { + return { + url: `https://api.m.jd.com/client.action?functionId=${function_id}&appid=content_ecology&body=${escape(JSON.stringify(body))}&client=wh5&clientVersion=9.3.0&uuid=8888888&t=${Date.now()}`, + headers: { + 'Cookie': cookie, + 'Host': 'api.m.jd.com', + 'User-Agent': $.isNode() ? (process.env.JD_USER_AGENT ? process.env.JD_USER_AGENT : (require('./USER_AGENTS').USER_AGENT)) : ($.getdata('JDUA') ? $.getdata('JDUA') : "jdapp;iPhone;9.4.4;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"), + 'Referer': 'https://h5.m.jd.com/babelDiy/Zeus/4SXuJSqKganGpDSEMEkJWyBrBHcM/index.html', + } + } +} +// 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) } + + + + + +//我加的函数 +function postToDingTalk(messgae) { + const message1 = "" + messgae + // that.log(messgae) + + const body = { + "msgtype": "markdown", + "markdown": { + "title": "签到领现金", + "text": message1 + }, + "at": { + "atMobiles": [], + "isAtAll": false + } + } + + + $.post(toDingtalk(dingtalk, JSON.stringify(body)), (data, status, xhr) => { + try { + that.log(resp) + that.log(data) + if (err) { + that.log(JSON.stringify(err)); + $.logErr(err); + } else { + if (safeGet(data)) { + $.duckRes = JSON.parse(data); + } + } + } catch (e) { + $.logErr(e, resp) + } finally { + resolve(); + } + }, "json") +} + + +function toDingtalk(urlmain, bodyMain) { + return { + url: urlmain, + body: bodyMain, + headers: { 'Content-Type': 'application/json;charset=utf-8' }, + timeout: 10000, + } +} \ No newline at end of file