forked from Toulu-debug/enen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjd_checkCookie.ts
42 lines (38 loc) · 1.23 KB
/
jd_checkCookie.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
/**
* 检测cookie是否有效
* cron: 0 * * * *
*/
import axios from "axios";
import USER_AGENT, {requireConfig} from "./TS_USER_AGENTS";
const notify = require('./sendNotify')
let cookie: string = '', UserName: string, index: number, errMsg: string = '';
!(async () => {
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;
await api(index, cookie, UserName)
}
if (errMsg)
await notify.sendNotify("Cookie失效", errMsg, '', '你好,世界!')
})()
async function api(index: number, cookie: string, username: string) {
let {data} = await axios.get(`https://me-api.jd.com/user_new/info/GetJDUserInfoUnion`, {
headers: {
Host: "me-api.jd.com",
Connection: "keep-alive",
Cookie: cookie,
"User-Agent": USER_AGENT,
"Accept-Language": "zh-cn",
"Referer": "https://home.m.jd.com/myJd/newhome.action?sceneval=2&ufc=&",
"Accept-Encoding": "gzip, deflate, br"
}
})
if (data.retcode === '0') {
console.log(index, '✅', username)
} else {
console.log(index, '❌', username)
errMsg += `${index} ${username}\n`
}
}