-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.js
85 lines (80 loc) · 2.68 KB
/
index.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
import "dotenv/config";
import fetch from "node-fetch";
// const notify = require("./sendNotify");
const updateAccesssTokenURL = "https://auth.aliyundrive.com/v2/account/token";
const signinURL = "https://member.aliyundrive.com/v1/activity/sign_in_list";
const rewardURL =
"https://member.aliyundrive.com/v1/activity/sign_in_reward?_rx-s=mobile";
const refreshToeknArry = process.env.REFRESH_TOKENS.split(",").map((i) =>
i.trim()
);
!(async () => {
for (const elem of refreshToeknArry) {
const queryBody = {
grant_type: "refresh_token",
refresh_token: elem,
};
//使用 refresh_token 更新 access_token
fetch(updateAccesssTokenURL, {
method: "POST",
body: JSON.stringify(queryBody),
headers: { "Content-Type": "application/json" },
})
.then((res) => res.json())
.then((json) => {
if (json.code === "InvalidParameter.RefreshToken") {
throw new Error(
"发生错误,终止 GitHub Actions。原因:" + json.message
);
}
let access_token = json.access_token;
// console.log(access_token);
//签到
fetch(signinURL, {
method: "POST",
body: JSON.stringify(queryBody),
headers: {
Authorization: "Bearer " + access_token,
"Content-Type": "application/json",
},
})
.then((res) => res.json())
.then((json) => {
const signin_count = json["result"]["signInCount"];
console.log("签到成功, 本月累计签到" + signin_count + "天" + "\n");
//领取奖励
fetch(rewardURL, {
method: "POST",
body: JSON.stringify({ signInDay: signin_count }),
headers: {
Authorization: "Bearer " + access_token,
"Content-Type": "application/json",
},
})
.then((res) => res.json())
.then((json) => {
console.log(
"本次签到获得" +
json["result"]["name"] +
" " +
json["result"]["description"] +
"\n"
);
})
.catch((err) => console.log(err));
})
.catch((err) => console.log(err));
})
.catch((err) => {
console.error(err);
process.exit(1); // 1 表示退出并标记为失败
});
}
// await notify.sendNotifyBark(`v2free 自动签到结果`,allnotify)
})()
.catch((e) => {
console.error(`❗️ 运行错误!\n${e}`);
process.exit(1);
})
.finally();
// notify.sendNotify(`v2free 自动签到结果`,allnotify)