1 Star 0 Fork 0

Mr不知为何/jd_scripts

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
jd_health.ts 2.89 KB
一键复制 编辑 原始数据 按行查看 历史
JDHelloWorld 提交于 2022-02-01 02:49 . break
/**
* 健康社区
* https://h5.m.jd.com/babelDiy/Zeus/D2CwCLVmaP3QonubWFJeTVhYRyT/index.html
* cron: 35 0,6,18 * * *
*/
import axios from 'axios';
import USER_AGENT, {exceptCookie, requireConfig, wait} from "./TS_USER_AGENTS";
import * as path from "path";
let cookie: string = '', res: any = '', UserName: string
!(async () => {
let cookiesArr: string[] = await requireConfig();
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
}
for (let j = 0; j < 3; j++) {
res = await api('jdhealth_getTaskDetail', {"buildingId": "", "taskId": "", "channelId": 1})
try {
for (let t of res.data.result.taskVos) {
if (t.status === 1 || t.status === 3) {
console.log(t.taskName)
for (let tp of t.productInfoVos || t.followShopVo || t.shoppingActivityVos || []) {
if (tp.status === 1) {
console.log('\t', tp.skuName || tp.shopName || tp.title)
if (t.taskName.includes('早睡打卡') && t.taskBeginTime < Date.now() && t.taskEndTime > Date.now()) {
res = await api('jdhealth_collectScore', {"taskToken": tp.taskToken, "taskId": t.taskId, "actionType": 1})
await wait(2000)
console.log('\t', res.data.bizMsg)
}
if (t.waitDuration) {
res = await api('jdhealth_collectScore', {"taskToken": tp.taskToken, "taskId": t.taskId, "actionType": 1})
console.log('\t', res.data.bizMsg)
await wait(t.waitDuration * 1000)
}
res = await api('jdhealth_collectScore', {"taskToken": tp.taskToken, "taskId": t.taskId, "actionType": 0})
if (res.data.bizMsg.indexOf('做完') !== -1) {
console.log(res.data.bizMsg)
break
} else {
console.log(res.data.bizMsg, res.data.result.score)
await wait(1500)
}
}
}
}
}
} catch (e) {
console.log('Error', e)
break
}
await wait(3000)
}
}
})();
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
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/issuns/jd_scripts.git
git@gitee.com:issuns/jd_scripts.git
issuns
jd_scripts
jd_scripts
main

搜索帮助