-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathjd_fruit_help.ts
186 lines (177 loc) · 8.23 KB
/
jd_fruit_help.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
/**
* 京东-东东农场-助力
* 所有CK助力顺序
* 内部 -> 助力池
* 和jd_fruit.js同方法自己设置内部码
* 如果没有添加内部码,直接助力助力池
* cron: 35 0,3,5 * * *
*/
import {User, JDHelloWorld} from "./TS_JDHelloWorld"
import {sendNotify} from "./sendNotify";
class Jd_fruit_help extends JDHelloWorld {
user: User
shareCodeSelf: string[] = []
code2user: {} = {}
constructor() {
super("农场助力");
}
async init() {
await this.run(this)
}
randPhoneId() {
return Math.random().toString(36).slice(2, 10) + Math.random().toString(36).slice(2, 10) + Math.random().toString(36).slice(2, 10) + Math.random().toString(36).slice(2, 10) + Math.random().toString(36).slice(2, 10);
}
async main(user: User) {
this.user = user
this.user.UserAgent = `jdapp;iPhone;10.2.0;${Math.ceil(Math.random() * 4 + 10)}.${Math.ceil(Math.random() * 4)};${this.randPhoneId()};network/4g;model/iPhone11,8;addressid/1188016812;appBuild/167724;jdSupportDarkMode/0;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 res: any
try {
res = await this.get(`https://api.m.jd.com/api?functionId=initForFarm&body=${encodeURIComponent(JSON.stringify({version: 4}))}&appid=wh5&clientVersion=9.1.0`, {
"accept": "*/*",
"accept-encoding": "gzip, deflate, br",
"accept-language": "zh-CN,zh;q=0.9",
"cache-control": "no-cache",
"cookie": this.user.cookie,
"origin": "https://home.m.jd.com",
"pragma": "no-cache",
"referer": "https://home.m.jd.com/myJd/newhome.action",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-site",
"User-Agent": this.user.UserAgent,
"Content-Type": "application/x-www-form-urlencoded"
})
if (res.code === '0') {
console.log('助力码', res.farmUserPro.shareCode)
this.shareCodeSelf.push(res.farmUserPro.shareCode)
this.code2user[this.user.UserName] = res.farmUserPro.shareCode
} else {
this.o2s(res, 'initForFarm error')
return {msg: `账号${this.user.index + 1} ${this.user.UserName}\n初始化失败\n${JSON.stringify(res)}`}
}
} catch (e) {
console.log(e.message)
await this.wait(5000)
return {msg: `账号${this.user.index + 1} ${this.user.UserName}\n运行出错\n${e.message}`}
}
}
async help(users: User[]) {
this.o2s(this.shareCodeSelf, '内部助力')
let res: any, full: string [] = [], message: string = ''
for (let user of users) {
try {
this.user = user
this.user.UserAgent = `jdapp;iPhone;10.2.0;${Math.ceil(Math.random() * 4 + 10)}.${Math.ceil(Math.random() * 4)};${this.randPhoneId()};network/4g;model/iPhone11,8;addressid/1188016812;appBuild/167724;jdSupportDarkMode/0;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 myCode: string = this.code2user[this.user.UserName] ?? ""
let shareCodePool: string[] = await this.getShareCodePool('farm', 50)
let shareCode: string[] = [...this.shareCodeSelf, ...shareCodePool]
this.o2s(shareCode, '助力顺序')
for (let code of shareCode) {
console.log(`账号${user.index + 1} ${user.UserName} 去助力 ${code}`)
if (full.includes(code)) {
console.log('full contains')
continue
}
res = await this.get(`https://api.m.jd.com/api?functionId=initForFarm&body=${encodeURIComponent(JSON.stringify({imageUrl: "", nickName: "", "shareCode": code, babelChannel: "3", version: 2, channel: 1}))}&appid=wh5`, {
"Host": "api.m.jd.com",
"Accept": "*/*",
"Origin": "https://carry.m.jd.com",
"Accept-Encoding": "gzip, deflate, br",
"User-Agent": this.user.UserAgent,
"Accept-Language": "zh-CN,zh-Hans;q=0.9",
"Referer": "https://carry.m.jd.com/",
"Cookie": this.user.cookie
})
if (!(res.helpResult && res.helpResult.code)) {
this.o2s(res, '助力出错')
} else if (res.helpResult.code === '0') {
console.log('助力成功,获得', res.helpResult.salveHelpAddWater)
for (let i = 0; i < 5; i++) {
try {
let runTimes: string = await this.get(`https://sharecodepool.cnmb.win/api/runTimes0917?activityId=farm&sharecode=${myCode}&today=${Date.now().toString()}`)
console.log(runTimes)
break
} catch (e) {
console.log(e.message)
await this.wait(this.getRandomNumberByRange(10000, 20000))
}
}
} else if (res.helpResult.code === '7') {
console.log('不给自己助力')
this.user['code'] = code
} else if (res.helpResult.code === '9') {
console.log('已助力')
} else if (res.helpResult.code === '10') {
console.log('已满')
full.push(code)
}
if (res.helpResult.remainTimes === 0) {
console.log('上限')
await this.wait(10000)
break
}
await this.wait(10000)
}
} catch (e) {
console.log(e.message)
await this.wait(10000)
}
await this.wait(5000)
}
for (let user of users) {
try {
this.user = user
this.user.UserAgent = `jdapp;iPhone;10.2.0;${Math.ceil(Math.random() * 4 + 10)}.${Math.ceil(Math.random() * 4)};${this.randPhoneId()};network/4g;model/iPhone11,8;addressid/1188016812;appBuild/167724;jdSupportDarkMode/0;Mozilla/5.0 (iPhone; CPU iPhone OS ${this.getIosVer()} like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1`
res = await this.get(`https://api.m.jd.com/api?functionId=farmAssistInit&body=${encodeURIComponent(JSON.stringify({"version": 14, "channel": 1, "babelChannel": "120"}))}&appid=wh5&clientVersion=9.1.0`, {
"accept": "*/*",
"accept-encoding": "gzip, deflate, br",
"accept-language": "zh-CN,zh;q=0.9",
"cache-control": "no-cache",
"cookie": this.user.cookie,
"origin": "https://home.m.jd.com",
"pragma": "no-cache",
"referer": "https://home.m.jd.com/myJd/newhome.action",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-site",
"User-Agent": this.user.UserAgent,
"Content-Type": "application/x-www-form-urlencoded"
})
if (res.code === '0') {
this.o2s(res)
let assistFriendList: number = res.assistFriendList.length
let farmAssistInit_waterEnergy: number = 0
for (let t of res.assistStageList) {
if (t.stageStaus === 2) {
await this.get(`https://api.m.jd.com/api?functionId=receiveStageEnergy&body=${encodeURIComponent(JSON.stringify({"version": 14, "channel": 1, "babelChannel": "120"}))}&appid=wh5`, {
"Host": "api.m.jd.com",
"Accept": "*/*",
"Origin": "https://carry.m.jd.com",
"Accept-Encoding": "gzip, deflate, br",
"User-Agent": this.user.UserAgent,
"Accept-Language": "zh-CN,zh-Hans;q=0.9",
"Referer": "https://carry.m.jd.com/",
"Cookie": this.user.cookie
})
await this.wait(3000)
farmAssistInit_waterEnergy += t.waterEnergy
} else if (t.stageStaus === 3) {
farmAssistInit_waterEnergy += t.waterEnergy
}
}
console.log('收到助力', assistFriendList)
console.log('助力已领取', farmAssistInit_waterEnergy)
message += `账号${this.user.index + 1} ${this.user.UserName}\n收到助力${assistFriendList}\n助力已领取${farmAssistInit_waterEnergy}\n\n`
} else {
this.o2s(res, 'initForFarm error')
}
} catch (e) {
console.log(e.message)
await this.wait(5000)
}
await this.wait(5000)
}
message && await sendNotify("农场助力", message)
}
}
new Jd_fruit_help().init().then()