Update jd_plantBean.js

This commit is contained in:
Shgdym 2022-10-12 21:33:10 +08:00 committed by GitHub
parent 9d7aba3e55
commit 05d6c88a65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -22,14 +22,17 @@ const $ = new Env('京东种豆得豆');
//Node.js用户请在jdCookie.js处填写京东ck; //Node.js用户请在jdCookie.js处填写京东ck;
//ios等软件用户直接用NobyDa的jd cookie //ios等软件用户直接用NobyDa的jd cookie
let jdNotify = true;//是否开启静默运行。默认true开启 let jdNotify = true;//是否开启静默运行。默认true开启
let cookiesArr = [], cookie = '', fullist = [], notify, newShareCodes, message,subTitle; let cookiesArr = [], cookie = '', fullist = [], jdPlantBeanShareArr = [], notify, newShareCodes, message,subTitle;
//京东接口地址 //京东接口地址
const JD_API_HOST = 'https://api.m.jd.com/client.action'; const JD_API_HOST = 'https://api.m.jd.com/client.action';
const JD_ZLC_URL = process.env.JD_ZLC_URL ? process.env.JD_ZLC_URL : "https://zlc1.chaoyi996.com";
//助力好友分享码(最多3个,否则后面的助力失败) //助力好友分享码(最多3个,否则后面的助力失败)
//此此内容是IOS用户下载脚本到本地使用填写互助码的地方同一京东账号的好友互助码请使用@符号隔开。 //此此内容是IOS用户下载脚本到本地使用填写互助码的地方同一京东账号的好友互助码请使用@符号隔开。
//下面给出两个账号的填写示例iOS只支持2个京东账号 //下面给出两个账号的填写示例iOS只支持2个京东账号
let shareCodes = [''] let shareCodes = ['']
let allMessage = ``; let allMessage = ``;
let codeType = 1;
let currentRoundId = null;//本期活动id let currentRoundId = null;//本期活动id
let lastRoundId = null;//上期id let lastRoundId = null;//上期id
let roundList = []; let roundList = [];
@ -74,7 +77,6 @@ if ($.isNode() && process.env.CC_NOHELPAFTER8) {
message = ''; message = '';
subTitle = ''; subTitle = '';
option = {}; option = {};
await shareCodesFormat();
await jdPlantBean(); await jdPlantBean();
await showMsg(); await showMsg();
} }
@ -108,6 +110,8 @@ async function jdPlantBean() {
const shareUrl = $.plantBeanIndexResult.data.jwordShareInfo.shareUrl const shareUrl = $.plantBeanIndexResult.data.jwordShareInfo.shareUrl
$.myPlantUuid = getParam(shareUrl, 'plantUuid') $.myPlantUuid = getParam(shareUrl, 'plantUuid')
console.log(`\n【京东账号${$.index}${$.UserName})的${$.name}好友互助码】${$.myPlantUuid}\n`); console.log(`\n【京东账号${$.index}${$.UserName})的${$.name}好友互助码】${$.myPlantUuid}\n`);
jdPlantBeanShareArr.push($.myPlantUuid)
roundList = $.plantBeanIndexResult.data.roundList; roundList = $.plantBeanIndexResult.data.roundList;
currentRoundId = roundList[num].roundId;//本期的roundId currentRoundId = roundList[num].roundId;//本期的roundId
lastRoundId = roundList[num - 1].roundId;//上期的roundId lastRoundId = roundList[num - 1].roundId;//上期的roundId
@ -123,9 +127,9 @@ async function jdPlantBean() {
await doCultureBean(); await doCultureBean();
await doGetReward(); await doGetReward();
await showTaskProcess(); await showTaskProcess();
if(llhelp){ await shareCodesFormat();
await doHelp() await doHelp()
}
await plantShareSupportList(); await plantShareSupportList();
} else { } else {
console.log(`种豆得豆-初始失败: ${JSON.stringify($.plantBeanIndexResult)}`); console.log(`种豆得豆-初始失败: ${JSON.stringify($.plantBeanIndexResult)}`);
@ -427,38 +431,86 @@ function showTaskProcess() {
} }
//助力好友 //助力好友
async function doHelp() { async function doHelp() {
helpStatisticArr = {}
helpStatisticArr['fromCode'] = $.myPlantUuid
helpStatisticArr['codeType'] = codeType;
helpStatisticArr['results'] = {};
helpStatisticRemark = ''
helpStatisticStatus = 2;
for (let plantUuid of newShareCodes) { for (let plantUuid of newShareCodes) {
console.log(`开始助力京东账号${$.index} - ${$.nickName}的好友: ${plantUuid}`); console.log(`开始助力京东账号${$.index} - ${$.nickName}的好友: ${plantUuid}`);
await $.wait(3000)
if (!plantUuid) continue; if (!plantUuid) continue;
if (plantUuid === $.myPlantUuid) { if (plantUuid === $.myPlantUuid) {
console.log(`\n跳过自己的plantUuid\n`) console.log(`\n跳过自己的plantUuid\n`)
continue continue
} }
await helpShare(plantUuid); await helpShare(plantUuid);
if ($.helpResult && $.helpResult.code === '0') { if ($.helpResult && $.helpResult.code === '0') {
// console.log(`助力好友结果: ${JSON.stringify($.helpResult.data.helpShareRes)}`); // console.log(`助力好友结果: ${JSON.stringify($.helpResult.data.helpShareRes)}`);
if ($.helpResult.data?.helpShareRes) { if ($.helpResult.data?.helpShareRes) {
if ($.helpResult.data.helpShareRes.state === '1') { if ($.helpResult.data.helpShareRes.state === '1') {
console.log(`助力好友${plantUuid}成功`) console.log(`助力好友${plantUuid}成功`)
helpStatisticStatus = 1;
console.log(`${$.helpResult.data.helpShareRes.promptText}\n`); console.log(`${$.helpResult.data.helpShareRes.promptText}\n`);
} else if ($.helpResult.data.helpShareRes.state === '2') { } else if ($.helpResult.data.helpShareRes.state === '2') {
console.log('您今日助力的机会已耗尽,已不能再帮助好友助力了\n'); console.log('您今日助力的机会已耗尽,已不能再帮助好友助力了\n');
helpStatisticStatus = 3;
if (!(helpStatisticStatus in helpStatisticArr['results'])) {
helpStatisticArr['results'][helpStatisticStatus] = [plantUuid]
} else {
helpStatisticArr['results'][helpStatisticStatus].push(plantUuid)
}
break; break;
} else if ($.helpResult.data.helpShareRes.state === '3') { } else if ($.helpResult.data.helpShareRes.state === '3') {
console.log('该好友今日已满9人助力,明天再来为Ta助力吧\n') helpStatisticStatus = 4;
//removeVal(newShareCodes,plantUuid) helpStatisticRemark += `fullremark${JSON.stringify($.helpResult.data.helpShareRes)}`
fullist.push(plantUuid); console.log('该好友今日已满9人助力/20瓶营养液,明天再来为Ta助力吧\n')
} else if ($.helpResult.data.helpShareRes.state === '4') { } else if ($.helpResult.data.helpShareRes.state === '4') {
helpStatisticStatus = 6;
helpStatisticRemark += $.helpResult.data.helpShareRes.promptText
console.log(`${$.helpResult.data.helpShareRes.promptText}\n`) console.log(`${$.helpResult.data.helpShareRes.promptText}\n`)
} else { } else {
helpStatisticStatus = 6;
helpStatisticRemark += `助力其他情况:${JSON.stringify($.helpResult.data.helpShareRes)}`
console.log(`助力其他情况:${JSON.stringify($.helpResult.data.helpShareRes)}`); console.log(`助力其他情况:${JSON.stringify($.helpResult.data.helpShareRes)}`);
} }
} }
} else { } else {
helpStatisticStatus = 2;
console.log(`助力好友失败: ${JSON.stringify($.helpResult)}`); console.log(`助力好友失败: ${JSON.stringify($.helpResult)}`);
} }
if (!(helpStatisticStatus in helpStatisticArr['results'])) {
helpStatisticArr['results'][helpStatisticStatus] = [plantUuid]
} else {
helpStatisticArr['results'][helpStatisticStatus].push(plantUuid)
}
await $.wait(2000) await $.wait(2000)
} }
helpStatisticArr['Remark'] = helpStatisticRemark;
r = { url: `https://zlc1.chaoyi996.com/api/app/booster-code/submit-real-contribution`, body: JSON.stringify(helpStatisticArr), headers: { "Content-Type": "application/json" } };
$.post(r, (err, resp, data) => {
try {
if (err) {
console.log(`${JSON.stringify(err)}`)
console.log(`${$.name} 提交助力结果API请求失败`)
} else {
if (data) {
console.log(`提交成功`)
data = JSON.parse(data);
}
}
} catch (e) {
$.logErr(e, resp)
}
})
} }
function showMsg() { function showMsg() {
$.log(`\n${message}\n`); $.log(`\n${message}\n`);
@ -699,16 +751,18 @@ async function helpShare(plantUuid) {
async function plantBeanIndex() { async function plantBeanIndex() {
$.plantBeanIndexResult = await request('plantBeanIndex');//plantBeanIndexBody $.plantBeanIndexResult = await request('plantBeanIndex');//plantBeanIndexBody
} }
function readShareCode() { function readShareCode(code) {
console.log(`当前使用助力池${JD_ZLC_URL}`)
console.log(JD_ZLC_URL + `/bean?code=` + code)
return new Promise(async resolve => { return new Promise(async resolve => {
$.get({url: `https://cdn.jsdelivr.net/gh/6dylan6/updateTeam@main/shareCodes/plant_bean.json`, timeout: 20000}, (err, resp, data) => { $.get({ url: JD_ZLC_URL + `/bean?code=` + code, timeout: 10000 }, (err, resp, data) => {
try { try {
if (err) { if (err) {
//console.log(`${JSON.stringify(err)}`) console.log(`${JSON.stringify(err)}`)
//console.log(`${$.name} API请求失败请检查网路重试`) console.log(`${$.name} API请求失败请检查网路重试`)
} else { } else {
if (data) { if (data) {
//console.log(`随机取码放到您固定的互助码后面(不影响已有固定互助)`) console.log(`随机取${randomCount}个码放到您固定的互助码后面`)
data = JSON.parse(data); data = JSON.parse(data);
} }
} }
@ -725,20 +779,14 @@ function readShareCode() {
//格式化助力码 //格式化助力码
function shareCodesFormat() { function shareCodesFormat() {
return new Promise(async resolve => { return new Promise(async resolve => {
// console.log(`第${$.index}个京东账号的助力码:::${$.shareCodesArr[$.index - 1]}`) console.log(`${$.index}个京东账号的助力码:::${jdPlantBeanShareArr[$.index - 1]}`)
newShareCodes = []; newShareCodes = [];
if ($.shareCodesArr[$.index - 1]) {
newShareCodes = $.shareCodesArr[$.index - 1].split('@');
} else { const readShareCodeRes = await readShareCode(jdPlantBeanShareArr[$.index - 1]);
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) { if (readShareCodeRes && readShareCodeRes.code === 200) {
newShareCodes = [...new Set([...newShareCodes, ...(readShareCodeRes.data || [])])]; newShareCodes = [...new Set([...newShareCodes, ...(readShareCodeRes.data || [])])];
} }
newShareCodes = newShareCodes.filter(item => {return fullist.indexOf(item) == -1});
console.log(`${$.index}个京东账号将要助力的好友${JSON.stringify(newShareCodes)}`) console.log(`${$.index}个京东账号将要助力的好友${JSON.stringify(newShareCodes)}`)
resolve(); resolve();
}) })