修复 东东超市蓝币兑换京豆功能
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
/*
|
||||
东东超市兑换奖品 脚本地址:https://gitee.com/lxk0301/jd_scripts/raw/master/jd_blueCoin.js
|
||||
感谢@yangtingxiao提供PR
|
||||
更新时间:2021-3-2
|
||||
更新时间:2021-6-7
|
||||
活动入口:京东APP我的-更多工具-东东超市
|
||||
支持京东多个账号
|
||||
脚本兼容: 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))
|
||||
.finally(() => $.done())
|
||||
async function PrizeIndex() {
|
||||
// await smtg_queryPrize();
|
||||
await smtg_queryPrize();
|
||||
// await smtg_materialPrizeIndex();//兑换酒类奖品,此兑换API与之前的兑换京豆类的不一致,故目前无法进行
|
||||
await Promise.all([
|
||||
smtg_queryPrize(),
|
||||
smtg_materialPrizeIndex()
|
||||
])
|
||||
const prizeList = [...$.queryPrizeData, ...$.materialPrizeIndex];
|
||||
// const prizeList = [...$.queryPrizeData];
|
||||
// await Promise.all([
|
||||
// smtg_queryPrize(),
|
||||
// smtg_materialPrizeIndex()
|
||||
// ])
|
||||
// const prizeList = [...$.queryPrizeData, ...$.materialPrizeIndex];
|
||||
const prizeList = [...$.queryPrizeData];
|
||||
if (prizeList && prizeList.length) {
|
||||
if (`${coinToBeans}` === '1000') {
|
||||
if (prizeList[1] && prizeList[1].beanType === 'BeanPackage') {
|
||||
console.log(`查询换${prizeList[1].title}ID成功,ID:${prizeList[1].prizeId}`)
|
||||
$.title = prizeList[1].title;
|
||||
$.blueCost = prizeList[1].blueCost;
|
||||
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[1] && prizeList[1].inStock === 506) {
|
||||
if (prizeList[0] && prizeList[0].inStock === 506) {
|
||||
$.beanerr = `失败,1000京豆领光了,请明天再来`;
|
||||
return ;
|
||||
}
|
||||
if (prizeList[1] && prizeList[1].targetNum === prizeList[1] && prizeList[1].finishNum) {
|
||||
$.beanerr = `${prizeList[1].subTitle}`;
|
||||
if (prizeList[0] && prizeList[0].limit === prizeList[0] && prizeList[0].finished) {
|
||||
$.beanerr = `${prizeList[0].name}`;
|
||||
return ;
|
||||
}
|
||||
//兑换1000京豆
|
||||
if ($.totalBlue > $.blueCost) {
|
||||
await smtg_obtainPrize(prizeList[1].prizeId);
|
||||
await smtg_obtainPrize(prizeList[0].prizeId);
|
||||
} else {
|
||||
console.log(`兑换失败,您目前蓝币${$.totalBlue}个,不足以兑换${$.title}所需的${$.blueCost}个`);
|
||||
$.beanerr = `兑换失败,您目前蓝币${$.totalBlue}个,不足以兑换${$.title}所需的${$.blueCost}个`;
|
||||
}
|
||||
} else if (`${coinToBeans}` === '20') {
|
||||
if (prizeList[0] && prizeList[0].beanType === 'Bean') {
|
||||
console.log(`查询换${prizeList[0].title}ID成功,ID:${prizeList[0].prizeId}`)
|
||||
$.title = prizeList[0].title;
|
||||
$.blueCost = prizeList[0].blueCost;
|
||||
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(`查询换万能的京豆ID失败`)
|
||||
$.beanerr = `东哥今天不给换`;
|
||||
@ -146,8 +146,8 @@ async function PrizeIndex() {
|
||||
$.beanerr = `失败,万能的京豆领光了,请明天再来`;
|
||||
return ;
|
||||
}
|
||||
if ((prizeList[0] && prizeList[0].targetNum) === (prizeList[0] && prizeList[0].finishNum)) {
|
||||
$.beanerr = `${prizeList[0].subTitle}`;
|
||||
if ((prizeList[0] && prizeList[0].limit) === (prizeList[0] && prizeList[0].finished)) {
|
||||
$.beanerr = `${prizeList[0].name}`;
|
||||
return ;
|
||||
}
|
||||
//兑换万能的京豆(1-20京豆)
|
||||
@ -241,7 +241,7 @@ function smtg_queryPrize(timeout = 0){
|
||||
return new Promise((resolve) => {
|
||||
setTimeout( ()=>{
|
||||
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 : {
|
||||
'Origin' : `https://jdsupermarket.jd.com`,
|
||||
'Cookie' : cookie,
|
||||
@ -264,8 +264,13 @@ function smtg_queryPrize(timeout = 0){
|
||||
return
|
||||
}
|
||||
if (data.data.bizCode === 0) {
|
||||
const { prizeList } = data.data.result;
|
||||
$.queryPrizeData = data.data.result.prizeList || [];
|
||||
const { areas } = data.data.result;
|
||||
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) {
|
||||
@ -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
|
||||
const body = {
|
||||
prizeId,
|
||||
"channel": "1"
|
||||
"connectId": prizeId,
|
||||
"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) => {
|
||||
setTimeout( ()=>{
|
||||
@ -318,15 +336,15 @@ function smtg_obtainPrize(prizeId, timeout = 0, functionId = 'smtg_obtainPrize')
|
||||
if ($.data.data.bizCode === 0) {
|
||||
if (`${coinToBeans}` === '1000') {
|
||||
$.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;
|
||||
} else if (`${coinToBeans}` === '20') {
|
||||
$.beanscount ++;
|
||||
console.log(`【京东账号${$.index}】${$.nickName || $.UserName} 第${$.data.data.result.exchangeNum}次换${$.title}成功`)
|
||||
if ($.data.data.result.exchangeNum === 20 || $.beanscount === coinToBeans || $.data.data.result.blue < 500) return;
|
||||
console.log(`【京东账号${$.index}】${$.nickName || $.UserName} 第${$.data.data.result.count}次换${$.title}成功`)
|
||||
if ($.data.data.result.count === 20 || $.beanscount === coinToBeans || $.data.data.result.blue < $.blueCost) return;
|
||||
} else {
|
||||
$.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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user