-
-
Notifications
You must be signed in to change notification settings - Fork 168
/
Copy pathsmzdm_checkin.js
294 lines (226 loc) · 6.15 KB
/
smzdm_checkin.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
/*
smzdm 签到脚本
项目地址: https://github.com/hex-ci/smzdm_script
cron: 10 8 * * *
*/
const Env = require('./env');
const { SmzdmBot, requestApi, removeTags, getEnvCookies, wait } = require('./bot');
const notify = require('./sendNotify');
const CryptoJS = require('crypto-js');
// ------------------------------------
const $ = new Env('smzdm 签到');
class SmzdmCheckinBot extends SmzdmBot {
constructor(cookie, sk) {
super(cookie);
this.sk = sk ? sk.trim() : '';
}
async run() {
const { msg: msg1 } = await this.checkin();
const { msg: msg2 } = await this.allReward();
const { msg: msg3 } = await this.extraReward();
return `${msg1}${msg2}${msg3}`;
}
async checkin() {
const { isSuccess, data, response } = await requestApi('https://user-api.smzdm.com/checkin', {
method: 'post',
headers: this.getHeaders(),
data: {
touchstone_event: '',
sk: this.sk || '1',
token: this.token,
captcha: ''
}
});
if (isSuccess) {
let msg = `⭐签到成功${data.data.daily_num}天
🏅金币: ${data.data.cgold}
🏅碎银: ${data.data.pre_re_silver}
🏅补签卡: ${data.data.cards}`;
await wait(3, 10);
const vip = await this.getVipInfo();
if (vip) {
msg += `\n🏅经验: ${vip.vip.exp_current}
🏅值会员等级: ${vip.vip.exp_level}
🏅值会员经验: ${vip.vip.exp_current_level}
🏅值会员有效期至: ${vip.vip.exp_level_expire}`;
}
$.log(`${msg}\n`);
return {
isSuccess,
msg: `${msg}\n\n`
};
}
else {
$.log(`签到失败!${response}`);
return {
isSuccess,
msg: '签到失败!'
};
}
}
async allReward() {
const { isSuccess, data, response } = await requestApi('https://user-api.smzdm.com/checkin/all_reward', {
method: 'post',
headers: this.getHeaders(),
debug: process.env.SMZDM_DEBUG
});
if (isSuccess) {
const msg1 = `${data.data.normal_reward.reward_add.title}: ${data.data.normal_reward.reward_add.content}`;
let msg2 = '';
if (data.data.normal_reward.gift.title) {
msg2 = `${data.data.normal_reward.gift.title}: ${data.data.normal_reward.gift.content_str}`;
}
else {
msg2 = `${data.data.normal_reward.gift.sub_content}`;
}
$.log(`${msg1}\n${msg2}\n`);
return {
isSuccess,
msg: `${msg1}\n${msg2}\n\n`
};
}
else {
if (data.error_code != '4') {
$.log(`查询奖励失败!${response}`);
}
return {
isSuccess,
msg: ''
};
}
}
async extraReward() {
const isContinue = await this.isContinueCheckin();
if (!isContinue) {
const msg = '今天没有额外奖励';
$.log(`${msg}\n`);
return {
isSuccess: false,
msg: `${msg}\n`
};
}
await wait(5, 10);
const { isSuccess, data, response } = await requestApi('https://user-api.smzdm.com/checkin/extra_reward', {
method: 'post',
headers: this.getHeaders()
});
if (isSuccess) {
const msg = `${data.data.title}: ${removeTags(data.data.gift.content)}`;
$.log(msg);
return {
isSuccess: true,
msg: `${msg}\n`
};
}
else {
$.log(`领取额外奖励失败!${response}`);
return {
isSuccess: false,
msg: ''
};
}
}
async isContinueCheckin() {
const { isSuccess, data, response } = await requestApi('https://user-api.smzdm.com/checkin/show_view_v2', {
method: 'post',
headers: this.getHeaders()
});
if (isSuccess) {
const result = data.data.rows.find(item => item.cell_type == '18001');
return result.cell_data.checkin_continue.continue_checkin_reward_show;
}
else {
$.log(`查询是否有额外奖励失败!${response}`);
return false;
}
}
async getVipInfo() {
const { isSuccess, data, response } = await requestApi('https://user-api.smzdm.com/vip', {
method: 'post',
headers: this.getHeaders(),
data: {
token: this.token
}
});
if (isSuccess) {
return data.data;
}
else {
$.log(`查询信息失败!${response}`);
return false;
}
}
}
function random32() {
const chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
let result = '';
for (let i = 0; i < 32; i++) {
result += chars.charAt(Math.floor(Math.random() * chars.length));
}
return result;
}
function getSk(cookie) {
const matchUserId = cookie.match(/smzdm_id=([^;]*)/);
if (!matchUserId) {
return ''
}
const userId = matchUserId[1];
const deviceId = getDeviceId(cookie);
const key = CryptoJS.enc.Utf8.parse('geZm53XAspb02exN');
const cipherText = CryptoJS.DES.encrypt(userId + deviceId, key, {
mode: CryptoJS.mode.ECB,
padding: CryptoJS.pad.Pkcs7
});
return cipherText.toString();
}
function getDeviceId(cookie) {
const matchDeviceId = cookie.match(/device_id=([^;]*)/);
if (matchDeviceId) {
return matchDeviceId[1];
}
return random32();
}
!(async () => {
const cookies = getEnvCookies();
if (cookies === false) {
$.log('\n请先设置 SMZDM_COOKIE 环境变量');
return;
}
let sks = [];
if (process.env.SMZDM_SK) {
if (process.env.SMZDM_SK.indexOf('&') > -1) {
sks = process.env.SMZDM_SK.split('&');
}
else if (process.env.SMZDM_SK.indexOf('\n') > -1) {
sks = process.env.SMZDM_SK.split('\n');
}
else {
sks = [process.env.SMZDM_SK];
}
}
let notifyContent = '';
for (let i = 0; i < cookies.length; i++) {
const cookie = cookies[i];
if (!cookie) {
continue;
}
let sk = sks[i];
if (!sk) {
sk = getSk(cookie)
}
if (i > 0) {
await wait(10, 30);
}
const sep = `\n****** 账号${i + 1} ******\n`;
$.log(sep);
const bot = new SmzdmCheckinBot(cookie, sk);
const msg = await bot.run();
notifyContent += sep + msg + '\n';
}
$.log();
await notify.sendNotify($.name, notifyContent);
})().catch((e) => {
$.log('', `❌ ${$.name}, 失败! 原因: ${e}!`, '')
}).finally(() => {
$.done();
});