-
Notifications
You must be signed in to change notification settings - Fork 283
/
huluwa.js
363 lines (325 loc) · 12.4 KB
/
huluwa.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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
/**
葫芦娃预约 v1.06
cron: 30 8 * * *
const $ = new Env("葫芦娃预约");
自行抓包把token(一般在请求头里)填到变量中, 多账号用换行隔开(可自定义)
环境变量 XLTH_COOKIE 新联惠购
环境变量 GLYP_COOKIE 贵旅优品
环境变量 KGLG_COOKIE 空港乐购
环境变量 HLQG_COOKIE 航旅黔购
环境变量 ZHCS_COOKIE 遵行出山
环境变量 GYQP_COOKIE 贵盐黔品
环境变量 LLSC_COOKIE 乐旅商城
环境变量 YLQX_COOKIE 驿路黔寻
*/
const SPLIT = "\n"; // 分割符(可自定义)
const axios = require('axios');
const crypto = require('crypto');
const moment = require('moment');
const notify = require('./sendNotify');
const XLTH_APPID = 'wxded2e7e6d60ac09d'; // 新联惠购
const GLYP_APPID = 'wx61549642d715f361'; // 贵旅优品
const KGLG_APPID = 'wx613ba8ea6a002aa8'; // 空港乐购
const HLQG_APPID = 'wx936aa5357931e226'; // 航旅黔购
const ZHCS_APPID = 'wx624149b74233c99a'; // 遵航出山
const GYQP_APPID = 'wx5508e31ffe9366b8'; // 贵盐黔品
const LLSC_APPID = 'wx821fb4d8604ed4d6'; // 乐旅商城
const YLQX_APPID = 'wxee0ce83ab4b26f9c'; // 驿路黔寻
const HOST = 'https://gw.huiqunchina.com';
const AK = '00670fb03584fbf44dd6b136e534f495';
const SK = '0d65f24dbe2bc1ede3c3ceeb96ef71bb';
let sendMessage = [];
function delay(time) {
return new Promise(resolve => setTimeout(resolve, time));
}
function calculateDigest(body, sk) {
const hmac = crypto.createHmac('sha256', sk);
hmac.update(body);
const signature = hmac.digest('base64');
return signature;
}
function calculateSignature(method, url, ak, sk, date) {
const strToSign = `${method.toUpperCase()}\n${url}\n\n${ak}\n${date}\n`;
const hmac = crypto.createHmac('sha256', sk);
hmac.update(strToSign);
const signature = hmac.digest('base64');
return signature;
}
function buildHeader(method, url, body) {
const date = moment().utc().format('ddd, DD MMM YYYY HH:mm:ss [GMT]');
const signature = calculateSignature(method, url, AK, SK, date);
const digest = calculateDigest(body, SK);
const headers = {
'Content-Type': 'application/json',
'X-HMAC-SIGNATURE': signature,
'X-HMAC-ACCESS-KEY': AK,
'X-HMAC-ALGORITHM': 'hmac-sha256',
'X-HMAC-DIGEST': digest,
'X-HMAC-Date': date,
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36 MicroMessenger/7.0.20.1781(0x6700143B) NetType/WIFI MiniProgramEnv/Windows WindowsWechat/WMPF XWEB/6945'
};
return headers;
}
async function getUserInfo(appId, token) {
const url = '/front-manager/api/customer/queryById/token';
const method = 'post';
const data = {appId};
const headers = buildHeader(method, url, JSON.stringify(data));
headers['X-access-token'] = token;
let resData;
await axios(HOST + url, {method: method, data: data, headers: headers})
.then(res => {
resData = res.data;
})
.catch(err => {
resData = err.response.data;
});
return resData;
}
async function getChannelActivity(id, token) {
const url = '/front-manager/api/customer/promotion/channelActivity';
const method = 'post';
const data = {id};
const headers = buildHeader(method, url, JSON.stringify(data));
headers['X-access-token'] = token;
let resData;
await axios(HOST + url, {method: method, data: data, headers: headers})
.then(res => {
resData = res.data;
})
.catch(err => {
resData = err.response.data;
});
return resData;
}
async function getChannelInfoId(appId) {
const url = '/front-manager/api/get/getChannelInfoId';
const method = 'post';
const data = {appId};
const headers = buildHeader(method, url, JSON.stringify(data));
headers['X-access-token'] = token;
let resData;
await axios(HOST + url, {method: method, data: data, headers: headers})
.then(res => {
resData = res.data;
})
.catch(err => {
resData = err.response.data;
});
return resData;
}
async function appoint(activityId, channelId, token) {
const url = '/front-manager/api/customer/promotion/appoint';
const method = 'post';
const data = {activityId, channelId};
const headers = buildHeader(method, url, JSON.stringify(data));
headers['X-access-token'] = token;
let resData;
await axios(HOST + url, {method: method, data: data, headers: headers})
.then(res => {
resData = res.data;
})
.catch(err => {
resData = err.response.data;
});
return resData;
}
async function checkCustomerInQianggou(activityId, channelId, token) {
const url = '/front-manager/api/customer/promotion/checkCustomerInQianggou';
const method = 'post';
const data = {activityId, channelId};
const headers = buildHeader(method, url, JSON.stringify(data));
headers['X-access-token'] = token;
let resData;
await axios(HOST + url, {method: method, data: data, headers: headers})
.then(res => {
resData = res.data;
})
.catch(err => {
resData = err.response.data;
});
return resData;
}
async function autoSubmit(appId, token) {
let channelId = '';
let channelName = '';
if (appId === XLTH_APPID) {
channelId = '8';
channelName = '新联惠购';
}
if (appId === GLYP_APPID) {
channelId = '7';
channelName = '贵旅优品';
}
if (appId === KGLG_APPID) {
channelId = '2';
channelName = '空港乐购';
}
if (appId === HLQG_APPID) {
channelId = '6';
channelName = '航旅黔购';
}
if (appId === ZHCS_APPID) {
channelId = '5';
channelName = '遵行出山';
}
if (appId === GYQP_APPID) {
channelId = '3';
channelName = '贵盐黔品';
}
if (appId === LLSC_APPID) {
channelId = '1';
channelName = '乐旅商城';
}
if (appId === YLQX_APPID) {
channelId = '9';
channelName = '驿路黔寻';
}
try {
const res1 = await getUserInfo(appId, token);
if (res1.code != '10000') {
console.log(res1.message);
sendMessage.push(res1.message);
return;
}
const realName = res1.data.realName;
const phone = res1.data.phone;
console.log(`当前用户[${phone}]`);
sendMessage.push(`当前用户[${phone}]`);
const res2 = await getChannelActivity(channelId, token);
if (res2.code != '10000') {
console.log(res2.message);
sendMessage.push(res2.message);
return;
}
const activityId = res2.data.id;
const activityName = res2.data.name;
console.log(`活动名称[${activityName}]`);
sendMessage.push(`活动名称[${activityName}]`);
const res3 = await checkCustomerInQianggou(activityId, channelId, token);
if (res3.code != '10000') {
console.log(res3.message);
sendMessage.push(res3.message);
return;
}
const data = res3.data;
let message = '用户已经预约成功';
if (data == false) {
const res4 = await appoint(activityId, channelId, token);
this.sendMessage = res4.message;
}
console.log(`预约结果[${message}]`);
sendMessage.push(`预约结果[${message}]`);
} catch (err) {
console.log(`运行异常[${err.message}]`);
sendMessage.push(`运行异常[${err.message}]`);
}
}
async function main() {
const XLTH_COOKIE_ARR = process.env.XLTH_COOKIE; // 新联惠购
const GLYP_COOKIE_ARR = process.env.GLYP_COOKIE; // 贵旅优品
const KGLG_COOKIE_ARR = process.env.KGLG_COOKIE; // 空港乐购
const HLQG_COOKIE_ARR = process.env.HLQG_COOKIE; // 航旅黔购
const ZHCS_COOKIE_ARR = process.env.ZHCS_COOKIE; // 遵行出山
const GYQP_COOKIE_ARR = process.env.GYQP_COOKIE; // 贵盐黔品
const LLSC_COOKIE_ARR = process.env.LLSC_COOKIE; // 乐旅商城
const YLQX_COOKIE_ARR = process.env.YLQX_COOKIE; // 驿路黔寻
if (XLTH_COOKIE_ARR) {
console.log('新联惠购预约开始');
sendMessage.push('新联惠购预约开始');
for (let [index, item] of XLTH_COOKIE_ARR.split(SPLIT).entries()) {
console.log(`----第${index + 1}个号----`);
sendMessage.push(`----第${index + 1}个号----`);
await autoSubmit(XLTH_APPID, item);
await delay(1000);
}
console.log('新联惠购预约结束\n');
sendMessage.push('新联惠购预约结束\n');
}
if (GLYP_COOKIE_ARR) {
console.log('贵旅优品预约开始');
sendMessage.push('贵旅优品预约开始');
for (let [index, item] of GLYP_COOKIE_ARR.split(SPLIT).entries()) {
console.log(`----第${index + 1}个号----`);
sendMessage.push(`----第${index + 1}个号----`);
await autoSubmit(GLYP_APPID, item);
await delay(1000);
}
console.log('贵旅优品预约结束\n');
sendMessage.push('贵旅优品预约结束\n');
}
if (KGLG_COOKIE_ARR) {
console.log('空港乐购预约开始');
sendMessage.push('新联惠购预约开始');
for (let [index, item] of KGLG_COOKIE_ARR.split(SPLIT).entries()) {
console.log(`----第${index + 1}个号----`);
sendMessage.push(`----第${index + 1}个号----`);
await autoSubmit(KGLG_APPID, item);
await delay(1000);
}
console.log('空港乐购预约结束\n');
sendMessage.push('空港乐购预约结束\n');
}
if (HLQG_COOKIE_ARR) {
console.log('航旅黔购预约开始');
sendMessage.push('新联惠购预约开始');
for (let [index, item] of HLQG_COOKIE_ARR.split(SPLIT).entries()) {
console.log(`----第${index + 1}个号----`);
sendMessage.push(`----第${index + 1}个号----`);
await autoSubmit(HLQG_APPID, item);
await delay(1000);
}
console.log('航旅黔购预约结束\n');
sendMessage.push('航旅黔购预约结束\n');
}
if (ZHCS_COOKIE_ARR) {
console.log('遵行出山预约开始');
sendMessage.push('新联惠购预约开始');
for (let [index, item] of ZHCS_COOKIE_ARR.split(SPLIT).entries()) {
console.log(`----第${index + 1}个号----`);
sendMessage.push(`----第${index + 1}个号----`);
await autoSubmit(ZHCS_APPID, item);
await delay(1000);
}
console.log('遵行出山预约结束\n');
sendMessage.push('遵行出山预约结束\n');
}
if (GYQP_COOKIE_ARR) {
console.log('贵盐黔品预约开始');
sendMessage.push('贵盐黔品预约开始');
for (let [index, item] of GYQP_COOKIE_ARR.split(SPLIT).entries()) {
console.log(`----第${index + 1}个号----`);
sendMessage.push(`----第${index + 1}个号----`);
await autoSubmit(GYQP_APPID, item);
await delay(1000);
}
console.log('贵盐黔品预约结束\n');
sendMessage.push('贵盐黔品预约结束\n');
}
if (LLSC_COOKIE_ARR) {
console.log('乐旅商城预约开始');
sendMessage.push('乐旅商城预约开始');
for (let [index, item] of LLSC_COOKIE_ARR.split(SPLIT).entries()) {
console.log(`----第${index + 1}个号----`);
sendMessage.push(`----第${index + 1}个号----`);
await autoSubmit(LLSC_APPID, item);
await delay(1000);
}
console.log('乐旅商城预约结束\n');
sendMessage.push('乐旅商城预约结束\n');
}
if (YLQX_COOKIE_ARR) {
console.log('驿路黔寻预约开始');
sendMessage.push('驿路黔寻预约开始');
for (let [index, item] of YLQX_COOKIE_ARR.split(SPLIT).entries()) {
console.log(`----第${index + 1}个号----`);
sendMessage.push(`----第${index + 1}个号----`);
await autoSubmit(YLQX_APPID, item);
await delay(1000);
}
console.log('驿路黔寻预约结束\n');
sendMessage.push('驿路黔寻预约结束\n');
}
await notify.sendNotify(`葫芦娃预约`, sendMessage.join('\n'), {}, '\n\n本通知 By:一泽');
}
main();