-
Notifications
You must be signed in to change notification settings - Fork 1k
/
jd_health_collect.ts
45 lines (37 loc) · 1.26 KB
/
jd_health_collect.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
/**
* 健康能量收集
* cron: 5-45/20 * * * *
*/
import axios from "axios";
import * as path from "path"
import USER_AGENT, {getCookie, exceptCookie, wait, o2s} from "./TS_USER_AGENTS"
let cookie: string = '', UserName: string, res: any = ''
!(async () => {
let cookiesArr: string[] = await getCookie()
let except: string[] = exceptCookie(path.basename(__filename))
for (let [index, value] of cookiesArr.entries()) {
cookie = value
UserName = decodeURIComponent(cookie.match(/pt_pin=([^;]*)/)![1])
console.log(`\n开始【京东账号${index + 1}】${UserName}\n`)
if (except.includes(encodeURIComponent(UserName))) {
console.log('已设置跳过')
continue
}
res = await api('jdhealth_collectProduceScore', {})
o2s(res)
await wait(1000)
}
})()
async function api(fn: string, body: object) {
let {data} = await axios.post('https://api.m.jd.com/', `functionId=${fn}&body=${encodeURIComponent(JSON.stringify(body))}&client=wh5&clientVersion=1.0.0&uuid=`, {
headers: {
'Host': 'api.m.jd.com',
'Origin': 'https://h5.m.jd.com',
'User-Agent': USER_AGENT,
'Referer': 'https://h5.m.jd.com/',
'Content-Type': 'application/x-www-form-urlencoded',
'Cookie': cookie
}
})
return data
}