代码拉取完成,页面将自动刷新
//20 14 10 4 * jd_pet_automation.js
const {Env} = require('./function/magic');
const $ = new Env('M萌宠自动化');
let commodityName = process.env.M_JD_PET_COMMODITY
? process.env.M_JD_PET_COMMODITY
: ''
$.log('默认4级商品,生产指定商品请自行配置 M_JD_PET_COMMODITY')
$.logic = async function () {
let info = await api('initPetTown', {"version": 1});
$.log(JSON.stringify(info));
debugger
if (info?.result?.petStatus < 5) {
return
}
if (info?.result?.petStatus === 5) {
$.log(info?.result?.goodsInfo);
let activityId = info?.result?.goodsInfo.activityId;
let activityIds = info?.result?.goodsInfo.activityIds;
let data = await api('redPacketExchange',
{"activityId": activityId, "activityIds": activityIds});
$.putMsg(`${info?.result?.goodsInfo.exchangeMedalNum === 4 ? '12'
: '25'}红包,${$.formatDate(
$.timestamp() + data.result.pastDays * 24 * 60 * 60 * 1000)}过期`)
info = await api('initPetTown', {"version": 1});
}
if (info?.result?.petStatus === 6) {
info = await api('goodsInfoList', {"type": 2})
let goods = commodityName ? info.result.goodsList.filter(
o => o.goodsName.includes(commodityName))[0]
: info.result.goodsList.filter(o => o.exchangeMedalNum === 4)[0];
if (!goods) {
$.putMsg(`没找到你要生产的 ${commodityName}`)
return
}
info = await api('goodsInfoUpdate', {"goodsId": goods.goodsId})
$.putMsg(`生产【${info.result.goodsInfo.goodsName}】成功`)
}
};
$.run({
wait: [2000, 3000], whitelist: ['1-15']
}).catch(
reason => $.log(reason));
// noinspection DuplicatedCode
async function api(fn, body) {
let url = `https://api.m.jd.com/client.action?functionId=${fn}&body=${JSON.stringify(
body)}&client=apple&clientVersion=10.0.4&osVersion=13.7&appid=wh5&loginType=2&loginWQBiz=pet-town`
//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓请求头↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
let headers = {
"Cookie": $.cookie,
"Connection": "keep-alive",
"Accept": "*/*",
"Host": "api.m.jd.com",
'User-Agent': `Mozilla/5.0 (iPhone; CPU iPhone OS 14_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/8.0.4(0x1800042c) NetType/4G Language/zh_CN miniProgram`,
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "zh-cn"
}
let {data} = await $.request(url, headers)
await $.wait(1000, 3000)
return data;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。