diff --git a/jd_fruit_Mod.js b/jd_fruit_Mod.js index 6084633..d9b8e17 100644 --- a/jd_fruit_Mod.js +++ b/jd_fruit_Mod.js @@ -39,8 +39,7 @@ const JD_API_HOST = 'https://api.m.jd.com/client.action'; const urlSchema = `openjd://virtual?params=%7B%20%22category%22:%20%22jump%22,%20%22des%22:%20%22m%22,%20%22url%22:%20%22https://h5.m.jd.com/babelDiy/Zeus/3KSjXqQabiTuD1cJ28QskrpWoBKT/index.html%22%20%7D`; let NowHour = new Date().getHours(); let llhelp=true; -if ($.isNode() && process.env.CC_NOHELPAFTER8) { - console.log(NowHour); +if ($.isNode() && process.env.CC_NOHELPAFTER8) { if (process.env.CC_NOHELPAFTER8=="true"){ if (NowHour>8){ llhelp=false; @@ -48,17 +47,38 @@ if ($.isNode() && process.env.CC_NOHELPAFTER8) { } } } +const fs = require('fs'); +let boolneedUpdate=false; +let strShare = './Fruit_ShareCache.json'; +let Fileexists = fs.existsSync(strShare); +let TempShareCache = []; +if (Fileexists) { + console.log("检测到东东农场缓存文件Fruit_ShareCache.json,载入..."); + TempShareCache = fs.readFileSync(strShare, 'utf-8'); + if (TempShareCache) { + TempShareCache = TempShareCache.toString(); + TempShareCache = JSON.parse(TempShareCache); + } +} + let WP_APP_TOKEN_ONE = ""; if ($.isNode()) { if (process.env.WP_APP_TOKEN_ONE) { WP_APP_TOKEN_ONE = process.env.WP_APP_TOKEN_ONE; } } -if(WP_APP_TOKEN_ONE) - console.log(`检测到已配置Wxpusher的Token,启用一对一推送...`); -else - console.log(`检测到未配置Wxpusher的Token,禁用一对一推送...`); - + +if (WP_APP_TOKEN_ONE) { + console.log(`检测到已配置Wxpusher的Token,启用一对一推送...`); + if (NowHour <9 || NowHour > 21) { + WP_APP_TOKEN_ONE = ""; + console.log(`农场只在9点后和22点前启用一对一推送,故此次暂时取消一对一推送...`); + } +} else + console.log(`检测到未配置Wxpusher的Token,禁用一对一推送...`); +let lnrun=0; +let llgetshare=false; +let NoNeedCodes = []; !(async () => { await requireConfig(); @@ -66,55 +86,87 @@ else $.msg($.name, '【提示】请先获取京东账号一cookie\n直接使用NobyDa的京东签到获取', 'https://bean.m.jd.com/bean/signIndex.action', { "open-url": "https://bean.m.jd.com/bean/signIndex.action" }); return; } - if(llhelp){ - console.log('开始收集您的互助码,用于账号内部互助,请稍等...'); - 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 (!$.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 (llhelp) { + console.log('开始收集您的互助码,用于账号内部互助,请稍等...'); + 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 (!$.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 - } - message = ''; - subTitle = ''; - option = {}; - $.retry = 0; - await GetCollect(); - } - } + if ($.isNode()) { + await notify.sendNotify(`${$.name}cookie已失效 - ${$.UserName}`, `京东账号${$.index} ${$.UserName}\n请重新登录获取cookie`); + } + continue + } + message = ''; + subTitle = ''; + option = {}; + $.retry = 0; + llgetshare=false; + await GetCollect(); + if(llgetshare){ + await $.wait(5000); + lnrun++; + } + if(lnrun==10){ + console.log(`访问接口次数达到10次,休息一分钟.....`); + await $.wait(60*1000); + lnrun=0; + } + } + } + if (boolneedUpdate) { + var str = JSON.stringify(TempShareCache, null, 2); + fs.writeFile(strShare, str, function (err) { + if (err) { + console.log(err); + console.log("缓存文件Fruit_ShareCache.json更新失败!"); + } else { + console.log("缓存文件Fruit_ShareCache.json更新成功!"); + } + }) + } } 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(); - 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 (cookiesArr[i]) { + cookie = cookiesArr[i]; + $.UserName = decodeURIComponent(cookie.match(/pt_pin=([^; ]+)(?=;?)/) && cookie.match(/pt_pin=([^; ]+)(?=;?)/)[1]) + $.index = i + 1; + $.isLogin = true; + $.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" + }); - if ($.isNode()) { - await notify.sendNotify(`${$.name}cookie已失效 - ${$.UserName}`, `京东账号${$.index} ${$.UserName}\n请重新登录获取cookie`); - } - continue + if ($.isNode()) { + await notify.sendNotify(`${$.name}cookie已失效 - ${$.UserName}`, `京东账号${$.index} ${$.UserName}\n请重新登录获取cookie`); + } + continue + } + message = ''; + subTitle = ''; + option = {}; + $.retry = 0; + + lnrun++; + await jdFruit(); + if (lnrun == 5) { + console.log(`访问接口次数达到5次,休息一分钟.....`); + await $.wait(60 * 1000); + lnrun = 0; + } } - message = ''; - subTitle = ''; - option = {}; - $.retry = 0; - await jdFruit(); - } } if ($.isNode() && allMessage && $.ctrTemp) { await notify.sendNotify(`${$.name}`, `${allMessage}`) @@ -293,56 +345,66 @@ async function predictionFruit() { } //浇水十次 async function doTenWater() { - jdFruitBeanCard = $.getdata('jdFruitBeanCard') ? $.getdata('jdFruitBeanCard') : jdFruitBeanCard; - if ($.isNode() && process.env.FRUIT_BEAN_CARD) { - jdFruitBeanCard = process.env.FRUIT_BEAN_CARD; - } - await myCardInfoForFarm(); - const { fastCard, doubleCard, beanCard, signCard } = $.myCardInfoRes; - if (`${jdFruitBeanCard}` === 'true' && JSON.stringify($.myCardInfoRes).match(`限时翻倍`) && beanCard > 0) { - console.log(`您设置的是使用水滴换豆卡,且背包有水滴换豆卡${beanCard}张, 跳过10次浇水任务`) - return - } - if ($.farmTask.totalWaterTaskInit.totalWaterTaskTimes < $.farmTask.totalWaterTaskInit.totalWaterTaskLimit) { - console.log(`\n准备浇水十次`); - let waterCount = 0; - isFruitFinished = false; - for (; waterCount < $.farmTask.totalWaterTaskInit.totalWaterTaskLimit - $.farmTask.totalWaterTaskInit.totalWaterTaskTimes; waterCount++) { - console.log(`第${waterCount + 1}次浇水`); - await waterGoodForFarm(); - console.log(`本次浇水结果: ${JSON.stringify($.waterResult)}`); - if ($.waterResult.code === '0') { - console.log(`剩余水滴${$.waterResult.totalEnergy}g`); - if ($.waterResult.finished) { - // 已证实,waterResult.finished为true,表示水果可以去领取兑换了 - isFruitFinished = true; - break - } else { - if ($.waterResult.totalEnergy < 10) { - console.log(`水滴不够,结束浇水`) - break - } - await gotStageAward();//领取阶段性水滴奖励 + try { + jdFruitBeanCard = $.getdata('jdFruitBeanCard') ? $.getdata('jdFruitBeanCard') : jdFruitBeanCard; + if ($.isNode() && process.env.FRUIT_BEAN_CARD) { + jdFruitBeanCard = process.env.FRUIT_BEAN_CARD; } - } else { - console.log('浇水出现失败异常,跳出不在继续浇水') - break; - } + await myCardInfoForFarm(); + const { + fastCard, + doubleCard, + beanCard, + signCard + } = $.myCardInfoRes; + /* if (`${jdFruitBeanCard}` === 'true' && JSON.stringify($.myCardInfoRes).match(`限时翻倍`) && beanCard > 0) { + console.log(`您设置的是使用水滴换豆卡,且背包有水滴换豆卡${beanCard}张, 跳过10次浇水任务`) + return + } */ + if ($.farmTask.totalWaterTaskInit.totalWaterTaskTimes < $.farmTask.totalWaterTaskInit.totalWaterTaskLimit) { + console.log(`\n准备浇水十次`); + let waterCount = 0; + isFruitFinished = false; + for (; waterCount < $.farmTask.totalWaterTaskInit.totalWaterTaskLimit - $.farmTask.totalWaterTaskInit.totalWaterTaskTimes; waterCount++) { + console.log(`第${waterCount + 1}次浇水`); + await waterGoodForFarm(); + console.log(`本次浇水结果: ${JSON.stringify($.waterResult)}`); + if ($.waterResult.code === '0') { + console.log(`剩余水滴${$.waterResult.totalEnergy}g`); + if ($.waterResult.finished) { + // 已证实,waterResult.finished为true,表示水果可以去领取兑换了 + isFruitFinished = true; + break + } else { + if ($.waterResult.totalEnergy < 10) { + console.log(`水滴不够,结束浇水`) + break + } + await gotStageAward(); //领取阶段性水滴奖励 + } + } else { + console.log('浇水出现失败异常,跳出不在继续浇水') + break; + } + } + if (isFruitFinished) { + option['open-url'] = urlSchema; + $.msg($.name, ``, `【京东账号${$.index}】${$.nickName || $.UserName}\n【提醒⏰】${$.farmInfo.farmUserPro.name}已可领取\n请去京东APP或微信小程序查看\n点击弹窗即达`, option); + $.done(); + if ($.isNode()) { + await notify.sendNotify(`${$.name} - 账号${$.index} - ${$.nickName || $.UserName}水果已可领取`, `京东账号${$.index} ${$.nickName || $.UserName}\n${$.farmInfo.farmUserPro.name}已可领取`); + } + if ($.isNode() && WP_APP_TOKEN_ONE) { + await notify.sendNotifybyWxPucher($.name, `【提醒⏰】${$.farmInfo.farmUserPro.name}已可领取\n【领取步骤】京东->我的->东东农场兑换京东红包,可以用于京东app的任意商品.`, `${$.UserName}`); + } + } + } else { + console.log('\n今日已完成10次浇水任务\n'); + } + } catch (e) { + console.log(`doTenWater 任务执行异常‼️‼️`); + $.logErr(e); } - if (isFruitFinished) { - option['open-url'] = urlSchema; - $.msg($.name, ``, `【京东账号${$.index}】${$.nickName || $.UserName}\n【提醒⏰】${$.farmInfo.farmUserPro.name}已可领取\n请去京东APP或微信小程序查看\n点击弹窗即达`, option); - $.done(); - if ($.isNode()) { - await notify.sendNotify(`${$.name} - 账号${$.index} - ${$.nickName || $.UserName}水果已可领取`, `京东账号${$.index} ${$.nickName || $.UserName}\n${$.farmInfo.farmUserPro.name}已可领取`); - } - if ($.isNode() && WP_APP_TOKEN_ONE) { - await notify.sendNotifybyWxPucher($.name, `【提醒⏰】${$.farmInfo.farmUserPro.name}已可领取\n【领取步骤】京东->我的->东东农场兑换京东红包,可以用于京东app的任意商品.`, `${$.UserName}`); - } - } - } else { - console.log('\n今日已完成10次浇水任务\n'); - } } //领取首次浇水奖励 async function getFirstWaterAward() { @@ -412,17 +474,22 @@ async function doTenWaterAgain() { } if (`${jdFruitBeanCard}` === 'true' && JSON.stringify($.myCardInfoRes).match('限时翻倍')) { console.log(`\n您设置的是水滴换豆功能,现在为您换豆`); - if (totalEnergy >= 100 && $.myCardInfoRes.beanCard > 0) { - //使用水滴换豆卡 - await userMyCardForFarm('beanCard'); - console.log(`使用水滴换豆卡结果:${JSON.stringify($.userMyCardRes)}`); - if ($.userMyCardRes.code === '0') { - message += `【水滴换豆卡】获得${$.userMyCardRes.beanCount}个京豆\n`; - return - } - } else { - console.log(`您目前水滴:${totalEnergy}g,水滴换豆卡${$.myCardInfoRes.beanCard}张,暂不满足水滴换豆的条件,为您继续浇水`) - } + + for (let lncount = 0; lncount < $.myCardInfoRes.beanCard; lncount++) { + if (totalEnergy >= 150 && $.myCardInfoRes.beanCard > 0) { + //使用水滴换豆卡 + await userMyCardForFarm('beanCard'); + console.log(`使用水滴换豆卡结果:${JSON.stringify($.userMyCardRes)}`); + if ($.userMyCardRes.code === '0') { + totalEnergy=totalEnergy-100; + message += `【水滴换豆卡】获得${$.userMyCardRes.beanCount}个京豆\n`; + } + } else { + console.log(`您目前水滴:${totalEnergy}g,水滴换豆卡${$.myCardInfoRes.beanCard}张,暂不满足水滴换豆的条件,为您继续浇水`) + break; + } + } + return; } // if (totalEnergy > 100 && $.myCardInfoRes.fastCard > 0) { // //使用快速浇水卡 @@ -716,6 +783,19 @@ async function masterHelpShare() { if(llhelp){ console.log('开始助力好友') for (let code of newShareCodes) { + if(NoNeedCodes){ + var llnoneed=false; + for (let NoNeedCode of NoNeedCodes) { + if (code==NoNeedCode){ + llnoneed=true; + break; + } + } + if(llnoneed){ + console.log(`${code}助力已满,跳过...`); + continue; + } + } console.log(`${$.UserName}开始助力: ${code}`); if (!code) continue; if (!$.farmInfo.farmUserPro) { @@ -739,6 +819,7 @@ async function masterHelpShare() { } else if ($.helpResult.helpResult.code === '9') { console.log(`【助力好友结果】: 之前给【${$.helpResult.helpResult.masterUserInfo.nickName}】助力过了`); } else if ($.helpResult.helpResult.code === '10') { + NoNeedCodes.push(code); console.log(`【助力好友结果】: 好友【${$.helpResult.helpResult.masterUserInfo.nickName}】已满五人助力`); } else { console.log(`助力其他情况:${JSON.stringify($.helpResult.helpResult)}`); @@ -789,7 +870,7 @@ async function executeWaterRains() { if (Date.now() < ($.farmTask.waterRainInit.lastTime + 3 * 60 * 60 * 1000)) { executeWaterRain = false; // message += `【第${$.farmTask.waterRainInit.winTimes + 1}次水滴雨】未到时间,请${new Date($.farmTask.waterRainInit.lastTime + 3 * 60 * 60 * 1000).toLocaleTimeString()}再试\n`; - console.log(`\`【第${$.farmTask.waterRainInit.winTimes + 1}次水滴雨】未到时间,请${new Date($.farmTask.waterRainInit.lastTime + 3 * 60 * 60 * 1000).toLocaleTimeString()}再试\n`); + console.log(`【第${$.farmTask.waterRainInit.winTimes + 1}次水滴雨】未到时间,请${new Date($.farmTask.waterRainInit.lastTime + 3 * 60 * 60 * 1000).toLocaleTimeString()}再试\n`); } } if (executeWaterRain) { @@ -1032,18 +1113,44 @@ async function duck() { } } async function GetCollect() { - try { - await initForFarm(); - if ($.farmInfo.farmUserPro) { - console.log(`\n【京东账号${$.index}(${$.UserName})的${$.name}好友互助码】${$.farmInfo.farmUserPro.shareCode}`); - newShareCodes.push($.farmInfo.farmUserPro.shareCode) - } else { - console.log(`\n【京东账号${$.index}(${$.UserName})的${$.name}好友互助码】\n数据异常,使用ccwav的互助码:f910ae66879a422daeb32f9250fc5e2e`); - newShareCodes.push("f910ae66879a422daeb32f9250fc5e2e"); + try { + console.log(`\n【京东账号${$.index}(${$.UserName})的${$.name}好友互助码】`); + var llfound = false; + var strShareCode = ""; + if (TempShareCache) { + for (let j = 0; j < TempShareCache.length; j++) { + if (TempShareCache[j].pt_pin == $.UserName) { + llfound = true; + strShareCode = TempShareCache[j].ShareCode; + } + } + } + if (!llfound) { + console.log($.UserName + "该账号无缓存,尝试联网获取互助码....."); + llgetshare=true; + await initForFarm(); + if ($.farmInfo.farmUserPro) { + var tempAddCK = {}; + strShareCode=$.farmInfo.farmUserPro.shareCode; + tempAddCK = { + "pt_pin": $.UserName, + "ShareCode": strShareCode + }; + TempShareCache.push(tempAddCK); + //标识,需要更新缓存文件 + boolneedUpdate = true; + } + } + + if (strShareCode) { + console.log(`\n`+strShareCode); + newShareCodes.push(strShareCode) + } else { + console.log(`\n数据异常`); + } + } catch (e) { + $.logErr(e); } - } catch (e) { - $.logErr(e); - } } // ========================API调用接口======================== //鸭子,点我有惊喜 @@ -1053,7 +1160,7 @@ async function getFullCollectionReward() { $.post(taskUrl("getFullCollectionReward", body), (err, resp, data) => { try { if (err) { - console.log('\n东东农场: API查询请求失败 ‼️‼️'); + console.log('\ngetFullCollectionReward: API查询请求失败 ‼️‼️'); console.log(JSON.stringify(err)); $.logErr(err); } else { @@ -1107,8 +1214,8 @@ async function gotStageAwardForFarm(type) { } //浇水API async function waterGoodForFarm() { - await $.wait(1000); - console.log('等待了1秒'); + await $.wait(2000); + console.log('等待了2秒'); const functionId = arguments.callee.name.toString(); $.waterResult = await request(functionId); @@ -1118,8 +1225,8 @@ async function initForTurntableFarm() { $.initForTurntableFarmRes = await request(arguments.callee.name.toString(), { version: 4, channel: 1 }); } async function lotteryForTurntableFarm() { - await $.wait(2000); - console.log('等待了2秒'); + await $.wait(3000); + console.log('等待了3秒'); $.lotteryRes = await request(arguments.callee.name.toString(), { type: 1, version: 4, channel: 1 }); } @@ -1302,13 +1409,13 @@ async function initForFarm() { }; $.post(option, (err, resp, data) => { try { - if (err) { - console.log('\n东东农场: API查询请求失败 ‼️‼️'); + if (err) { + console.log('\ninitForFarm: API查询请求失败 ‼️‼️'); console.log(JSON.stringify(err)); $.logErr(err); } else { if (safeGet(data)) { - $.farmInfo = JSON.parse(data) + $.farmInfo = JSON.parse(data) } } } catch (e) { @@ -1438,7 +1545,7 @@ function request(function_id, body = {}, timeout = 1000) { $.get(taskUrl(function_id, body), (err, resp, data) => { try { if (err) { - console.log('\n东东农场: API查询请求失败 ‼️‼️') + console.log('\nrequest: API查询请求失败 ‼️‼️') console.log(JSON.stringify(err)); console.log(`function_id:${function_id}`) $.logErr(err); diff --git a/jd_pet.js b/jd_pet_Mod.js similarity index 98% rename from jd_pet.js rename to jd_pet_Mod.js index 636ed8c..d286114 100644 --- a/jd_pet.js +++ b/jd_pet_Mod.js @@ -57,7 +57,17 @@ if ($.isNode() && process.env.CC_NOHELPAFTER8) { } } } - +let WP_APP_TOKEN_ONE = ""; +if ($.isNode()) { + if (process.env.WP_APP_TOKEN_ONE) { + WP_APP_TOKEN_ONE = process.env.WP_APP_TOKEN_ONE; + } +} +if(WP_APP_TOKEN_ONE) + console.log(`检测到已配置Wxpusher的Token,启用一对一推送...`); +else + console.log(`检测到未配置Wxpusher的Token,禁用一对一推送...`); + console.log(`共${cookiesArr.length}个京东账号\n`); !(async() => { @@ -166,6 +176,9 @@ async function jdPet() { if ($.isNode()) { await notify.sendNotify(`${$.name} - 账号${$.index} - ${$.nickName || $.UserName}奖品已可领取`, `京东账号${$.index} ${$.nickName || $.UserName}\n${$.petInfo.goodsInfo.goodsName}已可领取`); } + if ($.isNode() && WP_APP_TOKEN_ONE) { + await notify.sendNotifybyWxPucher($.name, `【提醒⏰】${$.petInfo.goodsInfo.goodsName}已可领取\n【领取步骤】京东->我的->东东萌宠兑换京东红包,可以用于京东app的任意商品.`, `${$.UserName}`); + } return } else if ($.petInfo.petStatus === 6) { await slaveHelp(); //已领取红包,但未领养新的,也能继续助力好友 @@ -174,6 +187,7 @@ async function jdPet() { if ($.isNode()) { await notify.sendNotify(`${$.name} - 账号${$.index} - ${$.nickName || $.UserName}奖品已可领取`, `京东账号${$.index} ${$.nickName || $.UserName}\n已领取红包,但未继续领养新的物品`); } + return } //console.log(`\n【京东账号${$.index}(${$.UserName})的${$.name}好友互助码】${$.petInfo.shareCode}\n`);