forked from chavyleung/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmcdd.js
More file actions
234 lines (221 loc) · 8.79 KB
/
mcdd.js
File metadata and controls
234 lines (221 loc) · 8.79 KB
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
const chavy = init()
const cookieName = '叮咚买菜'
const KEY_homeurl = 'chavy_home_url_mcdd'
const KEY_homeheader = 'chavy_home_header_mcdd'
const signinfo = {}
let VAL_homeurl = chavy.getdata(KEY_homeurl)
let VAL_homeheader = chavy.getdata(KEY_homeheader)
;(exec = async () => {
chavy.log(`🔔 ${cookieName} 开始签到`)
await signapp()
await getlottery()
if (signinfo.draw_num > 0) for (let i = 0; i < signinfo.draw_num; i++) await lotteryapp(i)
await browseapp()
await getinfo()
showmsg()
})()
.catch((e) => chavy.log(`❌ ${cookieName} 签到失败: ${e}`))
.finally(() => chavy.done())
function getinfo() {
return new Promise((resolve, reject) => {
const url = { url: VAL_homeurl, headers: JSON.parse(VAL_homeheader) }
chavy.get(url, (error, response, data) => {
try {
signinfo.info = JSON.parse(data)
if (typeof signinfo.is_today_sign === 'undefined') signinfo.is_today_sign = signinfo.info.data.user_sign.is_today_sign
resolve()
} catch (e) {
chavy.msg(cookieName, `获取信息: 失败`, `说明: ${e}`)
chavy.log(`❌ ${cookieName} getinfo - 获取信息失败: ${e}`)
chavy.log(`❌ ${cookieName} getinfo - response: ${JSON.stringify(response)}`)
resolve()
}
})
})
}
function signapp() {
return new Promise((resolve, reject) => {
const url = { url: `https://ddxq.mobi/api/v2/user/signin/`, headers: JSON.parse(VAL_homeheader) }
url.headers['Accept'] = '*/*'
url.headers['Origin'] = 'https://activity.m.ddxq.mobi'
url.headers['Accept-Encoding'] = 'gzip, deflate, br'
url.headers['Content-Type'] = 'application/x-www-form-urlencoded'
url.headers['Host'] = 'ddxq.mobi'
url.headers['Connection'] = 'keep-alive'
url.headers['Referer'] = 'https://activity.m.ddxq.mobi/'
url.headers['Content-Length'] = '129'
url.headers['Accept-Language'] = 'zh-cn'
url.body = VAL_homeurl.split('?')[1]
chavy.post(url, (error, response, data) => {
try {
signinfo.signapp = JSON.parse(data)
resolve()
} catch (e) {
chavy.msg(cookieName, `签到结果: 失败`, `说明: ${e}`)
chavy.log(`❌ ${cookieName} signapp - 签到失败: ${e}`)
chavy.log(`❌ ${cookieName} signapp - response: ${JSON.stringify(response)}`)
resolve()
}
})
})
}
function getlottery() {
return new Promise((resolve, reject) => {
const getlotteryurl = `https://maicai.api.ddxq.mobi/lottery/index?${VAL_homeurl.split('?')[1]}&event_id=5dbacee44df3e3ed628ce721`
const url = { url: getlotteryurl, headers: JSON.parse(VAL_homeheader) }
url.headers['Origin'] = 'https://activity.m.ddxq.mobi'
url.headers['Connection'] = 'keep-alive'
url.headers['Accept'] = '*/*'
url.headers['Referer'] = 'https://activity.m.ddxq.mobi/'
url.headers['Host'] = 'maicai.api.ddxq.mobi'
url.headers['Accept-Encoding'] = 'gzip, deflate, br'
url.headers['Accept-Language'] = 'zh-cn'
chavy.get(url, (error, response, data) => {
try {
signinfo.lotteryinfo = JSON.parse(data)
if (typeof signinfo.draw_num === 'undefined') signinfo.draw_num = signinfo.lotteryinfo.data.draw_num
resolve()
} catch (e) {
chavy.msg(cookieName, `获取抽奖: 失败`, `说明: ${e}`)
chavy.log(`❌ ${cookieName} getlottery - 获取抽奖失败: ${e}`)
chavy.log(`❌ ${cookieName} getlottery - response: ${JSON.stringify(response)}`)
resolve()
}
})
})
}
function lotteryapp(cnt) {
return new Promise((resolve, reject) => {
setTimeout(() => {
const lotteryappurl = `https://maicai.api.ddxq.mobi/lottery/draw?${VAL_homeurl.split('?')[1]}&event_id=5dbacee44df3e3ed628ce721`
const url = { url: lotteryappurl, headers: JSON.parse(VAL_homeheader) }
url.headers['Origin'] = 'https://activity.m.ddxq.mobi'
url.headers['Connection'] = 'keep-alive'
url.headers['Accept'] = '*/*'
url.headers['Referer'] = 'https://activity.m.ddxq.mobi/'
url.headers['Host'] = 'maicai.api.ddxq.mobi'
url.headers['Accept-Encoding'] = 'gzip, deflate, br'
url.headers['Accept-Language'] = 'zh-cn'
chavy.get(url, (error, response, data) => {
try {
if (!signinfo.lottery) signinfo.lottery = []
signinfo.lottery.push(JSON.parse(data))
resolve()
} catch (e) {
chavy.msg(cookieName, `获取抽奖: 失败`, `说明: ${e}`)
chavy.log(`❌ ${cookieName} lotteryapp - 获取抽奖失败: ${e}`)
chavy.log(`❌ ${cookieName} lotteryapp - response: ${JSON.stringify(response)}`)
resolve()
}
})
}, cnt * 5000)
})
}
function browseapp() {
return new Promise((resolve, reject) => {
const browseappurl = `https://maicai.api.ddxq.mobi/point/completeTask`
const url = { url: browseappurl, headers: JSON.parse(VAL_homeheader) }
url.body = `${VAL_homeurl.split('?')[1]}&station_id=5500fe01916edfe0738b4e43&task_type=21`
url.headers['Accept'] = '*/*'
url.headers['Origin'] = 'https://maicai.m.ddxq.mobi'
url.headers['Accept-Encoding'] = 'gzip, deflate, br'
url.headers['Content-Type'] = 'application/x-www-form-urlencoded'
url.headers['Host'] = 'maicai.api.ddxq.mobi'
url.headers['Connection'] = 'keep-alive'
url.headers['User-Agent'] = 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 xzone/9.7.5 station_id/5500fe01916edfe0738b4e43'
url.headers['Referer'] = 'https://maicai.m.ddxq.mobi/?v=1.30.0'
url.headers['Content-Length'] = '152'
url.headers['Accept-Language'] = 'zh-cn'
chavy.post(url, (error, response, data) => {
try {
signinfo.browseapp = JSON.parse(data)
resolve()
} catch (e) {
chavy.msg(cookieName, `浏览商品: 失败`, `说明: ${e}`)
chavy.log(`❌ ${cookieName} browseapp - 浏览商品失败: ${e}`)
chavy.log(`❌ ${cookieName} browseapp - response: ${JSON.stringify(response)}`)
resolve()
}
})
})
}
function showmsg() {
let subTitle, detail
if (signinfo.signapp.code == 0) {
if (signinfo.is_today_sign === false) subTitle = '签到: 成功'
else subTitle = '签到: 重复'
detail = `积分: ${signinfo.info.data.point_num} (+${signinfo.signapp.data.point}), 价值: ${signinfo.info.data.point_money}`
} else {
subTitle = '签到: 失败'
detail = `编码: ${signinfo.signapp.code}, 说明: ${signinfo.signapp.message}`
chavy.log(`❌ ${cookieName} showmsg - 签到失败: ${JSON.stringify(signinfo.signapp)}`)
}
if (signinfo.lotteryinfo.code == 0) {
if (signinfo.draw_num == 0) subTitle += '; 抽奖: 已转'
else subTitle += `; 抽奖: ${signinfo.draw_num}次`
} else {
subTitle = '抽奖: 失败'
detail = `编码: ${signinfo.lotteryinfo.code}, 说明: ${signinfo.lotteryinfo.message}`
chavy.log(`❌ ${cookieName} showmsg - 抽奖失败: ${JSON.stringify(signinfo.lotteryinfo)}`)
}
if (signinfo.browseapp.code == 0) {
subTitle += '; 浏览任务: 成功'
} else if (signinfo.browseapp.code == -1) {
subTitle += '; 浏览任务: 重复'
} else {
subTitle = '浏览任务: 失败'
detail = `编码: ${signinfo.browseapp.code}, 说明: ${signinfo.browseapp.msg}`
chavy.log(`❌ ${cookieName} showmsg - 浏览任务失败: ${JSON.stringify(signinfo.browseapp)}`)
}
if (signinfo.lottery) {
detail += '\n查看抽奖详情\n'
for (let i = 0; i < signinfo.lottery.length; i++) {
if (signinfo.lottery[i].code == 0) detail += `\n抽奖 (${i + 1}): ${signinfo.lottery[i].data.prize.title}`
else detail += `\n抽奖 (${i + 1}): ${signinfo.lottery[i].msg}`
}
}
chavy.msg(cookieName, subTitle, detail)
}
function init() {
isSurge = () => {
return undefined === this.$httpClient ? false : true
}
isQuanX = () => {
return undefined === this.$task ? false : true
}
getdata = (key) => {
if (isSurge()) return $persistentStore.read(key)
if (isQuanX()) return $prefs.valueForKey(key)
}
setdata = (key, val) => {
if (isSurge()) return $persistentStore.write(key, val)
if (isQuanX()) return $prefs.setValueForKey(key, val)
}
msg = (title, subtitle, body) => {
if (isSurge()) $notification.post(title, subtitle, body)
if (isQuanX()) $notify(title, subtitle, body)
}
log = (message) => console.log(message)
get = (url, cb) => {
if (isSurge()) {
$httpClient.get(url, cb)
}
if (isQuanX()) {
url.method = 'GET'
$task.fetch(url).then((resp) => cb(null, resp, resp.body))
}
}
post = (url, cb) => {
if (isSurge()) {
$httpClient.post(url, cb)
}
if (isQuanX()) {
url.method = 'POST'
$task.fetch(url).then((resp) => cb(null, resp, resp.body))
}
}
done = (value = {}) => {
$done(value)
}
return { isSurge, isQuanX, msg, log, getdata, setdata, get, post, done }
}