-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathmain.js
65 lines (54 loc) · 1.44 KB
/
main.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
const signPageUrl = "https://www.hifini.com/sg_sign.htm";
const responseSuccessCode = "0";
function generateBaseHeaders(cookie) {
return {
Cookie: cookie,
"User-Agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36",
};
}
async function getSign(cookie) {
const response = await fetch(signPageUrl, {
headers: generateBaseHeaders(cookie),
});
const resText = await response.text();
const re = /var sign\s*=\s*"([^"]+)"/;
const sign = re.exec(resText)[1];
return sign;
}
function checkIn(cookie, sign) {
fetch(signPageUrl, {
method: "POST",
headers: {
...generateBaseHeaders(cookie),
// necessary for POST XMLHttpRequest
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
"X-Requested-With": "XMLHttpRequest",
},
body: `sign=${sign}`,
})
.then((res) => res.json())
.then((resJson) => {
if (resJson.code === responseSuccessCode) {
// console.log("签到成功");
console.log(resJson.message);
//
} else {
// console.log("签到失败");
throw new Error(resJson.message);
//
}
});
}
async function main() {
let cookie;
if (process.env.COOKIE) {
cookie = process.env.COOKIE;
} else {
console.log("COOKIE NOT FOUND");
process.exit(1);
}
let sign = await getSign(cookie);
checkIn(cookie, sign);
}
main();