-
Notifications
You must be signed in to change notification settings - Fork 1k
/
jd_joy_park_run.ts
261 lines (238 loc) · 10.5 KB
/
jd_joy_park_run.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
/**
* 汪汪乐园-跑步+组队+浏览
* cron: 20 * * * *
* export FP_448DE=""
* export FP_B6AC3=""
*/
import {H5ST} from "./utils/h5st_pro"
import {getDate} from "date-fns";
import {JDHelloWorld, User} from "./TS_JDHelloWorld";
class Joy_Park_Run extends JDHelloWorld {
teamTool: H5ST
apiTool: H5ST
user: User
captainId: string | number
constructor() {
super()
}
async init() {
await this.run(this)
}
// 秒转分:秒
secondsToMinutes(seconds: number) {
let minutes: number = Math.floor(seconds / 60)
let second: number = Math.floor(seconds % 60)
return `${minutes}分${second}秒`
}
async team(fn: string, body: object) {
let timestamp: number = Date.now(), h5st: string
h5st = await this.teamTool.__genH5st({
appid: "activities_platform",
body: JSON.stringify(body),
client: "ios",
clientVersion: "3.9.2",
functionId: fn,
t: timestamp.toString()
})
return await this.get(`https://api.m.jd.com/?functionId=${fn}&body=${encodeURIComponent(JSON.stringify(body))}&t=${timestamp}&appid=activities_platform&client=ios&clientVersion=3.9.2&cthr=1&h5st=${h5st}`, {
'Host': 'api.m.jd.com',
'User-Agent': this.user.UserAgent,
'Origin': 'https://h5platform.jd.com',
'X-Requested-With': 'com.jd.jdlite',
'Referer': 'https://h5platform.jd.com/',
'Cookie': this.user.cookie
})
}
async api(fn: string, body: object) {
let timestamp: number = Date.now(), h5st: string = ''
if (fn === 'runningOpenBox') {
h5st = await this.apiTool.__genH5st({
appid: "activities_platform",
body: JSON.stringify(body),
client: "ios",
clientVersion: "3.9.2",
functionId: fn,
t: timestamp.toString()
})
}
let params: string = `functionId=${fn}&body=${JSON.stringify(body)}&t=${timestamp}&appid=activities_platform&client=ios&clientVersion=3.9.2&cthr=1`
h5st && (params += `&h5st=${h5st}`)
return await this.post('https://api.m.jd.com/', params, {
'authority': 'api.m.jd.com',
'content-type': 'application/x-www-form-urlencoded',
'cookie': this.user.cookie,
'origin': 'https://h5platform.jd.com',
'referer': 'https://h5platform.jd.com/',
'User-Agent': this.user.UserAgent,
})
}
async runningPageHome() {
return this.get(`https://api.m.jd.com/?functionId=runningPageHome&body=%7B%22linkId%22:%22L-sOanK_5RJCz7I314FpnQ%22,%22isFromJoyPark%22:true,%22joyLinkId%22:%22LsQNxL7iWDlXUs6cFl-AAg%22%7D&t=${Date.now()}&appid=activities_platform&client=ios&clientVersion=3.9.2`, {
'Host': 'api.m.jd.com',
'Origin': 'https://h5platform.jd.com',
'User-Agent': this.user.UserAgent,
'Referer': 'https://h5platform.jd.com/',
'Cookie': this.user.cookie
})
}
async startRunning(res: any, assets: number) {
if (!res.data.runningHomeInfo.nextRunningTime) {
console.log('终点目标', assets)
for (let i = 0; i < 5; i++) {
res = await this.api('runningOpenBox', {"linkId": "L-sOanK_5RJCz7I314FpnQ"})
if (parseFloat(res.data.assets) >= assets) {
assets = parseFloat(res.data.assets)
res = await this.api('runningFail', {"linkId": "L-sOanK_5RJCz7I314FpnQ"})
this.o2s(res, 'runningFail')
res = await this.api('runningPreserveAssets', {"linkId": "L-sOanK_5RJCz7I314FpnQ"})
console.log('领取成功', assets)
break
} else {
if (res.data.doubleSuccess) {
console.log('翻倍成功', parseFloat(res.data.assets))
await this.wait(10000)
} else if (!res.data.doubleSuccess && !res.data.runningHomeInfo.runningFinish) {
console.log('开始跑步', parseFloat(res.data.assets))
await this.wait(10000)
} else {
console.log('翻倍失败')
break
}
}
}
}
await this.wait(3000)
}
async main(user: User) {
this.user = user
this.user.UserAgent = `jdltapp;iPhone;3.9.2;Mozilla/5.0 (iPhone; CPU iPhone OS ${this.getIosVer()} like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1;`
let assets: number = parseFloat(process.env.JD_JOY_PARK_RUN_ASSETS || '0.08')
let rewardAmount: number = 0
try {
this.teamTool = new H5ST('448de', this.user.UserAgent, process.env.FP_448DE || "", 'https://h5platform.jd.com/swm-stable/people-run/index?activityId=L-sOanK_5RJCz7I314FpnQ', 'https://h5platform.jd.com')
await this.teamTool.__genAlgo()
let res: any, apTaskList: any
apTaskList = await this.api('apTaskList', {"linkId": "LsQNxL7iWDlXUs6cFl-AAg"})
for (let t of apTaskList.data) {
if (t.taskType === 'BROWSE_CHANNEL' && !t.taskFinished) {
console.log(t.taskTitle)
res = await this.api('apDoTask', {"taskType": t.taskType, "taskId": t.id, "itemId": encodeURIComponent(t.taskSourceUrl), "linkId": "LsQNxL7iWDlXUs6cFl-AAg"})
res.success ? console.log('任务完成') : this.o2s(res, '任务失败')
await this.wait(1000)
res = await this.api('apTaskDrawAward', {"taskType": t.taskType, "taskId": t.id, "linkId": "LsQNxL7iWDlXUs6cFl-AAg"})
res.success ? console.log('领奖成功', res.data[0].awardGivenNumber) : this.o2s(res, '领奖失败')
}
}
apTaskList = await this.api('apTaskList', {"linkId": "L-sOanK_5RJCz7I314FpnQ"})
for (let t of apTaskList.data) {
if (t.taskShowTitle === '逛会场得生命值' && !t.taskFinished) {
let apTaskDetail: any = await this.api('apTaskDetail', {"linkId": "L-sOanK_5RJCz7I314FpnQ", "taskType": "BROWSE_CHANNEL", "taskId": t.id, "channel": 4})
await this.wait(1000)
let taskItemList = apTaskDetail.data.taskItemList
for (let i = apTaskDetail.data.status.userFinishedTimes; i < apTaskDetail.data.status.finishNeed; i++) {
console.log(taskItemList[i].itemName)
res = await this.api('apTaskTimeRecord', {"linkId": "L-sOanK_5RJCz7I314FpnQ", "taskId": 817})
await this.wait(31000)
res = await this.api('apDoTask', {"linkId": "L-sOanK_5RJCz7I314FpnQ", "taskType": "BROWSE_CHANNEL", "taskId": t.id, "channel": 4, "itemId": encodeURIComponent(taskItemList[i].itemId), "checkVersion": true})
if (res.success) {
console.log('任务完成')
} else {
this.o2s(res, '任务失败')
}
await this.wait(3000)
}
}
}
await this.wait(2000)
res = await this.team('runningMyPrize', {"linkId": "L-sOanK_5RJCz7I314FpnQ", "pageSize": 20, "time": null, "ids": null})
// res = await this.team('runningMyPrize', {"linkId": "L-sOanK_5RJCz7I314FpnQ", "pageSize": 10, "time": 1660943842000, "ids": [1263040]})
// this.o2s(res)
let sum: number = 0, success: number = 0
rewardAmount = res.data.rewardAmount
if (res.data.runningCashStatus.currentEndTime && res.data.runningCashStatus.status === 0) {
console.log('可提现', rewardAmount)
res = await this.api('runningPrizeDraw', {"linkId": "L-sOanK_5RJCz7I314FpnQ", "type": 2})
await this.wait(2000)
console.log(res.data.message)
res = await this.team('runningMyPrize', {"linkId": "L-sOanK_5RJCz7I314FpnQ", "pageSize": 20, "time": null, "ids": null})
}
for (let t of res?.data?.detailVos || []) {
if (t.amount > 0 && getDate(new Date(t.createTime)) === new Date().getDate()) {
sum += t.amount
success++
} else {
break
}
}
console.log('成功', success)
sum = parseFloat(sum.toFixed(2))
console.log('收益', sum)
res = await this.team('runningTeamInfo', {"linkId": "L-sOanK_5RJCz7I314FpnQ"})
if (!this.captainId) {
if (res.data.members.length === 0) {
console.log('成为队长')
this.captainId = res.data.captainId
} else if (res.data.members.length !== 6) {
console.log('队伍未满', res.data.members.length)
this.captainId = res.data.captainId
} else {
console.log('队伍已满')
}
} else if (this.captainId && res.data.members.length === 0) {
console.log('已有组队ID,未加入队伍')
res = await this.team('runningJoinTeam', {"linkId": "L-sOanK_5RJCz7I314FpnQ", "captainId": this.captainId})
if (res.code === 0) {
console.log('组队成功')
for (let member of res.data.members) {
if (member.captain) {
console.log('队长', member.nickName)
break
}
}
if (res.data.members.length === 6) {
console.log('队伍已满')
this.captainId = ''
}
} else {
this.o2s(res, '组队失败')
}
} else {
console.log('已组队', res.data.members.length)
console.log('战队收益', res.data.teamSumPrize)
}
this.apiTool = new H5ST('b6ac3', this.user.UserAgent, process.env.FP_B6AC3 || "", 'https://h5platform.jd.com/swm-stable/people-run/index?activityId=L-sOanK_5RJCz7I314FpnQ', 'https://h5platform.jd.com')
await this.apiTool.__genAlgo()
res = await this.runningPageHome()
console.log('🧧', res.data.runningHomeInfo.prizeValue)
console.log('💊', res.data.runningHomeInfo.energy)
let energy: number = res.data.runningHomeInfo.energy
await this.wait(2000)
console.log('⏳', this.secondsToMinutes(res.data.runningHomeInfo.nextRunningTime / 1000))
if (res.data.runningHomeInfo.nextRunningTime && res.data.runningHomeInfo.nextRunningTime / 1000 < 300) {
console.log('⏳')
await this.wait(res.data.runningHomeInfo.nextRunningTime + 3000)
res = await this.runningPageHome()
await this.wait(1000)
}
await this.startRunning(res, assets)
res = await this.runningPageHome()
for (let i = 0; i < energy; i++) {
if (res.data.runningHomeInfo.nextRunningTime / 1000 < 3000 || new Date().getHours() > 15)
break
console.log('💉')
res = await this.api('runningUseEnergyBar', {"linkId": "L-sOanK_5RJCz7I314FpnQ"})
console.log(res.errMsg)
res = await this.runningPageHome()
await this.startRunning(res, assets)
await this.wait(1000)
}
res = await this.runningPageHome()
console.log('🧧', res.data.runningHomeInfo.prizeValue)
await this.wait(2000)
} catch (e) {
console.log('Error', e.message)
await this.wait(3000)
}
}
}
new Joy_Park_Run().init().then()