2 Star 1 Fork 27

kevin/jd_scripts

forked from XanderYe/jd_scripts 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
jd_checkCookie.ts 1.23 KB
一键复制 编辑 原始数据 按行查看 历史
kevin 提交于 2021-11-23 10:04 . edit
/**
* 每天检测cookie是否有效
* cron: 10 * * * *
*/
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}: any = 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`
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/kevin0217/jd_scripts.git
git@gitee.com:kevin0217/jd_scripts.git
kevin0217
jd_scripts
jd_scripts
master

搜索帮助