diff --git a/jd_fruit_friend.js b/jd_fruit_friend.js index 233ae28..1da9da2 100644 --- a/jd_fruit_friend.js +++ b/jd_fruit_friend.js @@ -10,19 +10,17 @@ ==========================Quantumultx========================= [task_local] #jd免费水果 -10 5,17 * * * jd_fruit_friend.js, tag=东东农场好友删减奖励, img-url=https://raw.githubusercontent.com/58xinian/icon/master/jdnc.png, enabled=true +10 2 * * * jd_fruit_friend.js, tag=东东农场好友删减奖励, img-url=https://raw.githubusercontent.com/58xinian/icon/master/jdnc.png, enabled=true =========================Loon============================= [Script] -cron "10 5,17 * * *" script-path=jd_fruit_friend.js,tag=东东农场好友删减奖励 +cron "10 2 * * *" script-path=jd_fruit_friend.js,tag=东东农场好友删减奖励 =========================Surge============================ -东东农场好友删减奖励 = type=cron,cronexp="10 5,17 * * *",wake-system=1,timeout=3600,script-path=jd_fruit_friend.js +东东农场好友删减奖励 = type=cron,cronexp="10 2 * * *",wake-system=1,timeout=3600,script-path=jd_fruit_friend.js =========================小火箭=========================== -东东农场好友删减奖励 = type=cron,script-path=jd_fruit_friend.js, cronexpr="10 5,17 * * *", timeout=3600, enable=true +东东农场好友删减奖励 = type=cron,script-path=jd_fruit_friend.js, cronexpr="10 2 * * *", timeout=3600, enable=true -每号间隔(毫秒),默认0毫秒(0分钟) -export fruit_sleep=20000 */ const $ = new Env('东东农场好友删减奖励'); @@ -35,7 +33,22 @@ let jdFruitBeanCard = false;//农场使用水滴换豆卡(如果出现限时活 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; +let llhelp = true; +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 lnrun = 0; +let llgetshare = false; !(async () => { await requireConfig(); if (!cookiesArr[0]) { @@ -43,60 +56,83 @@ let llhelp=true; 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" }); + console.log('\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 (!$.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(); - await $.wait(1500); - } - } - } - 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 ($.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; + llgetshare = false; + await GetCollect(); + if(llgetshare){ + await $.wait(5000); + lnrun++; + } + if(lnrun == 10){ + console.log(`\n【访问接口次数达到10次,休息一分钟.....】\n`); + 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("\n【缓存文件Fruit_ShareCache.json更新失败!】\n"); + } else { + console.log("\n【缓存文件Fruit_ShareCache.json更新成功!】\n"); + } + }) } - message = ''; - subTitle = ''; - option = {}; - $.retry = 0; - await jdFruit(); - await $.wait(30 * 1000); - } - if ($.isNode()) { - process.env.fruit_sleep ? await $.wait(Number(process.env.fruit_sleep)) : '' - } } + console.log('\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(); + 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 + } + message = ''; + subTitle = ''; + option = {}; + $.retry = 0; + lnrun++; + await jdFruit(); + if (lnrun == 5) { + console.log(`\n【访问接口次数达到5次,休息一分钟.....】\n`); + await $.wait(60 * 1000); + lnrun = 0; + } + } + } if ($.isNode() && allMessage && $.ctrTemp) { await notify.sendNotify(`${$.name}`, `${allMessage}`) } @@ -172,18 +208,44 @@ async function receiveFriendInvite() { } } 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数据异常,使用作者的互助码:94f3ba0769b04c94bbfca26139108702`); - newShareCodes.push("94f3ba0769b04c94bbfca26139108702"); + 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调用接口======================== //鸭子,点我有惊喜 @@ -572,7 +634,7 @@ function TotalBean() { }) }) } -function request(function_id, body = {}, timeout = 1000) { +function request(function_id, body = {}, timeout = 2000) { return new Promise(resolve => { setTimeout(() => { $.get(taskUrl(function_id, body), (err, resp, data) => { diff --git a/jd_fruit_help.js b/jd_fruit_help.js index 30f48a2..bbba2ea 100644 --- a/jd_fruit_help.js +++ b/jd_fruit_help.js @@ -23,9 +23,6 @@ cron "20 4,16 * * *" script-path=jd_fruit_help.js,tag=东东农场内部互助 export DO_TEN_WATER_AGAIN="" 默认再次浇水 -每号间隔(毫秒),默认0毫秒(0分钟) -export fruit_sleep=20000 - */ const $ = new Env('东东农场内部水滴互助'); let cookiesArr = [], @@ -54,7 +51,22 @@ let randomCount = $.isNode() ? 20 : 5; 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; +let llhelp = true; +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 lnrun = 0; +let llgetshare = false; !(async() => { await requireConfig(); if (!cookiesArr[0]) { @@ -62,7 +74,7 @@ let llhelp=true; return; } if(llhelp){ - console.log('开始收集您的互助码,用于账号内部互助,请稍等...'); + console.log('\n【开始收集您的互助码,用于账号内部互助,请稍等...】\n'); for (let i = 0; i < cookiesArr.length; i++) { if (cookiesArr[i]) { cookie = cookiesArr[i]; @@ -74,20 +86,41 @@ let llhelp=true; 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(); - await $.wait(1500); - } - } - } + 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(`\n【访问接口次数达到10次,休息一分钟.....】\n`); + 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("\n【缓存文件Fruit_ShareCache.json更新失败!】\n"); + } else { + console.log("\n【缓存文件Fruit_ShareCache.json更新成功!】\n"); + } + }) + } + } + console.log('\n【互助码已经收集完毕,现在开始账号内部互助,请稍等...】\n'); for (let i = 0; i < cookiesArr.length; i++) { if (cookiesArr[i]) { cookie = cookiesArr[i]; @@ -109,12 +142,14 @@ let llhelp=true; subTitle = ''; option = {}; $.retry = 0; - await jdFruit(); - await $.wait(20 * 1000); + lnrun++; + await jdFruit(); + if (lnrun == 5) { + console.log(`\n【访问接口次数达到5次,休息一分钟.....】\n`); + await $.wait(60 * 1000); + lnrun = 0; + } } - if ($.isNode()) { - process.env.fruit_sleep ? await $.wait(Number(process.env.fruit_sleep)) : '' - } } if ($.isNode() && allMessage && $.ctrTemp) { await notify.sendNotify(`${$.name}`, `${allMessage}`) @@ -231,7 +266,7 @@ async function turntableFarm() { } //助力好友 async function masterHelpShare() { - + await $.wait(2000); await initForFarm(); let salveHelpAddWater = 0; let remainTimes = 3;//今日剩余助力次数,默认3次(京东农场每人每天3次助力机会)。 @@ -250,7 +285,6 @@ async function masterHelpShare() { continue } await masterHelp(code); - await $.wait(2000); if ($.helpResult.code === '0') { if ($.helpResult.helpResult.code === '0') { //助力成功 @@ -306,18 +340,46 @@ async function masterHelpShare() { } 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数据异常`); + 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调用接口======================== //鸭子,点我有惊喜 async function getFullCollectionReward() { @@ -708,7 +770,7 @@ function TotalBean() { }) } -function request(function_id, body = {}, timeout = 1000) { +function request(function_id, body = {}, timeout = 2000) { return new Promise(resolve => { setTimeout(() => { $.get(taskUrl(function_id, body), (err, resp, data) => { diff --git a/jd_fruit_task.js b/jd_fruit_task.js index b742766..ba2ba91 100644 --- a/jd_fruit_task.js +++ b/jd_fruit_task.js @@ -23,9 +23,6 @@ cron "5 6-18/6 * * *" script-path=jd_fruit_task.js,tag=东东农场日常任务 export DO_TEN_WATER_AGAIN="" 默认再次浇水 -每号间隔(毫秒),默认0毫秒(0分钟) -export fruit_sleep=20000 - */ const $ = new Env('东东农场日常任务'); let cookiesArr = [], @@ -52,8 +49,9 @@ let jdFruitBeanCard = false; //农场使用水滴换豆卡(如果出现限时活 let randomCount = $.isNode() ? 20 : 5; 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 lnrun = 0; !(async() => { - await requireConfig(); + 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; @@ -79,13 +77,15 @@ const urlSchema = `openjd://virtual?params=%7B%20%22category%22:%20%22jump%22,%2 subTitle = ''; option = {}; $.retry = 0; - //await shareCodesFormat(); + lnrun++; await jdFruit(); + if (lnrun == 3) { + console.log(`\n【访问接口次数达到3次,休息一分钟.....】\n`); + await $.wait(60 * 1000); + lnrun = 0; + } await $.wait(30 * 1000); } - if ($.isNode()) { - process.env.fruit_sleep ? await $.wait(Number(process.env.fruit_sleep)) : '' - } } if ($.isNode() && allMessage && $.ctrTemp) { await notify.sendNotify(`${$.name}`, `${allMessage}`) @@ -1207,42 +1207,27 @@ function timeFormat(time) { } return date.getFullYear() + '-' + ((date.getMonth() + 1) >= 10 ? (date.getMonth() + 1) : '0' + (date.getMonth() + 1)) + '-' + (date.getDate() >= 10 ? date.getDate() : '0' + date.getDate()); } - function requireConfig() { - return new Promise(resolve => { - console.log('开始获取配置文件\n') - notify = $.isNode() ? require('./sendNotify') : ''; - //Node.js用户请在jdCookie.js处填写京东ck; - const jdCookieNode = $.isNode() ? require('./jdCookie.js') : ''; - const jdFruitShareCodes = $.isNode() ? require('./jdFruitShareCodes.js') : ''; - //IOS等用户直接用NobyDa的jd cookie - if ($.isNode()) { - Object.keys(jdCookieNode).forEach((item) => { - if (jdCookieNode[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); + return new Promise(resolve => { + console.log('开始获取配置文件\n') + notify = $.isNode() ? require('./sendNotify') : ''; + //Node.js用户请在jdCookie.js处填写京东ck; + const jdCookieNode = $.isNode() ? require('./jdCookie.js') : ''; + //IOS等用户直接用NobyDa的jd cookie + if ($.isNode()) { + Object.keys(jdCookieNode).forEach((item) => { + if (jdCookieNode[item]) { + cookiesArr.push(jdCookieNode[item]) } - console.log(`共${cookiesArr.length}个京东账号\n`) - $.shareCodesArr = []; - if ($.isNode()) { - Object.keys(jdFruitShareCodes).forEach((item) => { - if (jdFruitShareCodes[item]) { - $.shareCodesArr.push(jdFruitShareCodes[item]) - } - }) - } else { - if ($.getdata('jd_fruit_inviter')) $.shareCodesArr = $.getdata('jd_fruit_inviter').split('\n').filter(item => !!item); - console.log(`\nBoxJs设置的${$.name}好友邀请码:${$.getdata('jd_fruit_inviter') ? $.getdata('jd_fruit_inviter') : '暂无'}\n`); - } - // console.log(`$.shareCodesArr::${JSON.stringify($.shareCodesArr)}`) - // console.log(`jdFruitShareArr账号长度::${$.shareCodesArr.length}`) - // console.log(`您提供了${$.shareCodesArr.length}个账号的农场助力码\n`); - resolve() - }) + }) + 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); + } + console.log(`共${cookiesArr.length}个京东账号\n`) + $.shareCodesArr = []; + resolve() + }) } function TotalBean() {