From 926ce43891255a1611796a976bf92ba6bbd9c2f8 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 15 Jul 2021 21:05:21 -0400 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BA=8E=2007-15=2021:05?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jd_blueCoin.js | 120 +++++++++++++++++++++++++++++++------------------ 1 file changed, 76 insertions(+), 44 deletions(-) diff --git a/jd_blueCoin.js b/jd_blueCoin.js index bd11f18..d53309d 100755 --- a/jd_blueCoin.js +++ b/jd_blueCoin.js @@ -1,5 +1,5 @@ /* -东东超市兑换奖品 脚本地址:https://gitee.com/lxk0301/jd_scripts/raw/master/jd_blueCoin.js +东东超市兑换奖品 脚本地址:jd_blueCoin.js 感谢@yangtingxiao提供PR 更新时间:2021-6-7 活动入口:京东APP我的-更多工具-东东超市 @@ -8,24 +8,24 @@ ============QuantumultX============== [task_local] #东东超市兑换奖品 -0 0 0 * * * https://gitee.com/lxk0301/jd_scripts/raw/master/jd_blueCoin.js, tag=东东超市兑换奖品, img-url=https://raw.githubusercontent.com/58xinian/icon/master/jxc.png, enabled=true +0 0 0 * * * jd_blueCoin.js, tag=东东超市兑换奖品, img-url=https://raw.githubusercontent.com/58xinian/icon/master/jxc.png, enabled=true ====================Loon================= [Script] -cron "0 0 0 * * *" script-path=https://gitee.com/lxk0301/jd_scripts/raw/master/jd_blueCoin.js,tag=东东超市兑换奖品 +cron "0 0 0 * * *" script-path=jd_blueCoin.js,tag=东东超市兑换奖品 ===================Surge================== -东东超市兑换奖品 = type=cron,cronexp="0 0 0 * * *",wake-system=1,timeout=3600,script-path=https://gitee.com/lxk0301/jd_scripts/raw/master/jd_blueCoin.js +东东超市兑换奖品 = type=cron,cronexp="0 0 0 * * *",wake-system=1,timeout=3600,script-path=jd_blueCoin.js ============小火箭========= -东东超市兑换奖品 = type=cron,script-path=https://gitee.com/lxk0301/jd_scripts/raw/master/jd_blueCoin.js, cronexpr="0 0 0 * * *", timeout=3600, enable=true +东东超市兑换奖品 = type=cron,script-path=jd_blueCoin.js, cronexpr="0 0 0 * * *", timeout=3600, enable=true */ const $ = new Env('东东超市兑换奖品'); const notify = $.isNode() ? require('./sendNotify') : ''; let allMessage = ''; //Node.js用户请在jdCookie.js处填写京东ck; const jdCookieNode = $.isNode() ? require('./jdCookie.js') : ''; -let coinToBeans = $.getdata('coinToBeans') || 0; //兑换多少数量的京豆(20或者1000),0表示不兑换,默认不兑换京豆,如需兑换把0改成20或者1000,或者'商品名称'(商品名称放到单引号内)即可 +let coinToBeans = $.getdata('coinToBeans') || 20; //兑换多少数量的京豆(20或者1000),0表示不兑换,默认不兑换京豆,如需兑换把0改成20或者1000,或者'商品名称'(商品名称放到单引号内)即可 let jdNotify = false;//是否开启静默运行,默认false关闭(即:奖品兑换成功后会发出通知提示) //IOS等用户直接用NobyDa的jd cookie let cookiesArr = [], cookie = ''; @@ -39,12 +39,26 @@ if ($.isNode()) { } const JD_API_HOST = `https://api.m.jd.com/api?appid=jdsupermarket`; +Date.prototype.Format = function (fmt) { //author: meizz + var o = { + "M+": this.getMonth() + 1, //月份 + "d+": this.getDate(), //日 + "h+": this.getHours(), //小时 + "m+": this.getMinutes(), //分 + "s+": this.getSeconds(), //秒 + "S": this.getMilliseconds() //毫秒 + }; + if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length)); + for (var k in o) + if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length))); + return fmt; +} !(async () => { 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++) { + for (let i = 0; i < cookiesArr.length; i++) { cookie = cookiesArr[i]; if (cookie) { $.UserName = decodeURIComponent(cookie.match(/pt_pin=([^; ]+)(?=;?)/) && cookie.match(/pt_pin=([^; ]+)(?=;?)/)[1]) @@ -60,7 +74,7 @@ const JD_API_HOST = `https://api.m.jd.com/api?appid=jdsupermarket`; //console.log($.coincount); $.isLogin = true; $.nickName = ''; - // await TotalBean(); + await TotalBean(); console.log(`\n****开始【京东账号${$.index}】${$.nickName || $.UserName}****\n`); // console.log(`目前暂无兑换酒类的奖品功能,即使输入酒类名称,脚本也会提示下架\n`) if (!$.isLogin) { @@ -96,7 +110,15 @@ const JD_API_HOST = `https://api.m.jd.com/api?appid=jdsupermarket`; })() .catch((e) => $.logErr(e)) .finally(() => $.done()) + async function PrizeIndex() { + let timel = new Date().Format("ss") + let timea = 58; + if(timel < 58) { + let timec = (timea - timel) * 1000; + console.log(`等待时间 ${timec / 1000}`); + await sleep(timec) + } await smtg_queryPrize(); // await smtg_materialPrizeIndex();//兑换酒类奖品,此兑换API与之前的兑换京豆类的不一致,故目前无法进行 // await Promise.all([ @@ -107,52 +129,56 @@ async function PrizeIndex() { const prizeList = [...$.queryPrizeData]; if (prizeList && prizeList.length) { if (`${coinToBeans}` === '1000') { - if (prizeList[0] && prizeList[0].type === 3) { - console.log(`查询换${prizeList[0].name}ID成功,ID:${prizeList[0].prizeId}`) - $.title = prizeList[0].name; - $.blueCost = prizeList[0].cost; - } else { - console.log(`查询换1000京豆ID失败`) - $.beanerr = `东哥今天不给换`; - return ; - } - if (prizeList[0] && prizeList[0].inStock === 506) { - $.beanerr = `失败,1000京豆领光了,请明天再来`; - return ; - } - if (prizeList[0] && prizeList[0].limit === prizeList[0] && prizeList[0].finished) { - $.beanerr = `${prizeList[0].name}`; - return ; - } - //兑换1000京豆 - if ($.totalBlue > $.blueCost) { - await smtg_obtainPrize(prizeList[0].prizeId); - } else { - console.log(`兑换失败,您目前蓝币${$.totalBlue}个,不足以兑换${$.title}所需的${$.blueCost}个`); - $.beanerr = `兑换失败,您目前蓝币${$.totalBlue}个,不足以兑换${$.title}所需的${$.blueCost}个`; - } - } else if (`${coinToBeans}` === '20') { if (prizeList[1] && prizeList[1].type === 3) { console.log(`查询换${prizeList[1].name}ID成功,ID:${prizeList[1].prizeId}`) $.title = prizeList[1].name; $.blueCost = prizeList[1].cost; + } else { + console.log(`查询换1000京豆ID失败`) + $.beanerr = `东哥今天不给换`; + return ; + } + // if (prizeList[1] && prizeList[1].status === 2) { + // $.beanerr = `失败,1000京豆领光了,请明天再来`; + // return ; + // } + if (prizeList[1] && prizeList[1].limit === prizeList[1] && prizeList[1].finished) { + $.beanerr = `${prizeList[1].name}`; + return ; + } + //兑换1000京豆 + if ($.totalBlue > $.blueCost) { + for (let j = 0; j <= 10; j++) { + await smtg_obtainPrize(prizeList[1].prizeId); + } + } else { + console.log(`兑换失败,您目前蓝币${$.totalBlue}个,不足以兑换${$.title}所需的${$.blueCost}个`); + $.beanerr = `兑换失败,您目前蓝币${$.totalBlue}个,不足以兑换${$.title}所需的${$.blueCost}个`; + } + } else if (`${coinToBeans}` === '20') { + if (prizeList[0] && prizeList[0].type === 3) { + console.log(`查询换${prizeList[0].name}ID成功,ID:${prizeList[0].prizeId}`) + $.title = prizeList[0].name; + $.blueCost = prizeList[0].cost; } else { console.log(`查询换万能的京豆ID失败`) $.beanerr = `东哥今天不给换`; return ; } - if (prizeList[0] && prizeList[0].inStock === 506) { - console.log(`失败,万能的京豆领光了,请明天再来`); - $.beanerr = `失败,万能的京豆领光了,请明天再来`; - return ; - } + // if (prizeList[0] && prizeList[0].status === 2) { + // console.log(`失败,万能的京豆领光了,请明天再来`); + // $.beanerr = `失败,万能的京豆领光了,请明天再来`; + // return ; + // } if ((prizeList[0] && prizeList[0].limit) === (prizeList[0] && prizeList[0].finished)) { $.beanerr = `${prizeList[0].name}`; return ; } //兑换万能的京豆(1-20京豆) if ($.totalBlue > $.blueCost) { - await smtg_obtainPrize(prizeList[0].prizeId,1000); + for (let j = 0; j <= 10; j++) { + await smtg_obtainPrize(prizeList[0].prizeId, 1000); + } } else { console.log(`兑换失败,您目前蓝币${$.totalBlue}个,不足以兑换${$.title}所需的${$.blueCost}个`); $.beanerr = `兑换失败,您目前蓝币${$.totalBlue}个,不足以兑换${$.title}所需的${$.blueCost}个`; @@ -183,9 +209,13 @@ async function PrizeIndex() { } if ($.totalBlue > $.blueCost) { if ($.type === 4 && !$.beanType) { - await smtg_obtainPrize(prizeId, 0, "smtg_lockMaterialPrize") + for (let j = 0; j <= 10; j++) { + await smtg_obtainPrize(prizeId, 0, "smtg_lockMaterialPrize") + } } else { - await smtg_obtainPrize(prizeId); + for (let j = 0; j <= 10; j++) { + await smtg_obtainPrize(prizeId); + } } } else { console.log(`兑换失败,您目前蓝币${$.totalBlue}个,不足以兑换${$.title}所需的${$.blueCost}个`); @@ -349,7 +379,7 @@ function smtg_obtainPrize(prizeId, timeout = 0, functionId = 'smt_exchangePrize' } } } - await smtg_obtainPrize(prizeId,3000); + await smtg_obtainPrize(prizeId, 3000); } catch (e) { $.logErr(e, resp); } finally { @@ -361,7 +391,7 @@ function smtg_obtainPrize(prizeId, timeout = 0, functionId = 'smt_exchangePrize' } function smtgHome() { return new Promise((resolve) => { - $.get(taskUrl('smtg_home'), (err, resp, data) => { + $.get(taskUrl('smtg_newHome'), (err, resp, data) => { try { if (err) { console.log('\n东东超市兑换奖品: API查询请求失败 ‼️‼️') @@ -386,7 +416,9 @@ function smtgHome() { }) }) } - +function sleep(timeout) { + return new Promise((resolve) => setTimeout(resolve, timeout)); +} //通知 function msgShow() { // $.msg($.name, ``, `【京东账号${$.index}】${$.nickName}\n【收取蓝币】${$.coincount ? `${$.coincount}个` : $.coinerr }${coinToBeans ? `\n【兑换京豆】${ $.beanscount ? `${$.beanscount}个` : $.beanerr}` : ""}`);