This commit is contained in:
Faker 2022-06-06 15:38:47 +08:00
parent 1c1a5c0cb9
commit 3f128ab339

View File

@ -1,12 +1,13 @@
/*
种豆得豆 脚本更新地址https://raw.githubusercontent.com/Aaron-lv/sync/jd_scripts/jd_plantBean.js
更新时间2021-04-9
更新时间2022-03-19
活动入口京东APP我的-更多工具-种豆得豆
已支持IOS京东多账号,云端多京东账号
脚本兼容: QuantumultX, Surge, Loon, JSBox, Node.js
会自动关注任务中的店铺跟商品介意者勿使用
互助码shareCode请先手动运行脚本查看打印可看到
每个京东账号每天只能帮助3个人多出的助力码将会助力失败
=====================================Quantumult X=================================
[task_local]
1 7-21/2 * * * https://raw.githubusercontent.com/Aaron-lv/sync/jd_scripts/jd_plantBean.js, tag=种豆得豆, img-url=https://raw.githubusercontent.com/58xinian/icon/master/jdzd.png, enabled=true
@ -22,7 +23,7 @@ cron "1 7-21/2 * * *" script-path=https://raw.githubusercontent.com/Aaron-lv/syn
京东种豆得豆 = type=cron,script-path=https://raw.githubusercontent.com/Aaron-lv/sync/jd_scripts/jd_plantBean.js, cronexpr="1 7-21/2 * * *", timeout=3600, enable=true
*/
const $ = new Env('京东种豆得豆');
const $ = new Env('种豆得豆互助版');
//Node.js用户请在jdCookie.js处填写京东ck;
//ios等软件用户直接用NobyDa的jd cookie
let jdNotify = true;//是否开启静默运行。默认true开启
@ -32,12 +33,7 @@ const JD_API_HOST = 'https://api.m.jd.com/client.action';
//助力好友分享码(最多3个,否则后面的助力失败)
//此此内容是IOS用户下载脚本到本地使用填写互助码的地方同一京东账号的好友互助码请使用@符号隔开。
//下面给出两个账号的填写示例iOS只支持2个京东账号
let shareCodes = [ // IOS本地脚本用户这个列表填入你要助力的好友的shareCode
//账号一的好友shareCode,不同好友的shareCode中间用@符号隔开
'lsvcdmfjrraodhrrvhcfiz7iye@o7eiltak46s2x3mao6ugdiywqv6t56rymtxfe4q@e7lhibzb3zek2zegsqjmjagw4c3zvnit3ipzuci@olmijoxgmjuty7323i6ijrv5tdhd32kefogty5i@gf2njfitdloxldekzam2flrji4@mq65ksgdrkobhiyvkoqfi7ff7i5ac3f4ijdgqji@wkmb7lejrmax2avk7bszvx7s74@4npkonnsy7xi3acvl3goi4ga5gpmpv2km4yj3di@rj7s6mzlk7uognpgua34bszhyf4cpqqtj5vfhta@olmijoxgmjutyif5p35uuja6gwp2ulsp2x6fjoi@dzfuhp3b2fz7mnj5ndxxqsradgg5bsrhuof2mbq',
//账号二的好友shareCode,不同好友的shareCode中间用@符号隔开
'lsvcdmfjrraodhrrvhcfiz7iye@o7eiltak46s2x3mao6ugdiywqv6t56rymtxfe4q@e7lhibzb3zek2zegsqjmjagw4c3zvnit3ipzuci@olmijoxgmjuty7323i6ijrv5tdhd32kefogty5i@gf2njfitdloxldekzam2flrji4@mq65ksgdrkobhiyvkoqfi7ff7i5ac3f4ijdgqji@wkmb7lejrmax2avk7bszvx7s74@4npkonnsy7xi3acvl3goi4ga5gpmpv2km4yj3di@rj7s6mzlk7uognpgua34bszhyf4cpqqtj5vfhta@olmijoxgmjutyif5p35uuja6gwp2ulsp2x6fjoi@dzfuhp3b2fz7mnj5ndxxqsradgg5bsrhuof2mbq',
]
let shareCodes = []
let allMessage = ``;
let currentRoundId = null;//本期活动id
let lastRoundId = null;//上期id
@ -45,23 +41,44 @@ let roundList = [];
let awardState = '';//上期活动的京豆是否收取
let randomCount = $.isNode() ? 20 : 5;
let num;
let llerror=false;
let llerrorhuobao=false;
$.newShareCode = [];
let NowHour = new Date().getHours();
let llhelp=true;
if ($.isNode() && process.env.CC_NOHELPAFTER8) {
if (process.env.CC_NOHELPAFTER8=="true"){
if (NowHour>8){
llhelp=false;
console.log(`现在是9点后时段不启用互助....`);
}
}
}
!(async () => {
await requireConfig();
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;
for (let k = 0; k < cookiesArr.length; k++) {
if (cookiesArr[k]) {
cookie = cookiesArr[k];
$.UserName = decodeURIComponent(cookie.match(/pt_pin=([^; ]+)(?=;?)/) && cookie.match(/pt_pin=([^; ]+)(?=;?)/)[1]);
$.index = k + 1;
$.isLogin = true;
llerror=false;
llerrorhuobao=false;
$.nickName = '';
await TotalBean();
console.log(`\n开始【京东账号${$.index}${$.nickName || $.UserName}\n`);
if (!$.isLogin) {
$.msg($.name, `【提示】cookie已失效`, `京东账号${$.index} ${$.nickName || $.UserName}\n请重新登录获取\nhttps://bean.m.jd.com/bean/signIndex.action`, {"open-url": "https://bean.m.jd.com/bean/signIndex.action"});
$.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`);
@ -71,9 +88,24 @@ let num;
message = '';
subTitle = '';
option = {};
await shareCodesFormat();
await jdPlantBean();
await showMsg();
if ($.isNode() && llerror && !llerrorhuobao) {
await notify.sendNotify(`${$.name}`, `京东账号${$.index} ${$.nickName || $.UserName}\n任务执行异常,请检查执行日志 ‼️‼️`);
}
}
}
if(llhelp){
console.log(`开始账号内互助`);
for (let j = 0; j < cookiesArr.length; j++) {
if (cookiesArr[j]) {
cookie = cookiesArr[j];
$.UserName = decodeURIComponent(cookie.match(/pt_pin=([^; ]+)(?=;?)/) && cookie.match(/pt_pin=([^; ]+)(?=;?)/)[1])
$.index = j + 1;
//await shareCodesFormat();
await doHelp()
}
}
}
if ($.isNode() && allMessage) {
@ -89,10 +121,7 @@ async function jdPlantBean() {
try {
console.log(`获取任务及基本信息`)
await plantBeanIndex();
if ($.plantBeanIndexResult.errorCode === 'PB101') {
console.log(`\n活动太火爆了,还是去买买买吧!\n`)
return
}
if (!llerror) {
for (let i = 0; i < $.plantBeanIndexResult.data.roundList.length; i++) {
if ($.plantBeanIndexResult.data.roundList[i].roundState === "2") {
num = i
@ -104,6 +133,8 @@ async function jdPlantBean() {
const shareUrl = $.plantBeanIndexResult.data.jwordShareInfo.shareUrl
$.myPlantUuid = getParam(shareUrl, 'plantUuid')
console.log(`\n【京东账号${$.index}${$.UserName})的${$.name}好友互助码】${$.myPlantUuid}\n`);
jdPlantBeanShareArr.push($.myPlantUuid)
roundList = $.plantBeanIndexResult.data.roundList;
currentRoundId = roundList[num].roundId; //本期的roundId
lastRoundId = roundList[num - 1].roundId; //上期的roundId
@ -113,17 +144,26 @@ async function jdPlantBean() {
message += `【上期时间】${roundList[num - 1].dateDesc.replace('上期 ', '')}\n`;
message += `【上期成长值】${roundList[num - 1].growth}\n`;
await receiveNutrients(); //定时领取营养液
await doHelp();//助力
await doTask(); //做日常任务
// await doEgg();
await stealFriendWater();
await doCultureBean();
await doGetReward();
await showTaskProcess();
await plantBeanIndex();
if (!llerror) {
$.taskList = $.plantBeanIndexResult.data.taskList;
if ($.taskList && $.taskList.length > 0) {
console.log(" 任务 进度");
for (let item of $.taskList) {
console.log(`[${item["taskName"]}] ${item["gainedNum"]}/${item["totalNum"]} ${item["isFinished"]}`);
}
}
}
await plantShareSupportList();
} else {
console.log(`种豆得豆-初始失败: ${JSON.stringify($.plantBeanIndexResult)}`);
}
}
} catch (e) {
$.logErr(e);
const errMsg = `京东账号${$.index} ${$.nickName || $.UserName}\n任务执行异常,请检查执行日志 ‼️‼️`;
@ -163,11 +203,13 @@ async function doGetReward() {
}
async function doCultureBean() {
await plantBeanIndex();
if (!llerror) {
if ($.plantBeanIndexResult && $.plantBeanIndexResult.code === '0') {
const plantBeanRound = $.plantBeanIndexResult.data.roundList[num]
const plantBeanRound = $.plantBeanIndexResult.data.roundList[num];
if (plantBeanRound.roundState === '2') {
//收取营养液
if (plantBeanRound.bubbleInfos && plantBeanRound.bubbleInfos.length) console.log(`开始收取营养液`)
if (plantBeanRound.bubbleInfos && plantBeanRound.bubbleInfos.length)
console.log(`开始收取营养液`)
for (let bubbleInfo of plantBeanRound.bubbleInfos) {
console.log(`收取-${bubbleInfo.name}-的营养液`)
await cultureBean(plantBeanRound.roundId, bubbleInfo.nutrientsType)
@ -178,6 +220,7 @@ async function doCultureBean() {
console.log(`plantBeanIndexResult:${JSON.stringify($.plantBeanIndexResult)}`)
}
}
}
async function stealFriendWater() {
await stealFriendList();
if ($.stealFriendList && $.stealFriendList.code === '0') {
@ -262,23 +305,22 @@ async function doTask() {
await shopTaskList();
const { data } = $.shopTaskListRes;
let goodShopListARR = [],moreShopListARR = [], shopList = [];
if (!data.goodShopList) {
data.goodShopList = [];
}
if (!data.moreShopList) {
data.moreShopList = [];
}
const { goodShopList, moreShopList } = data;
if (goodShopList) {
for (let i of goodShopList) {
if (i.taskState === '2') {
goodShopListARR.push(i);
}
}
}
if (moreShopList) {
for (let j of moreShopList) {
if (j.taskState === '2') {
moreShopListARR.push(j);
}
}
}
shopList = goodShopListARR.concat(moreShopListARR);
for (let shop of shopList) {
const { shopId, shopTaskId } = shop;
@ -389,29 +431,20 @@ async function doTask() {
}
}
}
function showTaskProcess() {
return new Promise(async resolve => {
await plantBeanIndex();
$.taskList = $.plantBeanIndexResult.data.taskList;
if ($.taskList && $.taskList.length > 0) {
console.log(" 任务 进度");
for (let item of $.taskList) {
console.log(`[${item["taskName"]}] ${item["gainedNum"]}/${item["totalNum"]} ${item["isFinished"]}`);
}
}
resolve()
})
}
//助力好友
async function doHelp() {
for (let plantUuid of newShareCodes) {
console.log(`开始助力京东账号${$.index} - ${$.nickName}的好友: ${plantUuid}`);
$.newShareCode = [...(jdPlantBeanShareArr || [])]
for (let plantUuid of $.newShareCode) {
console.log(`${$.UserName}开始助力: ${plantUuid}`);
if (!plantUuid) continue;
if (plantUuid === $.myPlantUuid) {
console.log(`\n跳过自己的plantUuid\n`)
continue
}
await helpShare(plantUuid);
console.log("========HELP=======");
if ($.helpResult && $.helpResult.code === '0' && !$.helpResult.errorCode) {
// console.log(`助力好友结果: ${JSON.stringify($.helpResult.data.helpShareRes)}`);
if ($.helpResult.data.helpShareRes) {
@ -543,58 +576,68 @@ async function helpShare(plantUuid) {
console.log(`助力结果的code:${$.helpResult && $.helpResult.code}`);
}
async function plantBeanIndex() {
llerror=false;
llerrorhuobao=false;
$.plantBeanIndexResult = await request('plantBeanIndex'); //plantBeanIndexBody
if ($.plantBeanIndexResult.errorCode === 'PB101') {
console.log(`\n活动太火爆了,还是去买买买吧!\n`)
llerror=true;
llerrorhuobao=true;
return
}
function readShareCode() {
return new Promise(async resolve => {
$.get({url: `http://transfer.nz.lu/bean`, timeout: 10000}, (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);
if ($.plantBeanIndexResult.errorCode) {
console.log(`获取任务及基本信息出错10秒后重试\n`)
await $.wait(10000);
$.plantBeanIndexResult = await request('plantBeanIndex');
if ($.plantBeanIndexResult.errorCode === 'PB101') {
console.log(`\n活动太火爆了,还是去买买买吧!\n`)
llerror=true;
llerrorhuobao=true;
return
}
}
} catch (e) {
$.logErr(e, resp)
} finally {
resolve(data);
if ($.plantBeanIndexResult.errorCode) {
console.log(`获取任务及基本信息出错30秒后重试\n`)
await $.wait(30000);
$.plantBeanIndexResult = await request('plantBeanIndex');
if ($.plantBeanIndexResult.errorCode === 'PB101') {
console.log(`\n活动太火爆了,还是去买买买吧!\n`)
llerror=true;
llerrorhuobao=true;
return
}
}
if ($.plantBeanIndexResult.errorCode) {
console.log(`获取任务及基本信息失败,活动异常,换个时间再试试吧....`)
console.log("错误代码;" + $.plantBeanIndexResult.errorCode)
llerror=true;
return;
}
})
await $.wait(15000);
resolve()
})
}
//格式化助力码
function shareCodesFormat() {
return new Promise(async resolve => {
// console.log(`第${$.index}个京东账号的助力码:::${$.shareCodesArr[$.index - 1]}`)
console.log(`${$.index}个京东账号的助力码:${$.shareCodesArr[$.index - 1]}`)
newShareCodes = [];
if ($.shareCodesArr[$.index - 1]) {
newShareCodes = $.shareCodesArr[$.index - 1].split('@');
} else {
console.log(`由于您第${$.index}个京东账号未提供shareCode,将采纳本脚本自带的助力码\n`)
// console.log(`由于您第${$.index}个京东账号未提供shareCode,将采纳本脚本自带的助力码\n`)
const tempIndex = $.index > shareCodes.length ? (shareCodes.length - 1) : ($.index - 1);
newShareCodes = shareCodes[tempIndex].split('@');
}
const readShareCodeRes = await readShareCode();
if (readShareCodeRes && readShareCodeRes.code === 200) {
newShareCodes = [...new Set([...newShareCodes, ...(readShareCodeRes.data || [])])];
}
console.log(`${$.index}个京东账号将要助力的好友${JSON.stringify(newShareCodes)}`)
resolve();
})
}
function requireConfig() {
return new Promise(resolve => {
console.log('开始获取种豆得豆配置文件\n')
//console.log('开始获取种豆得豆配置文件\n')
notify = $.isNode() ? require('./sendNotify') : '';
//Node.js用户请在jdCookie.js处填写京东ck;
const jdCookieNode = $.isNode() ? require('./jdCookie.js') : '';
const jdPlantBeanShareCodes = $.isNode() ? require('./jdPlantBeanShareCodes.js') : '';
const jdPlantBeanShareCodes = '';
//IOS等用户直接用NobyDa的jd cookie
if ($.isNode()) {
Object.keys(jdCookieNode).forEach((item) => {
@ -619,7 +662,7 @@ function requireConfig() {
console.log(`\nBoxJs设置的${$.name}好友邀请码:${$.getdata('jd_plantbean_inviter') ? $.getdata('jd_plantbean_inviter') : '暂无'}\n`);
}
// console.log(`\n种豆得豆助力码::${JSON.stringify($.shareCodesArr)}`);
console.log(`您提供了${$.shareCodesArr.length}个账号的种豆得豆助力码\n`);
//console.log(`您提供了${$.shareCodesArr.length}个账号的种豆得豆助力码\n`);
resolve()
})
}
@ -727,7 +770,7 @@ function request(function_id, body = {}){
})
}
function taskUrl(function_id, body) {
body["version"] = "9.2.4.0";
body["version"] = "9.2.4.1";
body["monitor_source"] = "plant_app_plant_index";
body["monitor_refer"] = "";
return {