forked from Toulu-debug/enen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjd_jinli_hongbao.ts
219 lines (206 loc) · 8.32 KB
/
jd_jinli_hongbao.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
/**
* 京东-锦鲤红包
* 只获取前9CK,再多403
* 只有助力,红包手动开
* cron: 1 0,6,18 * * *
* CK1 HW.ts -> 内部
* CK2~9 内部 -> HW.ts
*/
import axios from 'axios'
import {sendNotify} from './sendNotify'
import {get, getshareCodeHW, o2s, randomString, requireConfig, wait} from "./TS_USER_AGENTS"
import {Md5} from "ts-md5"
let cookie: string = '', cookiesArr: string[] = [], res: any = '', UserName: string, UA: string = ''
let shareCodesSelf: string[] = [], shareCodes: string[] = [], shareCodesHW: string[] = [], fullCode: string[] = []
let min: number[] = [0.02, 0.12, 0.3, 0.4, 0.6, 0.7, 0.8, 1, 1.2, 2, 3.6]
let log: string = ''
!(async () => {
cookiesArr = await requireConfig(false)
cookiesArr = cookiesArr.slice(0, 9)
await join()
await getShareCodeSelf()
await help()
// await open(false)
})()
async function getShareCodeSelf() {
for (let [index, value] of cookiesArr.entries()) {
try {
cookie = value
UserName = decodeURIComponent(cookie.match(/pt_pin=([^;]*)/)![1])
console.log(`\n开始【京东账号${index + 1}】${UserName}\n`)
UA = `jdltapp;iPhone;3.1.0;${Math.ceil(Math.random() * 4 + 10)}.${Math.ceil(Math.random() * 4)};${randomString(40)}`
res = await api('h5activityIndex', {"isjdapp": 1})
console.log('红包ID:', res.data.result.redpacketInfo.id)
shareCodesSelf.push(res.data.result.redpacketInfo.id)
await wait(1000)
} catch (e) {
console.log(e)
}
}
o2s(shareCodesSelf)
}
async function join() {
for (let [index, value] of cookiesArr.entries()) {
try {
cookie = value
UserName = decodeURIComponent(cookie.match(/pt_pin=([^;]*)/)![1])
console.log(`\n开始【京东账号${index + 1}】${UserName}\n`)
for (let i = 0; i < 5; i++) {
try {
UA = `jdltapp;iPhone;3.1.0;${Math.ceil(Math.random() * 4 + 10)}.${Math.ceil(Math.random() * 4)};${randomString(40)}`
log = await getLog()
let random = log.match(/"random":"(\d+)"/)[1], log1 = log.match(/"log":"(.*)"/)[1]
res = await api('h5launch', {"followShop": 0, "random": random, "log": log1, "sceneid": "JLHBhPageh5"})
console.log('活动初始化:', res.data.result.statusDesc)
await wait(1000)
break
} catch (e) {
await wait(3000)
}
}
} catch (e) {
console.log(e)
}
}
}
async function open(autoOpen: boolean = false) {
let exitOpen: boolean = false
for (let [index, value] of cookiesArr.entries()) {
if (exitOpen)
break
try {
cookie = value
UserName = decodeURIComponent(cookie.match(/pt_pin=([^;]*)/)![1])
console.log(`\n开始【京东账号${index + 1}】${UserName}\n`)
let j: number = 1
res = await api('h5activityIndex', {"isjdapp": 1})
for (let t of res.data.result.redpacketConfigFillRewardInfo) {
if (t.packetStatus === 2) {
console.log(`红包${j}已拆过,获得`, t.packetAmount)
if (!min.includes(t.packetAmount)) {
await sendNotify('锦鲤红包', `账号${index + 1} ${UserName}\n${t.packetAmount}`)
}
} else if (t.packetStatus === 1) {
console.log(`红包${j}可拆`)
if (autoOpen) {
UA = `jdltapp;iPhone;3.1.0;${Math.ceil(Math.random() * 4 + 10)}.${Math.ceil(Math.random() * 4)};${randomString(40)}`
log = await getLog()
let random = log.match(/"random":"(\d+)"/)[1], log1 = log.match(/"log":"(.*)"/)[1]
res = await api('h5receiveRedpacketAll', {"random": random, "log": log1, "sceneid": "JLHBhPageh5"})
console.log('打开成功', parseFloat(res.data.result.discount))
if (!min.includes(parseFloat(res.data.result.discount))) {
await sendNotify('锦鲤红包', `账号${index + 1} ${UserName}\n${t.packetAmount}`)
}
await wait(10000)
}
} else {
console.log(`${j}`, t.hasAssistNum, '/', t.requireAssistNum)
}
j++
}
} catch (e) {
console.log(e)
}
await wait(3000)
}
}
async function help() {
for (let [index, value] of cookiesArr.entries()) {
try {
cookie = value
UserName = decodeURIComponent(cookie.match(/pt_pin=([^;]*)/)![1])
if (shareCodesHW.length === 0) {
shareCodesHW = await getshareCodeHW('jlhb')
}
// 1 3 5 5 9 15
if (index === 0) {
shareCodes = Array.from(new Set([...shareCodesHW, ...shareCodesSelf]))
} else {
shareCodes = Array.from(new Set([...shareCodesSelf, ...shareCodesHW]))
}
// 剩余账号无法助力满下一级红包
// if (cookiesArr.length === 4 && index === 3) {
// shareCodes = Array.from(new Set([...shareCodesHW, ...shareCodesSelf]))
// }
// else if ([11, 12, 13, 14].includes(cookiesArr.length) && index > 10) {
// shareCodes = Array.from(new Set([...shareCodesHW, ...shareCodesSelf]))
// }
let remain: number = 1
for (let code of shareCodes) {
if (!fullCode.includes(code)) {
if (!remain) {
break
}
for (let i = 0; i < 5; i++) {
UA = `jdltapp;iPhone;3.1.0;${Math.ceil(Math.random() * 4 + 10)}.${Math.ceil(Math.random() * 4)};${randomString(40)}`
log = await getLog()
let random = log.match(/"random":"(\d+)"/)[1], log1 = log.match(/"log":"(.*)"/)[1]
console.log(`账号${index + 1} ${UserName} 去助力 ${code} ${shareCodesSelf.includes(code) ? '*内部*' : ''}`)
res = await api('jinli_h5assist', {"redPacketId": code, "followShop": 0, "random": random, "log": log1, "sceneid": "JLHBhPageh5"})
// o2s(res, 'jinli_h5assist')
if (res.rtn_code !== 0) {
console.log('log无效')
} else {
if (res.data.result.status === 0) {
console.log('助力成功:', parseFloat(res.data.result.assistReward.discount))
await wait(45000)
remain = 0
break
} else if (res.data.result.status === 3) {
console.log('今日助力次数已满')
await wait(45000)
remain = 0
break
} else if (res.data.result.statusDesc === '抱歉,你不能为自己助力哦') {
console.log('不能助力自己')
remain = 0
await wait(45000)
break
} else {
console.log('助力结果:', res.data.result.statusDesc)
if (res.data.result.statusDesc === '啊偶,TA的助力已满,开启自己的红包活动吧~') {
fullCode.push(code)
}
}
}
await wait(45000)
}
}
}
} catch (e) {
console.log(e)
}
}
}
async function api(fn: string, body: object) {
let {data} = await axios.post(`https://api.m.jd.com/api?appid=jinlihongbao&functionId=${fn}&loginType=2&client=jinlihongbao&clientVersion=10.2.4&osVersion=AndroidOS&d_brand=Xiaomi&d_model=Xiaomi`, `body=${encodeURIComponent(JSON.stringify(body))}`, {
headers: {
"Cookie": cookie,
"origin": "https://h5.m.jd.com",
"referer": "https://h5.m.jd.com/babelDiy/Zeus/2NUvze9e1uWf4amBhe1AV6ynmSuH/index.html",
'Content-Type': 'application/x-www-form-urlencoded',
"X-Requested-With": "com.jingdong.app.mall",
"User-Agent": "Mozilla/5.0 (Linux; U; Android 8.0.0; zh-cn; Mi Note 2 Build/OPR1.170623.032) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/61.0.3163.128 Mobile Safari/537.36 XiaoMi/MiuiBrowser/10.1.1",
}
})
return data
}
async function getLog() {
// let farm: string = await getFarmShareCode(cookie)
// await wait(1000)
// let bean: string = await getBeanShareCode(cookie)
// let pt_pin: string = encodeURIComponent(UserName)
// if (farm.length > 0 && bean.length > 0) {
// res = await get(`https://api.jdsharecode.xyz/api/jlhb_log?farm=${farm}&bean=${bean}&pin=${Md5.hashStr(pt_pin)}`)
res = await get(`https://api.jdsharecode.xyz/api/jlhb_log?farm=farm&bean=bean&pin=pin`)
if (res === 1) {
console.log('一致性验证失败,脚本退出')
process.exit(0)
} else {
return res
}
// } else {
// console.log('获取账号助力码失败,脚本退出')
// process.exit(0)
// }
}