修复 东东超市蓝币兑换京豆功能

This commit is contained in:
wisz2021
2021-06-07 14:57:10 +08:00
parent f634e51ec2
commit 199f42ba84

View File

@@ -1,7 +1,7 @@
/* /*
东东超市兑换奖品 脚本地址https://gitee.com/lxk0301/jd_scripts/raw/master/jd_blueCoin.js 东东超市兑换奖品 脚本地址https://gitee.com/lxk0301/jd_scripts/raw/master/jd_blueCoin.js
感谢@yangtingxiao提供PR 感谢@yangtingxiao提供PR
更新时间2021-3-2 更新时间2021-6-7
活动入口京东APP我的-更多工具-东东超市 活动入口京东APP我的-更多工具-东东超市
支持京东多个账号 支持京东多个账号
脚本兼容: QuantumultX, Surge, Loon, JSBox, Node.js 脚本兼容: QuantumultX, Surge, Loon, JSBox, Node.js
@@ -97,45 +97,45 @@ const JD_API_HOST = `https://api.m.jd.com/api?appid=jdsupermarket`;
.catch((e) => $.logErr(e)) .catch((e) => $.logErr(e))
.finally(() => $.done()) .finally(() => $.done())
async function PrizeIndex() { async function PrizeIndex() {
// await smtg_queryPrize(); await smtg_queryPrize();
// await smtg_materialPrizeIndex();//兑换酒类奖品此兑换API与之前的兑换京豆类的不一致故目前无法进行 // await smtg_materialPrizeIndex();//兑换酒类奖品此兑换API与之前的兑换京豆类的不一致故目前无法进行
await Promise.all([ // await Promise.all([
smtg_queryPrize(), // smtg_queryPrize(),
smtg_materialPrizeIndex() // smtg_materialPrizeIndex()
]) // ])
const prizeList = [...$.queryPrizeData, ...$.materialPrizeIndex]; // const prizeList = [...$.queryPrizeData, ...$.materialPrizeIndex];
// const prizeList = [...$.queryPrizeData]; const prizeList = [...$.queryPrizeData];
if (prizeList && prizeList.length) { if (prizeList && prizeList.length) {
if (`${coinToBeans}` === '1000') { if (`${coinToBeans}` === '1000') {
if (prizeList[1] && prizeList[1].beanType === 'BeanPackage') { if (prizeList[0] && prizeList[0].type === 3) {
console.log(`查询换${prizeList[1].title}ID成功ID:${prizeList[1].prizeId}`) console.log(`查询换${prizeList[0].name}ID成功ID:${prizeList[0].prizeId}`)
$.title = prizeList[1].title; $.title = prizeList[0].name;
$.blueCost = prizeList[1].blueCost; $.blueCost = prizeList[0].cost;
} else { } else {
console.log(`查询换1000京豆ID失败`) console.log(`查询换1000京豆ID失败`)
$.beanerr = `东哥今天不给换`; $.beanerr = `东哥今天不给换`;
return ; return ;
} }
if (prizeList[1] && prizeList[1].inStock === 506) { if (prizeList[0] && prizeList[0].inStock === 506) {
$.beanerr = `失败1000京豆领光了请明天再来`; $.beanerr = `失败1000京豆领光了请明天再来`;
return ; return ;
} }
if (prizeList[1] && prizeList[1].targetNum === prizeList[1] && prizeList[1].finishNum) { if (prizeList[0] && prizeList[0].limit === prizeList[0] && prizeList[0].finished) {
$.beanerr = `${prizeList[1].subTitle}`; $.beanerr = `${prizeList[0].name}`;
return ; return ;
} }
//兑换1000京豆 //兑换1000京豆
if ($.totalBlue > $.blueCost) { if ($.totalBlue > $.blueCost) {
await smtg_obtainPrize(prizeList[1].prizeId); await smtg_obtainPrize(prizeList[0].prizeId);
} else { } else {
console.log(`兑换失败,您目前蓝币${$.totalBlue}个,不足以兑换${$.title}所需的${$.blueCost}`); console.log(`兑换失败,您目前蓝币${$.totalBlue}个,不足以兑换${$.title}所需的${$.blueCost}`);
$.beanerr = `兑换失败,您目前蓝币${$.totalBlue}个,不足以兑换${$.title}所需的${$.blueCost}`; $.beanerr = `兑换失败,您目前蓝币${$.totalBlue}个,不足以兑换${$.title}所需的${$.blueCost}`;
} }
} else if (`${coinToBeans}` === '20') { } else if (`${coinToBeans}` === '20') {
if (prizeList[0] && prizeList[0].beanType === 'Bean') { if (prizeList[1] && prizeList[1].type === 3) {
console.log(`查询换${prizeList[0].title}ID成功ID:${prizeList[0].prizeId}`) console.log(`查询换${prizeList[1].name}ID成功ID:${prizeList[1].prizeId}`)
$.title = prizeList[0].title; $.title = prizeList[1].name;
$.blueCost = prizeList[0].blueCost; $.blueCost = prizeList[1].cost;
} else { } else {
console.log(`查询换万能的京豆ID失败`) console.log(`查询换万能的京豆ID失败`)
$.beanerr = `东哥今天不给换`; $.beanerr = `东哥今天不给换`;
@@ -146,8 +146,8 @@ async function PrizeIndex() {
$.beanerr = `失败,万能的京豆领光了,请明天再来`; $.beanerr = `失败,万能的京豆领光了,请明天再来`;
return ; return ;
} }
if ((prizeList[0] && prizeList[0].targetNum) === (prizeList[0] && prizeList[0].finishNum)) { if ((prizeList[0] && prizeList[0].limit) === (prizeList[0] && prizeList[0].finished)) {
$.beanerr = `${prizeList[0].subTitle}`; $.beanerr = `${prizeList[0].name}`;
return ; return ;
} }
//兑换万能的京豆(1-20京豆) //兑换万能的京豆(1-20京豆)
@@ -241,7 +241,7 @@ function smtg_queryPrize(timeout = 0){
return new Promise((resolve) => { return new Promise((resolve) => {
setTimeout( ()=>{ setTimeout( ()=>{
let url = { let url = {
url : `${JD_API_HOST}&functionId=smtg_queryPrize&clientVersion=8.0.0&client=m&body=%7B%7D&t=${Date.now()}`, url : `${JD_API_HOST}&functionId=smt_queryPrizeAreas&clientVersion=8.0.0&client=m&body=%7B%22channel%22%3A%2218%22%7D&t=${Date.now()}`,
headers : { headers : {
'Origin' : `https://jdsupermarket.jd.com`, 'Origin' : `https://jdsupermarket.jd.com`,
'Cookie' : cookie, 'Cookie' : cookie,
@@ -264,8 +264,13 @@ function smtg_queryPrize(timeout = 0){
return return
} }
if (data.data.bizCode === 0) { if (data.data.bizCode === 0) {
const { prizeList } = data.data.result; const { areas } = data.data.result;
$.queryPrizeData = data.data.result.prizeList || []; const prizes = areas.filter(vo => vo['type'] === 4);
if (prizes && prizes[0]) {
$.areaId = prizes[0].areaId;
$.periodId = prizes[0].periodId;
$.queryPrizeData = prizes[0].prizes || [];
}
} }
} }
} catch (e) { } catch (e) {
@@ -278,11 +283,24 @@ function smtg_queryPrize(timeout = 0){
}) })
} }
//换京豆 //换京豆
function smtg_obtainPrize(prizeId, timeout = 0, functionId = 'smtg_obtainPrize') { function smtg_obtainPrize(prizeId, timeout = 0, functionId = 'smt_exchangePrize') {
//1000京豆prizeId为4401379726 //1000京豆prizeId为4401379726
const body = { const body = {
prizeId, "connectId": prizeId,
"channel": "1" "areaId": $.areaId,
"periodId": $.periodId,
"informationParam": {
"eid": "",
"referUrl": -1,
"shshshfp": "",
"openId": -1,
"isRvc": 0,
"fp": -1,
"shshshfpa": "",
"shshshfpb": "",
"userAgent": -1
},
"channel": "18"
} }
return new Promise((resolve) => { return new Promise((resolve) => {
setTimeout( ()=>{ setTimeout( ()=>{
@@ -318,15 +336,15 @@ function smtg_obtainPrize(prizeId, timeout = 0, functionId = 'smtg_obtainPrize')
if ($.data.data.bizCode === 0) { if ($.data.data.bizCode === 0) {
if (`${coinToBeans}` === '1000') { if (`${coinToBeans}` === '1000') {
$.beanscount ++; $.beanscount ++;
console.log(`【京东账号${$.index}${$.nickName || $.UserName}${$.data.data.result.exchangeNum}次换${$.title}成功`) console.log(`【京东账号${$.index}${$.nickName || $.UserName}${$.data.data.result.count}次换${$.title}成功`)
if ($.beanscount === 1) return; if ($.beanscount === 1) return;
} else if (`${coinToBeans}` === '20') { } else if (`${coinToBeans}` === '20') {
$.beanscount ++; $.beanscount ++;
console.log(`【京东账号${$.index}${$.nickName || $.UserName}${$.data.data.result.exchangeNum}次换${$.title}成功`) console.log(`【京东账号${$.index}${$.nickName || $.UserName}${$.data.data.result.count}次换${$.title}成功`)
if ($.data.data.result.exchangeNum === 20 || $.beanscount === coinToBeans || $.data.data.result.blue < 500) return; if ($.data.data.result.count === 20 || $.beanscount === coinToBeans || $.data.data.result.blue < $.blueCost) return;
} else { } else {
$.beanscount ++; $.beanscount ++;
console.log(`【京东账号${$.index}${$.nickName || $.UserName}${$.data.data.result.exchangeNum}次换${$.title}成功`) console.log(`【京东账号${$.index}${$.nickName || $.UserName}${$.data.data.result.count}次换${$.title}成功`)
if ($.beanscount === 1) return; if ($.beanscount === 1) return;
} }
} }