forked from Toulu-debug/enen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jd_joy_reward.ts
111 lines (102 loc) · 3.47 KB
/
jd_joy_reward.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/**
* 注意:
* 0~15秒才会进行兑换
* 16~59秒会进入死循环等待
* new Env('宠汪汪兑换');
*/
import axios from 'axios';
import {format} from 'date-fns';
import USER_AGENT, {requireConfig, TotalBean, wait} from './TS_USER_AGENTS';
import * as fs from 'fs';
const notify = require('./sendNotify'), md5 = require('md5')
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 lkt = new Date().getTime()
let lks = md5('' + 'RtKLB8euDo7KwsO0' + lkt).toString()
let {data}: any = await axios.get(`https://jdjoy.jd.com/common/gift/getBeanConfigs?reqSource=h5&invokeKey=RtKLB8euDo7KwsO0&validate=${validate}`, {
headers: {
'lkt': lkt,
'lks': lks,
'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) {
return new Promise<void>(async resolve => {
while (1) {
if (new Date().getSeconds() < 15) {
break
} else {
await wait(100)
}
}
console.log('exchange()', format(new Date(), 'hh:mm:ss:SSS'))
let lkt = new Date().getTime()
let lks = md5('' + 'RtKLB8euDo7KwsO0' + lkt).toString()
let {data}: any = await axios.post(`https://jdjoy.jd.com/common/gift/new/exchange?reqSource=h5&invokeKey=RtKLB8euDo7KwsO0&validate=${validate}`,
JSON.stringify({"buyParam": {"orderSource": 'pet', "saleInfoId": beanId}, "deviceInfo": {}}), {
headers: {
'lkt': lkt,
'lks': lks,
"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();
})
}