|
|
发表于
2021-7-21 23:42:31
来自手机
|
显示全部楼层
来自 重庆
const $ = new Env("愤怒的锦鲤")
const JD_API_HOST = 'https://api.m.jd.com/client.action';
const ua = `jdltapp;iPhone;3.1.0;${Math.ceil(Math.random()*4+10)}.${Math.ceil(Math.random()*4)};${randomString(40)}`
var kois = process.env.kois ?? ""
let cookiesArr = []
var packets = [];
!(async () => {
if(!kois){
console.log("请在环境变量中填写需要助力的账号")
}
requireConfig()
len = cookiesArr.length
for (let i = 0; i < len; i++) {
cookie = cookiesArr[i]
if(!kois){
if(i != 0) {
break
}
console.log(`默认给账号${i+1}助力`)
}else if(kois.indexOf(cookie.match(/pt_pin=([^; ]+)(?=;?)/) && cookie.match(/pt_pin=([^; ]+)(?=;?)/)[1])==-1)continue
data = await requestApi('h5launch',cookie);
switch (data?.data?.result.status) {
case 1://火爆
continue;
case 2://已经发起过
break;
default:
if(data?.data?.result?.redPacketId){
packets.push(data.data.result.redPacketId)
}
continue;
}
data = await requestApi('h5activityIndex',cookie);
// console.log(data)
switch (data?.data?.code) {
case 20002://已达拆红包数量限制
break;
case 10002://活动正在进行,火爆号
break;
case 20001://红包活动正在进行,可拆
packets.push(data.data.result.redpacketInfo.id)
break;
default:
break;
}
}
tools = cookiesArr
while (tools.length && packets.length) {
var cookie = tools.pop()
requestApi('jinli_h5assist',cookie, {"redPacketId":packets[0]}).then(
function(data){
desc = data?.data?.result?.statusDesc
if(desc && desc.indexOf("助力已满")!=-1){
packets.shift()
tools.unshift(cookie)
}else if(!desc){
tools.unshift(cookie)
}
console.log(desc)
}
)
await $.wait(50)
}
})() .catch((e) => {
$.log('', `❌ ${$.name}, 失败! 原因: ${e}!`, '')
})
.finally(() => {
$.done();
})
function requestApi(functionId, cookie, body = {}) {
return new Promise(resolve => {
$.post({
url: `${JD_API_HOST}/api?appid=jd_mp_h5&functionId=${functionId}&loginType=2&client=jd_mp_h5&clientVersion=10.0.5&osVersion=AndroidOS&d_brand=Xiaomi&d_model=Xiaomi`,
headers: {
"Cookie": cookie,
"origin": "https://h5.m.jd.com",
"referer": "https://h5.m.jd.com/babelDiy/Zeus/2NUvze9e1uWf4amBhe1AV6ynmSuH/index.html",
'Content-Type': 'application/x-www-form-urlencoded',
"X-Requested-With": "com.jingdong.app.mall",
"User-Agent": ua,
},
body: `body=${escape(JSON.stringify(body))}`,
}, (_, resp, data) => {
try {
data = JSON.parse(data)
} catch (e) {
$.logErr('Error: ', e, resp)
} finally {
resolve(data)
}
})
})
}
function requireConfig() {
return new Promise(resolve => {
notify = $.isNode() ? require('./sendNotify') : '';
const jdCookieNode = $.isNode() ? require('./jdCookie.js') : '';
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);
}
console.log(`共${cookiesArr.length}个京东账号\n`)
resolve()
})
}
function randomString(e) {
e = e || 32;
let t = "abcdefhijkmnprstwxyz2345678",
a = t.length,
n = "";
for (i = 0; i < e; i++)
n += t.charAt(Math.floor(Math.random() * a));
return n
}
function Env(t, e) {
"undefined" != typeof process && JSON.stringify(process.env).indexOf("GIT_HUB") > -1 && process.exit(0);
class s {
constructor(t) {
this.env = t
}
send(t, e = "GET") {
t = "string" == typeof t ? {
url: t
} : t;
let s = this.get;
return "POST" === e && (s = this.post), new Promise((e, i) => {
s.call(this, t, (t, s, r) => {
t ? i(t) : e(s)
})
})
}
get(t) {
return this.send.call(this.env, t)
}
post(t) {
return this.send.call(this.env, t, "POST")
}
}
return new class {
constructor(t, e) {
this.name = t, this.http = new s(this), this.data = null, this.dataFile = "box.dat", this.logs = [], this.isMute = !1, this.isNeedRewrite = !1, this.logSeparator = "\n", this.startTime = (new Date).getTime(), Object.assign(this, e), this.log("", ` |
|