forked from chavyleung/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsuning.js
320 lines (304 loc) · 12.4 KB
/
suning.js
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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
const chavy = init()
const cookieName = '苏宁易购'
const KEY_loginurl = 'chavy_login_url_suning'
const KEY_loginbody = 'chavy_login_body_suning'
const KEY_loginheader = 'chavy_login_header_suning'
const KEY_signurl = 'chavy_sign_url_suning'
const KEY_signheader = 'chavy_sign_header_suning'
const KEY_signweburl = 'chavy_signweb_url_suning'
const KEY_signweburlBarry = 'snyg_userTokenKey'
const KEY_signwebheader = 'chavy_signweb_header_suning'
const KEY_signgameurl = 'chavy_signgame_url_suning'
const KEY_signgameheader = 'chavy_signgame_header_suning'
const KEY_signgetgameurl = 'chavy_signgetgame_url_suning'
const KEY_signgetgameheader = 'chavy_signgetgame_header_suning'
const KEY_runflag = 'chavy_runflag_suning'
const signinfo = {}
let VAL_loginurl = chavy.getdata(KEY_loginurl)
let VAL_loginbody = chavy.getdata(KEY_loginbody)
let VAL_loginheader = chavy.getdata(KEY_loginheader)
let VAL_signurl = chavy.getdata(KEY_signurl)
let VAL_signheader = chavy.getdata(KEY_signheader)
let VAL_signweburl = chavy.getdata(KEY_signweburl)
let VAL_signweburlBarry = chavy.getdata(KEY_signweburlBarry)
let VAL_signwebheader = chavy.getdata(KEY_signwebheader)
let VAL_signgameurl = chavy.getdata(KEY_signgameurl)
let VAL_signgameheader = chavy.getdata(KEY_signgameheader)
let VAL_signgetgameurl = chavy.getdata(KEY_signgetgameurl)
let VAL_signgetgameheader = chavy.getdata(KEY_signgetgameheader)
let VAL_runflag = chavy.getdata(KEY_runflag)
;(sign = async () => {
chavy.log(`🔔 ${cookieName}`)
await loginapp()
if (VAL_signurl) await signapp()
await getinfo()
if (VAL_signweburl || VAL_signweburlBarry) await signweb(), await getwebinfo()
if (VAL_signgameurl && VAL_signgetgameurl) await signgame(), await getgameinfo()
showmsg()
chavy.done()
})().catch((e) => chavy.log(`❌ ${cookieName} 签到失败: ${e}`), chavy.done())
function loginapp() {
return new Promise((resolve, reject) => {
const url = { url: VAL_loginurl, body: VAL_loginbody, headers: JSON.parse(VAL_loginheader) }
// chavy.log(`❕ ${cookieName} loginapp - VAL_runflag: ${VAL_runflag}`)
// if (VAL_runflag) delete url.headers['Cookie']
// else chavy.setdata('true', KEY_runflag)
chavy.post(url, (error, response, data) => {
resolve()
})
})
}
function signapp() {
return new Promise((resolve, reject) => {
const url = { url: VAL_signurl, headers: JSON.parse(VAL_signheader) }
delete url.headers['Cookie']
chavy.get(url, (error, response, data) => {
try {
chavy.log(`❕ ${cookieName} signapp - response: ${JSON.stringify(response)}`)
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 signgame() {
return new Promise((resolve, reject) => {
const url = { url: VAL_signgameurl, headers: JSON.parse(VAL_signgameheader) }
delete url.headers['Cookie']
chavy.get(url, (error, response, data) => {
try {
chavy.log(`❕ ${cookieName} signgame - response: ${JSON.stringify(response)}`)
signinfo.signgame = JSON.parse(data)
resolve()
} catch (e) {
chavy.msg(cookieName, `天天低价: 失败`, `说明: ${e}`)
chavy.log(`❌ ${cookieName} signgame - 签到失败: ${e}`)
chavy.log(`❌ ${cookieName} signgame - response: ${JSON.stringify(response)}`)
resolve()
}
})
})
}
function signweb() {
return new Promise((resolve, reject) => {
let url = null
if (VAL_signweburl) {
url = { url: VAL_signweburl, headers: JSON.parse(VAL_signwebheader) }
delete url.headers['Cookie']
url.headers['Host'] = 'luckman.suning.com'
url.headers['Referer'] = 'https: //luckman.suning.com/luck-web/sign/app/index_sign.htm?wx_navbar_transparent=true'
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 SNEBUY-APP 8.5.0 SNCLIENT-WAP'
} else if (VAL_signweburlBarry) {
url = { url: VAL_signweburlBarry, headers: {} }
url.headers['Cookie'] = chavy.getdata('snyg_userCookieKey')
url.headers['Accept'] = 'application/json'
url.headers['Accept-Encoding'] = 'gzip, deflate, br'
url.headers['Connection'] = 'keep-alive'
url.headers['Referer'] = 'https://luckman.suning.com/luck-web/sign/app/index_sign.htm?wx_navbar_transparent=true'
url.headers['Host'] = 'luckman.suning.com'
url.headers['User-Agent'] = chavy.getdata('snyg_userAgentKey')
url.headers['Accept-Language'] = 'en-us'
url.headers['X-Requested-With'] = 'XMLHttpRequest'
}
chavy.get(url, (error, response, data) => {
try {
chavy.log(`❕ ${cookieName} signweb - response: ${JSON.stringify(response)}`)
signinfo.signweb = JSON.parse(data)
resolve()
} catch (e) {
chavy.msg(cookieName, `每日红包: 失败`, `说明: ${e}`)
chavy.log(`❌ ${cookieName} signweb - 每日红包失败: ${e}`)
chavy.log(`❌ ${cookieName} signweb - response: ${JSON.stringify(response)}`)
resolve()
}
})
})
}
function getwebinfo() {
return new Promise((resolve, reject) => {
const timestamp = Math.round(new Date().getTime()).toString()
const VAL_webinfourl = `https://luckman.suning.com/luck-web/sign/api/query/detail/record_sign.do?terminal=app&channel=sign&_=${timestamp}`
const url = { url: VAL_webinfourl, headers: JSON.parse(VAL_signheader) }
delete url.headers['Cookie']
url.headers['Host'] = 'luckman.suning.com'
chavy.get(url, (error, response, data) => {
try {
chavy.log(`❕ ${cookieName} getwebinfo - response: ${JSON.stringify(response)}`)
signinfo.webinfo = JSON.parse(data)
resolve()
} catch (e) {
chavy.msg(cookieName, `领红包结果: 失败`, `说明: ${e}`)
chavy.log(`❌ ${cookieName} getwebinfo - 领红包失败: ${e}`)
chavy.log(`❌ ${cookieName} getwebinfo - response: ${JSON.stringify(response)}`)
resolve()
}
})
})
}
function getgameinfo() {
return new Promise((resolve, reject) => {
const url = { url: VAL_signgetgameurl, headers: JSON.parse(VAL_signgetgameheader) }
delete url.headers['Cookie']
chavy.get(url, (error, response, data) => {
try {
chavy.log(`❕ ${cookieName} getgameinfo - response: ${JSON.stringify(response)}`)
signinfo.gameinfo = JSON.parse(data.match(/\((.*)\)/)[1])
resolve()
} catch (e) {
chavy.msg(cookieName, `查询天天低价: 失败`, `说明: ${e}`)
chavy.log(`❌ ${cookieName} getgameinfo - 查询天天低价失败: ${e}`)
chavy.log(`❌ ${cookieName} getgameinfo - response: ${JSON.stringify(response)}`)
resolve()
}
})
})
}
function getinfo() {
return new Promise((resolve, reject) => {
const timestamp = Math.round(new Date().getTime()).toString()
const url = { url: `https://sign.suning.com/sign-web/m/newsign/getDiamondInfo.do?_=${timestamp}`, headers: JSON.parse(VAL_signheader) }
delete url.headers['Cookie']
chavy.get(url, (error, response, data) => {
try {
chavy.log(`❕ ${cookieName} getinfo - info: ${JSON.stringify(response)}`)
signinfo.info = JSON.parse(data)
resolve()
} catch (e) {
chavy.msg(cookieName, `获取签到信息: 失败`, `说明: ${e}`)
chavy.log(`❌ ${cookieName} getinfo - 获取签到信息失败: ${e}`)
chavy.log(`❌ ${cookieName} getinfo - response: ${JSON.stringify(response)}`)
resolve()
}
})
})
}
function showmsg() {
let subTitle = ''
let detail = ''
let moreDetail = ''
if (signinfo.signapp && signinfo.signapp.code == '1') {
if (signinfo.signapp.data.todayFirstSignFlag == true) subTitle = '签到: 成功'
else subTitle = '签到: 重复'
for (myinfo of signinfo.info.data) {
detail += detail == '' ? '总共: ' : ', '
detail += myinfo.showLabel
}
if (signinfo.signapp.data.prizeLists) {
detail += `, 说明: 还有${signinfo.signapp.data.remainingPoint}云钻待领取`
const prizeLists = signinfo.signapp.data.prizeLists
const customerDays = signinfo.signapp.data.customerDays
const prize = prizeLists[customerDays - 1]
moreDetail += moreDetail == '' ? '' : '\n'
moreDetail += '\n💎 每日签到: '
for (res of prize) moreDetail += `\n${res.prizeName}: ${res.prizeContent}`
}
} else {
subTitle = '签到: 失败'
chavy.log(`❌ ${cookieName} showmsg - 每日签到: ${JSON.stringify(signinfo.signapp)}`)
}
subTitle += subTitle == '' ? '' : ', '
if (signinfo.signweb) {
if (signinfo.signweb.respCode == '1') {
subTitle += '红包: 成功'
} else if (signinfo.signweb.respCode == '70512') {
subTitle += '红包: 重复'
} else {
subTitle += '红包: 失败'
chavy.log(`❌ ${cookieName} showmsg - 每日红包 - signweb: ${JSON.stringify(signinfo.signweb)}`)
}
} else {
subTitle += '红包: 失败'
chavy.log(`❌ ${cookieName} showmsg - 每日红包 - signweb: ${JSON.stringify(signinfo.signweb)}`)
}
subTitle += subTitle == '' ? '' : ', '
if (signinfo.signgame && signinfo.signgame.code == '1') {
if (signinfo.signgame.data.resultCode == 'SG0000') {
subTitle += '低价: 成功'
} else if (signinfo.signgame.data.resultCode == 'SG0103') {
subTitle += '低价: 重复'
} else {
subTitle += '低价: 失败'
chavy.log(`❌ ${cookieName} showmsg - 每日红包 - signgame: ${JSON.stringify(signinfo.signgame)}`)
}
} else {
subTitle += '低价: 失败'
chavy.log(`❌ ${cookieName} showmsg - 每日红包 - signgame: ${JSON.stringify(signinfo.signgame)}`)
}
if (signinfo.webinfo && signinfo.webinfo.respData) {
const currentIndex = signinfo.webinfo.respData.currentIndex
const detailTreeMap = signinfo.webinfo.respData.detailTreeMap
const currentMap = detailTreeMap[currentIndex]
if (currentMap.signMark == true) {
moreDetail += moreDetail == '' ? '' : '\n'
moreDetail += '\n🧧 每日红包: '
for (res of currentMap.resList) moreDetail += `\n${res.remark}: ${res.amount}`
} else {
chavy.log(`❌ ${cookieName} showmsg - 每日红包 - webinfo: ${JSON.stringify(signinfo.webinfo)}`)
}
} else {
chavy.log(`❌ ${cookieName} showmsg - 每日红包 - webinfo: ${JSON.stringify(signinfo.webinfo)}`)
}
if (signinfo.signgame && signinfo.gameinfo && signinfo.gameinfo.code == 1) {
if (signinfo.gameinfo.data.resultCode == 0000) {
moreDetail += moreDetail == '' ? '' : '\n'
moreDetail += '\n💰 天天低价: '
for (d of signinfo.gameinfo.data.result.datas)
if (d.obj) moreDetail += `\n${d.obj.couponRuleName} (${d.obj.remainValue}元)`
else moreDetail += `\n${d.basePrizeEntity.prizeName} (${d.basePrizeEntity.prizeRules})`
} else {
chavy.log(`❌ ${cookieName} showmsg - 天天低价 - gameinfo: ${JSON.stringify(signinfo.gameinfo)}`)
}
} else {
chavy.log(`❌ ${cookieName} showmsg - 天天低价 - gameinfo: ${JSON.stringify(signinfo.gameinfo)}`)
}
if (moreDetail) detail += `\n查看签到详情\n${moreDetail}`
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 }
}