-
Notifications
You must be signed in to change notification settings - Fork 0
/
jd_jxgc.ts
202 lines (187 loc) · 7.08 KB
/
jd_jxgc.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
/**
* 京喜工厂
* cron: 30 * * * *
*/
import axios from "axios"
import * as path from "path"
import {format} from 'date-fns'
import {sendNotify} from './sendNotify'
import {requireConfig, wait, exceptCookie, randomWord} from "./TS_USER_AGENTS"
import {requestAlgo, geth5st} from "./utils/V3";
let cookie: string = '', res: any = '', UserName: string
interface Params {
bizCode?: string,
name?: string,
pin?: string,
sharePin?: string,
shareType?: string,
materialTuanPin?: string,
materialTuanId?: string,
needPickSiteInfo?: number,
source?: string,
productionId?: number,
date?: string,
taskId?: number,
configExtra?: string,
factoryid?: number,
querytype?: number,
apptoken?: string,
pgtimestamp?: string,
phoneID?: string,
doubleflag?: number,
timeStamp?: string,
showAreaTaskFlag?: number,
}
!(async () => {
await requestAlgo('c0ff1')
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
}
res = await api('userinfo/GetUserInfo', '_time,materialTuanId,materialTuanPin,needPickSiteInfo,pin,sharePin,shareType,source,zone', {pin: '', sharePin: '', shareType: '', materialTuanPin: '', materialTuanId: '', needPickSiteInfo: 0, source: ''})
let productionId: number = 0, factoryId: number = 0
await wait(2000)
try {
productionId = res.data.productionList[0].productionId
factoryId = res.data.factoryList[0].factoryId
let investedElectric: number = res.data.productionList[0].investedElectric, needElectric: number = res.data.productionList[0].needElectric, progress: string = (investedElectric / needElectric * 100).toFixed(2)
console.log('生产进度:', progress)
if (progress === '100.00') {
sendNotify("京喜工厂生产完成", `账号${index + 1} ${UserName}`)
continue
}
} catch (e) {
console.log('当前没有产品在生产')
continue
}
// 开红包
if (res.data.productionStage.productionStageAwardStatus === 1) {
res = await api('userinfo/DrawProductionStagePrize', '_time,productionId,zone', {productionId: productionId})
console.log('打开红包:', res.data.active)
await wait(4000)
}
// 收发电机
res = await api('generator/QueryCurrentElectricityQuantity', '_time,factoryid,querytype,zone', {factoryid: factoryId, querytype: 1})
await wait(2000)
let flag: number = -1
if (res.data.nextCollectDoubleFlag === 1) {
// 下次双倍
if (res.data.currentElectricityQuantity === res.data.maxElectricityQuantity) {
// 发电机满
flag = 1
} else {
console.log('发电机可收取双倍,但没满')
}
} else {
// 没有双倍,直接收
flag = 0
}
if (flag !== -1) {
res = await api('generator/CollectCurrentElectricity', '_time,apptoken,doubleflag,factoryid,pgtimestamp,phoneID,zone', {apptoken: '', pgtimestamp: '', phoneID: '', factoryid: factoryId, doubleflag: flag, timeStamp: 'undefined'})
res.ret === 0
? console.log('发电机收取成功:', res.data.CollectElectricity)
: console.log('发电机收取失败:', res)
}
await wait(4000)
// 投入电力
for (let j = 0; j < 2; j++) {
res = await api('userinfo/InvestElectric', '_time,productionId,zone', {productionId: productionId})
if (res.ret === 0) {
console.log('投入电力成功:', res.data.investElectric)
} else {
console.log('投入电力失败:', res)
break
}
await wait(3000)
}
res = await api('friend/QueryHireReward', '_time,zone')
await wait(2000)
for (let t of res.data.hireReward) {
if (t.date !== format(Date.now(), "yyyyMMdd") && new Date().getHours() >= 6) {
res = await api('friend/HireAward', '_time,date,type,zone', {date: t.date})
await wait(2000)
if (res.ret === 0)
console.log('收取气泡成功:', t.electricityQuantity)
}
}
console.log('任务列表开始')
for (let j = 0; j < 30; j++) {
if (await task() === 0) {
break
}
await wait(5000)
}
console.log('任务列表结束')
}
})()
async function task() {
res = await api('GetUserTaskStatusList', '_time,bizCode,showAreaTaskFlag,source', {showAreaTaskFlag: 1, bizCode: 'dream_factory'})
console.log('GetUserTaskStatusList: 刷新任务列表')
await wait(3000)
for (let t of res.data.userTaskStatusList) {
if (t.awardStatus === 2) {
if (t.completedTimes >= t.targetTimes) {
console.log('可领奖:', t.taskName)
res = await api('Award', '_time,bizCode,source,taskId', {taskId: t.taskId, bizCode: t.bizCode})
if (res.ret === 0) {
console.log('领奖成功:', res.data.prizeInfo.trim() * 1)
await wait(4000)
return 1
} else {
console.log('领奖出错')
return 0
}
}
if (t.dateType === 2 && t.completedTimes < t.targetTimes && [2, 6, 9].indexOf(t.taskType) > -1) {
console.log('任务开始:', t.taskName)
res = await api('DoTask', '_time,_ts,bizCode,configExtra,source,taskId', {taskId: t.taskId, bizCode: t.bizCode, configExtra: ''})
await wait(5000)
if (res.ret === 0) {
console.log('任务完成')
await wait(3000)
return 1
} else {
console.log('任务失败')
return 0
}
}
}
}
return 0
}
async function api(fn: string, stk: string, params: Params = {}) {
let url: string, timestamp = Date.now()
let t: { key: string, value: string } [] = [
{key: '_time', value: timestamp.toString()},
{key: '_ts', value: timestamp.toString()},
{key: 'bizCode', value: 'dream_factory'},
{key: 'source', value: 'dreamfactory'},
]
let w: string = randomWord()
if (['GetUserTaskStatusList', 'DoTask', 'Award'].includes(fn))
url = `https://m.jingxi.com/newtasksys/newtasksys_front/${fn}?source=dreamfactory&_time=${timestamp}&_ts=${timestamp}&_stk=${encodeURIComponent(stk)}&_=${timestamp + 3}&sceneval=2&g_login_type=1&callback=jsonpCBK${w}${w}&g_ty=ls`
else
url = `https://m.jingxi.com/dreamfactory/${fn}?zone=dream_factory&_time=${timestamp}&_stk=${encodeURIComponent(stk)}&_ste=1&_=${timestamp + 3}&sceneval=2&g_login_type=1&callback=jsonpCBK${w}${w}&g_ty=ls`
for (let [key, value] of Object.entries(params)) {
t.push({key, value})
url += `&${key}=${value}`
}
let h5st = geth5st(t, 'c0ff1')
url += `&h5st=${encodeURIComponent(h5st)}`
let {data} = await axios.get(url, {
headers: {
'Host': 'm.jingxi.com',
'User-Agent': 'jdpingou;',
'Accept-Language': 'zh-CN,zh-Hans;q=0.9',
'Referer': 'https://st.jingxi.com/',
'Cookie': cookie
}
})
return JSON.parse(data.match(/try.?{jsonpCBK.?.?\((.*)/)[1])
}