优化,减少由于京东数据异常导致脚本出错

This commit is contained in:
lxk0301
2021-03-30 09:12:56 +08:00
parent bb7633d7b5
commit 6c3ec191ec

View File

@@ -1,6 +1,6 @@
/* /*
种豆得豆 脚本更新地址https://gitee.com/lxk0301/jd_scripts/raw/master/jd_plantBean.js 种豆得豆 脚本更新地址https://gitee.com/lxk0301/jd_scripts/raw/master/jd_plantBean.js
更新时间2021-2-27 更新时间2021-3-30
活动入口京东APP我的-更多工具-种豆得豆 活动入口京东APP我的-更多工具-种豆得豆
已支持IOS京东双账号,云端N个京东账号 已支持IOS京东双账号,云端N个京东账号
脚本兼容: QuantumultX, Surge, Loon, JSBox, Node.js 脚本兼容: QuantumultX, Surge, Loon, JSBox, Node.js
@@ -90,7 +90,7 @@ async function jdPlantBean() {
console.log(`获取任务及基本信息`) console.log(`获取任务及基本信息`)
await plantBeanIndex(); await plantBeanIndex();
// console.log(plantBeanIndexResult.data.taskList); // console.log(plantBeanIndexResult.data.taskList);
if ($.plantBeanIndexResult.code === '0') { if ($.plantBeanIndexResult && $.plantBeanIndexResult.code === '0') {
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`);
@@ -130,7 +130,7 @@ async function doGetReward() {
//收获 //收获
await getReward(); await getReward();
console.log('开始领取京豆'); console.log('开始领取京豆');
if ($.getReward.code === '0') { if ($.getReward && $.getReward.code === '0') {
console.log('京豆领取成功'); console.log('京豆领取成功');
message += `【上期兑换京豆】${$.getReward.data.awardBean}\n`; message += `【上期兑换京豆】${$.getReward.data.awardBean}\n`;
$.msg($.name, subTitle, message); $.msg($.name, subTitle, message);
@@ -138,6 +138,8 @@ async function doGetReward() {
// if ($.isNode()) { // if ($.isNode()) {
// await notify.sendNotify(`${$.name} - 账号${$.index} - ${$.nickName || $.UserName}`, `京东账号${$.index} ${$.nickName}\n${message}`); // await notify.sendNotify(`${$.name} - 账号${$.index} - ${$.nickName || $.UserName}`, `京东账号${$.index} ${$.nickName}\n${message}`);
// } // }
} else {
console.log(`$.getReward 异常:${JSON.stringify($.getReward)}`)
} }
} else if (awardState === '6') { } else if (awardState === '6') {
//京豆已领取 //京豆已领取
@@ -151,7 +153,7 @@ async function doGetReward() {
} }
async function doCultureBean() { async function doCultureBean() {
await plantBeanIndex(); await plantBeanIndex();
if ($.plantBeanIndexResult.code === '0') { if ($.plantBeanIndexResult && $.plantBeanIndexResult.code === '0') {
const plantBeanRound = $.plantBeanIndexResult.data.roundList[1] const plantBeanRound = $.plantBeanIndexResult.data.roundList[1]
if (plantBeanRound.roundState === '2') { if (plantBeanRound.roundState === '2') {
//收取营养液 //收取营养液
@@ -168,7 +170,7 @@ async function doCultureBean() {
} }
async function stealFriendWater() { async function stealFriendWater() {
await stealFriendList(); await stealFriendList();
if ($.stealFriendList.code === '0') { if ($.stealFriendList && $.stealFriendList.code === '0') {
if ($.stealFriendList.data.tips) { if ($.stealFriendList.data.tips) {
console.log('偷取好友营养液今日已达上限'); console.log('偷取好友营养液今日已达上限');
return return
@@ -182,7 +184,7 @@ async function stealFriendWater() {
console.log(`可以偷的好友的信息paradiseUuid::${JSON.stringify(item.paradiseUuid)}`); console.log(`可以偷的好友的信息paradiseUuid::${JSON.stringify(item.paradiseUuid)}`);
await collectUserNutr(item.paradiseUuid); await collectUserNutr(item.paradiseUuid);
console.log(`偷取好友营养液情况:${JSON.stringify($.stealFriendRes)}`) console.log(`偷取好友营养液情况:${JSON.stringify($.stealFriendRes)}`)
if ($.stealFriendRes.code === '0') { if ($.stealFriendRes && $.stealFriendRes.code === '0') {
console.log(`偷取好友营养液成功`) console.log(`偷取好友营养液成功`)
} }
} }
@@ -192,18 +194,20 @@ async function stealFriendWater() {
console.log(`可以偷的好友的信息paradiseUuid::${JSON.stringify(item.paradiseUuid)}`); console.log(`可以偷的好友的信息paradiseUuid::${JSON.stringify(item.paradiseUuid)}`);
await collectUserNutr(item.paradiseUuid); await collectUserNutr(item.paradiseUuid);
console.log(`偷取好友营养液情况:${JSON.stringify($.stealFriendRes)}`) console.log(`偷取好友营养液情况:${JSON.stringify($.stealFriendRes)}`)
if ($.stealFriendRes.code === '0') { if ($.stealFriendRes && $.stealFriendRes.code === '0') {
console.log(`偷取好友营养液成功`) console.log(`偷取好友营养液成功`)
} }
} }
} }
} }
} }
} else {
console.log(`$.stealFriendList 异常: ${JSON.stringify($.stealFriendList)}`)
} }
} }
async function doEgg() { async function doEgg() {
await egg(); await egg();
if ($.plantEggLotteryRes.code === '0') { if ($.plantEggLotteryRes && $.plantEggLotteryRes.code === '0') {
if ($.plantEggLotteryRes.data.restLotteryNum > 0) { if ($.plantEggLotteryRes.data.restLotteryNum > 0) {
const eggL = new Array($.plantEggLotteryRes.data.restLotteryNum).fill(''); const eggL = new Array($.plantEggLotteryRes.data.restLotteryNum).fill('');
console.log(`目前共有${eggL.length}次扭蛋的机会`) console.log(`目前共有${eggL.length}次扭蛋的机会`)
@@ -216,7 +220,7 @@ async function doEgg() {
console.log('暂无扭蛋机会') console.log('暂无扭蛋机会')
} }
} else { } else {
console.log('查询天天扭蛋的机会失败') console.log('查询天天扭蛋的机会失败' + JSON.stringify($.plantEggLotteryRes))
} }
} }
async function doTask() { async function doTask() {
@@ -269,7 +273,7 @@ async function doTask() {
} }
const shopRes = await requestGet('shopNutrientsTask', body); const shopRes = await requestGet('shopNutrientsTask', body);
console.log(`shopRes结果:${JSON.stringify(shopRes)}`); console.log(`shopRes结果:${JSON.stringify(shopRes)}`);
if (shopRes.code === '0') { if (shopRes && shopRes.code === '0') {
if (shopRes.data && shopRes.data.nutrState && shopRes.data.nutrState === '1') { if (shopRes.data && shopRes.data.nutrState && shopRes.data.nutrState === '1') {
unFinishedShopNum --; unFinishedShopNum --;
} }
@@ -310,7 +314,7 @@ async function doTask() {
"skuId": skuId "skuId": skuId
} }
const productRes = await requestGet('productNutrientsTask', body); const productRes = await requestGet('productNutrientsTask', body);
if (productRes.code === '0') { if (productRes && productRes.code === '0') {
// console.log('nutrState', productRes) // console.log('nutrState', productRes)
//这里添加多重判断,有时候会出现活动太火爆的问题,导致nutrState没有 //这里添加多重判断,有时候会出现活动太火爆的问题,导致nutrState没有
if (productRes.data && productRes.data.nutrState && productRes.data.nutrState === '1') { if (productRes.data && productRes.data.nutrState && productRes.data.nutrState === '1') {
@@ -355,7 +359,7 @@ async function doTask() {
} }
const channelRes = await requestGet('plantChannelNutrientsTask', body); const channelRes = await requestGet('plantChannelNutrientsTask', body);
console.log(`channelRes结果:${JSON.stringify(channelRes)}`); console.log(`channelRes结果:${JSON.stringify(channelRes)}`);
if (channelRes.code === '0') { if (channelRes && channelRes.code === '0') {
if (channelRes.data && channelRes.data.nutrState && channelRes.data.nutrState === '1') { if (channelRes.data && channelRes.data.nutrState && channelRes.data.nutrState === '1') {
unFinishedChannelNum --; unFinishedChannelNum --;
} }
@@ -392,7 +396,7 @@ async function doHelp() {
continue continue
} }
await helpShare(plantUuid); await helpShare(plantUuid);
if ($.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') {