This commit is contained in:
Faker
2022-05-12 11:10:00 +08:00
parent 25fe17e584
commit f3f5c595bb
15 changed files with 637 additions and 301 deletions

View File

@@ -1,41 +1,65 @@
import USER_AGENT, {post, requireConfig, wait} from './TS_USER_AGENTS'
/**
* 京东-领现金
* 兼容panda api和本地sign
*
* 使用panda sign
* export PANDA_TOKEN=""
* 本地sign算法 import {getSign} from './test/sign'
*/
import {User, JDHelloWorld} from "./TS_JDHelloWorld";
import {getSign} from "./test/sign";
let cookie: string = '', res: any = '', data: any, UserName: string
class CASH extends JDHelloWorld {
cookie: string
!(async () => {
let cookiesArr: string[] = await requireConfig()
for (let [index, value] of Object.entries(cookiesArr)) {
cookie = value
UserName = decodeURIComponent(cookie.match(/pt_pin=([^;]*)/)![1])
console.log(`\n开始【京东账号${index + 1}${UserName}\n`)
constructor() {
super();
}
res = await api('cash_homePage', {})
async init() {
await this.run(new CASH())
}
async api(fn: string, body: object) {
let sign = getSign(fn, body)
return await this.post(`https://api.m.jd.com/client.action?functionId=${fn}`, sign, {
'Host': 'api.m.jd.com',
'Cookie': this.cookie,
'user-agent': 'jdapp;',
})
}
async main(user: User) {
this.cookie = user.cookie
let res: any = await this.api('cash_homePage', {})
if (res.data.result.signedStatus !== 1) {
console.log('今日未签到')
data = await api('cash_sign', {"remind": 0, "inviteCode": "", "type": 0, "breakReward": 0})
await wait(1000)
await this.api('cash_sign', {"remind": 0, "inviteCode": "", "type": 0, "breakReward": 0})
await this.wait(1000)
console.log('签到成功')
} else {
console.log('今日已签到')
}
res = await api('cash_homePage', {})
await wait(1000)
let type: number[] = [2, 4, 31, 16, 3, 5, 17, 21]
res = await this.api('cash_homePage', {})
let type: number[] = [2, 4, 31, 16, 3, 5, 17, 21], data: any
let otherTaskNum = res.data.result.taskInfos.filter(item => !type.includes(item.type)).length
let taskNum = res.data.result.taskInfos.filter(item => type.includes(item.type)).length
console.log(taskNum, otherTaskNum)
for (let i = 0; i < 10; i++) {
res = await api('cash_homePage', {})
res = await this.api('cash_homePage', {})
if (res.data.result.taskInfos.filter(item => type.includes(item.type) && item.doTimes === item.times).length === taskNum) {
console.log('任务全部完成')
break
}
for (let t of res?.data?.result?.taskInfos || []) {
if (t.doTimes < t.times && t.type !== 7) {
console.log(t.name)
data = await api('cash_doTask', {"type": t.type, "taskInfo": t.desc})
await wait(t.duration * 1000 || 1000)
data = await this.api('cash_doTask', {"type": t.type, "taskInfo": t.desc})
await this.wait(t.duration * 1000 || 1000)
if (data.data.bizCode === 0) {
console.log('任务完成', data.data.result.totalMoney ?? '')
break
@@ -45,18 +69,9 @@ let cookie: string = '', res: any = '', data: any, UserName: string
}
}
}
await wait(2000)
await this.wait(2000)
}
}
})()
async function api(fn: string, body: object) {
let sign = getSign(fn, body)
return await post(`https://api.m.jd.com/client.action?functionId=${fn}`, sign, {
'Host': 'api.m.jd.com',
'Cookie': cookie,
'content-type': 'application/x-www-form-urlencoded',
'user-agent': USER_AGENT,
'referer': ''
})
}
new CASH().init().then().catch()