forked from sudojia/AutoTaskScript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsspanel_checkin.js
127 lines (121 loc) · 4.02 KB
/
sspanel_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
/**
* @author Telegram@sudojia
* @site https://blog.imzjw.cn
* @date 2021/9/25 22:11
* @last Modified by sudojia
* @last Modified time 2022/01/20 11:17
* @description SSPANEL面板自动签到
*/
const $ = new require('./env').Env('SSPANEL面板自动签到');
const notify = $.isNode() ? require('./sendNotify') : '';
let total = process.env.SITE_ACCOUNTS, totalList = [], message = '';
if (total.indexOf('&') > -1) {
totalList = total.split('&');
} else {
totalList = [total];
}
!(async () => {
if (!total) {
console.log('请先设置环境变量【SITE_ACCOUNTS】')
return;
}
for (let i = 0; i < totalList.length; i++) {
$.index = i + 1;
// 网站
$.SITE_URL = totalList[i].split(',')[0];
// 邮箱
$.email = totalList[i].split(',')[1].split(':')[0];
// 密码
$.pwd = totalList[i].split(',')[1].split(':')[1];
console.log(`\n*****开始第【${$.index}】个网站****\n`);
await main();
await $.wait(2000)
}
if (message) {
await notify.sendNotify(`${$.name}`, `${message}`);
}
})().catch((e) => {
$.log('', `❌ ${$.name}, 失败! 原因: ${e}!`, '')
}).finally(() => {
$.done();
})
async function main() {
await login();
await $.wait(1000);
if ($.isRet === 1) {
await checkin();
}
}
/**
* 登录
*
* @returns {*}
*/
function login() {
return new Promise((resolve) => {
$.post(sendPost('auth/login', `email=${$.email}&passwd=${$.pwd}&code=`), (err, response, data) => {
try {
if (err) {
console.log(`login API 请求失败\n${JSON.stringify(err)}`)
} else {
data = JSON.parse(data);
console.log(data.msg, '\n');
$.isRet = data.ret;
}
} catch (err) {
$.logErr(err, response);
} finally {
resolve();
}
})
})
}
/**
* 签到
*
* @returns {*}
*/
function checkin() {
return new Promise((resolve) => {
$.post(sendPost('user/checkin', ''), async (err, response, data) => {
try {
if (err) {
console.log(`checkin API 请求失败\n${JSON.stringify(err)}`)
} else {
console.log('开始进行签到...\n');
data = JSON.parse(data);
message += `开始第【${$.index}】个网站\n`;
if (data.ret === 1) {
if (data.trafficInfo) {
console.log(`${data.msg}\n今日已用:${data.trafficInfo.todayUsedTraffic}\n过去已用:${data.trafficInfo.lastUsedTraffic}\n剩余流量:${data.trafficInfo.unUsedTraffic}\n\n`);
message += `${data.msg}\n今日已用:${data.trafficInfo.todayUsedTraffic}\n过去已用:${data.trafficInfo.lastUsedTraffic}\n剩余流量:${data.trafficInfo.unUsedTraffic}\n\n`;
} else {
console.log(`${data.msg}\n`)
message += `${data.msg}\n\n`;
}
} else {
console.log(data.msg, '\n');
message += data.msg + '\n\n';
}
}
} catch (err) {
$.logErr(err, response);
} finally {
resolve();
}
})
})
}
function sendPost(path, body = {}) {
return {
url: `${$.SITE_URL}/${path}`,
body: body,
headers: {
"Accept": "application/json, text/javascript, */*; q=0.01",
"Content-type": "application/x-www-form-urlencoded; charset=UTF-8",
"Referer": `${$.SITE_URL}/${path}`,
"Accept-encoding": "gzip, deflate, br",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36 Edg/97.0.1072.62"
}
}
}