-
Notifications
You must be signed in to change notification settings - Fork 138
/
Copy pathapp.js
400 lines (359 loc) · 12.4 KB
/
app.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
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
import axios from "axios";
import qs from "qs";
import xmlJs from "xml-js";
import iconv from "iconv-lite";
import * as cheerio from 'cheerio';
axios.defaults.retry = 3; //设置全局请求次数
axios.defaults.retryDelay = 1000;//设置全局请求间隙
// 填写Telegram的Bot API和Chat ID
const telegramToken = process.env.TELEGRAM_TOKEN
const telegramID = process.env.TELEGRAM_ID
// 填写server酱sckey,不开启server酱则不用填
const sckey = process.env["SCKEY"];
// 填写pushplus的token,不开启pushplus则不用填
const token = process.env["PPTOKEN"];
// 填写PushDeer的key, 不开启不用填
const pushDeer = process.env["PDKEY"]
// 填写Bark的key, 不开启不用填
const barkKey = process.env["BARKKEY"]
// 填写Bark的服务器地址, 不开启不用填
const barkServer = process.env["BARKSERVER"]
//配置需要打开的服务信息,hao4k 和 4ksj,未配置只对hao4k
// const needCheckHost = process.env["CHECKHOST"]
const needCheckHost = '4ksj'
// 填入Hao4k账号对应cookie
let cookie = process.env["COOKIE"];
// 填入4KSJ账号对应Cookie
let cookieSJ = process.env["SJCOOKIE"];
// 更新 cookie 中 will_timelogout_XXXXXX 的值为当前时间戳加一天
function updateCookieLogoutTimePlusOneDay(cookieStr) {
const oneDayInSeconds = 24 * 60 * 60;
const timestampPlusOneDay = Math.floor(Date.now() / 1000) + oneDayInSeconds;
return cookieStr.replace(/(will_timelogout_\d+=)\d+/, `$1${timestampPlusOneDay}`);
}
cookieSJ = updateCookieLogoutTimePlusOneDay(cookieSJ);
const SJUrl =
"https://www.4ksj.com/";
const hao4kUrl =
"https://www.hao4k.cn/qiandao/";
const userAgent =
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36";
const SJUserAgent =
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36 Edg/129.0.0.0";
const headers = {
cookie: cookie ?? "",
"User-Agent": userAgent,
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"
};
const SJHeaders = {
cookie: cookieSJ ?? cookie,
"User-Agent": SJUserAgent,
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"
};
class HostInfo {
name;
url;
header;
status;
formHash;
message;
constructor(name, url, header) {
this.name = name;
this.url = url;
this.header = header;
}
}
async function getFormHashSJ(host) {
let headers = host.header;
await axios
.get(host.url + 'qiandao.php', {
headers,
responseType: "arraybuffer",
})
.then(async (response) => {
const gb = iconv.decode(response.data, "utf-8");
const $ = cheerio.load(gb);
let formHash = '';
const userName = $('.nexmemberintels>h5').text().replace('\n', '');
if (userName === '') {
console.log("cookie失效!");
host.status = false;
host.message = "cookie失效!";
} else {
console.log(host.name, "获取用户信息成功!");
formHash = $('#scbar_form input:nth-child(2)').val();
host.status = true;
host.formHash = formHash;
await checkinSJ(host);
}
})
.catch((error) => {
host.status = false;
host.message = "获取formhash出错" + error;
console.log(host.name, error);
});
}
async function getFormHash(host) {
let headers = host.header;
await axios
.get(host.url, {
headers,
responseType: "arraybuffer",
})
.then(async (response) => {
const gb = iconv.decode(response.data, "gb2312");
const $ = cheerio.load(gb);
let formHash = '';
const userName = $('#mumucms_username').text();
if (userName === '') {
console.log("cookie失效!");
host.status = false;
host.message = "cookie失效!";
} else {
console.log(host.name, "获取用户信息成功!");
formHash = $('#scbar_form input').eq(1).val();
host.status = true;
host.formHash = formHash;
await checkin(host);
}
})
.catch((error) => {
host.status = false;
host.message = "获取formhash出错" + error;
console.log(host.name, error);
});
}
async function checkinSJ(host) {
const checkInUrl =
host.url + "qiandao.php?sign=" + host.formHash;
let headers = host.header;
await axios
.get(checkInUrl, {
headers,
responseType: "arraybuffer",
})
.then(async (response) => {
const GBK = iconv.decode(response.data, "GBK");
const $ = cheerio.load(GBK);
const msg = $('#messagetext>p').text()
host.message = msg;
host.status = true;
await getCheckinInfoSJ(host);
})
.catch((error) => {
console.log(host.name, "签到出错或超时" + error);
host.status = false;
host.message = "签到出错或超时" + error;
});
}
async function checkin(host) {
const checkInUrl =
host.url + "?mod=sign&operation=qiandao&formhash=" + host.formHash + "&format=empty&inajax=1&ajaxtarget=";
let headers = host.header;
await axios
.get(checkInUrl, {
headers,
responseType: "arraybuffer",
})
.then(async (response) => {
const resUtf8 = iconv.decode(response.data, "GBK");
const dataStr = xmlJs.xml2json(resUtf8, {
compact: true,
spaces: 4,
});
const data = JSON.parse(dataStr);
const content = data?.root?._cdata;
if (content) {
if (content === "今日已签") {
host.message = "今日已签!";
}
} else {
host.message = "签到成功!";
}
host.status = true;
await getCheckinInfo(host);
})
.catch((error) => {
console.log(host.name, "签到出错或超时" + error);
host.status = false;
host.message = "签到出错或超时" + error;
});
}
async function getCheckinInfoSJ(host) {
let headers = host.header;
await axios
.get(host.url + 'qiandao.php', {
headers,
responseType: "arraybuffer",
})
.then((response) => {
const gb = iconv.decode(response.data, "GBK");
const $ = cheerio.load(gb);
//本月打卡
let month = $('#wp > .ct2 > .sd div:nth-child(2) .xl1 li:nth-child(2):eq(0)').text();
//连续打卡
let ctu = $('#wp > .ct2 > .sd div:nth-child(2) .xl1 li:nth-child(3):eq(0)').text();
//累计打卡
let total = $('#wp > .ct2 > .sd div:nth-child(2) .xl1 li:nth-child(4):eq(0)').text();
//累计奖励
let totalPrice = $('#wp > .ct2 > .sd div:nth-child(2) .xl1 li:nth-child(5):eq(0)').text();
//最近奖励
let price = $('#wp > .ct2 > .sd div:nth-child(2) .xl1 li:nth-child(6):eq(0)').text();
let info = month +'; '+ ctu +'; '+ total +'; '+ totalPrice +'; '+ price;
host.message = host.message + info;
// console.log(host.name, info)
})
.catch((error) => {
host.message = "获取签到信息出错!" + error;
console.log(host.name, "获取签到信息出错!" + error);
});
}
async function getCheckinInfo(host) {
let headers = host.header;
await axios
.get(host.url, {
headers,
responseType: "arraybuffer",
})
.then((response) => {
const gb = iconv.decode(response.data, "gb2312");
const $ = cheerio.load(gb);
let days = $('#lxdays').val(); //连续签到天数
let reward = $('#lxreward').val(); // 签到奖励
let allDays = $('#lxtdays').val(); // 签到总天数
let rank = $('#qiandaobtnnum').val();// 签到排名
let info = " 本次签到奖励: " + reward + " 个币; 已连续签到: " + days + " 天; 今日排名: " + rank + " 位; 签到总天数: " + allDays + " 天;";
host.message = host.message + info;
console.log(host.name, info)
})
.catch((error) => {
host.message = "获取签到信息出错!" + error;
console.log(host.name, "获取签到信息出错!" + error);
});
}
function pushNotice(status, message) {
console.log("开始推送消息")
if (sckey) {
console.log("通过server酱推送消息");
sendSCMsg(status, message);
}
if (token) {
console.log("通过pushPlus推送消息");
sendPushPlusMsg(status, message);
}
if (pushDeer) {
console.log("通过pushDeer推送消息");
sendPushDeerMsg(status, message);
}
if (barkKey) {
console.log("通过bark推送消息");
sendBarkMsg(status, message);
}
if (telegramToken) {
console.log("通过Telegram推送消息");
sendTelegramMsg(status, message);
}
console.log("结束推送消息")
}
function sendSCMsg(status, info) {
let serverUrl = "https://sctapi.ftqq.com/" + sckey + ".send";
axios.post(serverUrl, qs.stringify({
"title": status,
"desp": info
}))
.catch((e) => {
console.log(e);
})
}
function sendPushPlusMsg(status, info) {
axios
.post("http://www.pushplus.plus/send", {
'token': token,
'title': status,
'content': info
})
.catch((e) => {
console.log(e);
});
}
function sendPushDeerMsg(status, info) {
let message = status + info;
axios
.post("https://api2.pushdeer.com/message/push", {
'pushkey': pushDeer,
'type': 'text',
'text': message
})
.catch((e) => {
console.log(e);
});
}
function sendBarkMsg(status, info) {
let title = encodeURI(status);
let message = encodeURI(info);
let barkRealServer = barkServer ? barkServer : "https://api.day.app";
let barkUrl = barkRealServer + "/" + barkKey + "/" + title + "/" + message;
axios
.get(barkUrl)
.catch((e) => {
console.log(e);
})
}
/**
* 通过 Telegram 发送消息
* @param {*} status 签到结果
* @param {*} info 签到返回信息
*/
function sendTelegramMsg(status, info) {
axios
.post("https://api.telegram.org/bot" + telegramToken + "/sendMessage", {
'chat_id': telegramID,
'text': '<b>' + status + '</b>\n' + info,
'parse_mode': 'HTML'
})
.catch((e)=>{
console.log(e);
})
}
async function start() {
let status = "未配置";
let message = "未配置";
let checkIn = false;
console.log("配置的打卡的服务", needCheckHost);
const needCheck = needCheckHost ? needCheckHost : "hao4k";
if (needCheck.indexOf("4ksj") !== -1) {
if (!checkIn) {
checkIn = true;
status = "";
message = "";
}
let sj = new HostInfo("4K视界", SJUrl, SJHeaders);
await getFormHashSJ(sj);
status += sj.name + ": ";
if (sj.status) {
status += "签到成功!";
} else {
status += "签到失败!";
}
message += "* " + sj.name + ": " + sj.message;
}
if (needCheck.indexOf("hao4k") !== -1) {
if (!checkIn) {
checkIn = true;
status = "";
message = "";
}
let hao4k = new HostInfo("hao4K", hao4kUrl, headers);
await getFormHash(hao4k);
status += hao4k.name + ": ";
if (hao4k.status) {
status += "签到成功!";
} else {
status += "签到失败!";
}
message += "* " + hao4k.name + ": " + hao4k.message;
}
console.log(status, message);
pushNotice(status, message);
}
await start()