代码拉取完成,页面将自动刷新
同步操作将从 git更新/JDHelloWorld-jd_scripts 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
/**
*
* Running time limit:
* s >= 58 or s <= 30 => exchange()
* s > 30 and s < 58 => wait...
*
*/
import axios from 'axios';
import USER_AGENT, {requireConfig, TotalBean, wait} from './TS_USER_AGENTS';
import * as fs from 'fs';
const notify = require('./sendNotify')
let $: any = {};
let cookie: string = '', validate: string = '', UserName: string, index: number;
let target: number = process.env.JD_JOY_REWARD_NAME ? parseInt(process.env.JD_JOY_REWARD_NAME) : 500;
!(async () => {
let validate_arr: string | Array<string> = fs.readFileSync('./validate.txt', 'utf-8')
if (validate_arr.indexOf('\n')) {
validate_arr = validate_arr.split('\n')
validate_arr.pop()
}
let cookiesArr: any = await requireConfig();
for (let i = 0; i < cookiesArr.length; i++) {
cookie = cookiesArr[i];
UserName = decodeURIComponent(cookie.match(/pt_pin=([^;]*)/)![1])
index = i + 1;
let {isLogin, nickName}: any = await TotalBean(cookie)
if (!isLogin) {
notify.sendNotify(__filename.split('/').pop(), `cookie已失效\n京东账号${index}:${nickName || UserName}`)
continue
}
console.log(`\n开始【京东账号${$.index}】${$.nickName || $.UserName}\n`);
if (i < validate_arr.length)
validate = validate_arr[i]
else {
console.log('预存验证码不够用,退出!')
break
}
let tasks: any = await init();
let h: number = new Date().getHours();
let config: any;
if (h >= 0 && h < 8)
config = tasks.data['beanConfigs0']
if (h >= 8 && h < 16)
config = tasks.data['beanConfigs8']
if (h >= 16 && h < 24)
config = tasks.data['beanConfigs16']
for (let bean of config) {
console.log(bean.id, bean.giftName, bean.leftStock)
if (bean.giftValue === target) {
await exchange(bean.id)
}
}
}
})()
function init() {
return new Promise(async resolve => {
let {data} = await axios.get(`https://jdjoy.jd.com/common/gift/getBeanConfigs?reqSource=h5&invokeKey=qRKHmL4sna8ZOP9F&validate=${validate}`, {
headers: {
'Host': 'jdjoy.jd.com',
'content-type': 'application/json',
'origin': 'https://h5.m.jd.com',
"User-Agent": USER_AGENT,
'referer': 'https://jdjoy.jd.com/',
'cookie': cookie
}
})
resolve(data);
})
}
function exchange(beanId: number) {
console.log('exchange()')
return new Promise<void>(async resolve => {
while (1) {
let s: number = new Date().getSeconds();
if (s >= 58 || s <= 30) {
break
} else {
await wait(500)
}
}
let {data} = await axios.post(`https://jdjoy.jd.com/common/gift/new/exchange?reqSource=h5&invokeKey=qRKHmL4sna8ZOP9F&validate=${validate}`,
JSON.stringify({"buyParam": {"orderSource": 'pet', "saleInfoId": beanId}, "deviceInfo": {}}), {
headers: {
"Host": "jdjoy.jd.com",
"Accept-Language": "zh-cn",
"Content-Type": "application/json",
"Origin": "https://jdjoy.jd.com",
"User-Agent": USER_AGENT,
"Referer": "https://jdjoy.jd.com/pet/index",
"Cookie": cookie
}
})
console.log(data);
resolve();
})
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。