forked from sudojia/AutoTaskScript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hlx.js
207 lines (198 loc) · 6.62 KB
/
hlx.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
/**
* @author Telegram@sudojia
* @site https://blog.imzjw.cn
* @date 2022/01/20 09:23
* @description 葫芦侠自动签到(应网友要求)
*/
const $ = new require('./env').Env('葫芦侠自动签到');
const notify = $.isNode() ? require('./sendNotify') : '';
let total = process.env.HLX_ACCOUNTS, totalList = [], message = '';
const HLX_API = 'http://floor.huluxia.com';
const headers = {
"Connection": "close",
"Content-Type": "application/x-www-form-urlencoded",
"Host": "floor.huluxia.com",
"Accept-Encoding": "gzip",
"User-Agent": "okhttp/3.8.1"
};
if (total.indexOf('&') > -1) {
totalList = total.split('&');
} else {
totalList = [total];
}
!(async () => {
if (!total) {
console.log('请设置环境变量【HLX_ACCOUNTS】')
return;
}
for (let i = 0; i < totalList.length; i++) {
$.index = i + 1;
// 账号
$.phone = totalList[i].split('#')[0];
// MD5 加密密码
$.paswd = totalList[i].split('#')[1];
console.log(`\n*****开始第【${$.index}】个账号****\n`);
await main();
await $.wait(2000)
}
if (message) {
await notify.sendNotify(`「葫芦侠签到报告」`, `${message}`);
}
})().catch((e) => {
$.log('', `❌ ${$.name}, 失败! 原因: ${e}!`, '')
}).finally(() => {
$.done();
})
async function main() {
await login();
await $.wait(1000);
await checkToken();
await $.wait(1000);
await getAllCategory();
}
/**
* 登录
*
* @returns {*}
*/
function login() {
let param = 'account/login/ANDROID/4.0?platform=2&gkey=000000&app_version=4.0.0.6.2&versioncode=20141433&market_id=floor_baidu&_key=&device_code=%5Bw%5D02%3A00%3A00%3A00%3A00%3A00';
let sudojia = {
url: `${HLX_API}/${param}`,
body: `account=${$.phone}&login_type=2&password=${$.paswd}`,
headers: headers
}
return new Promise((resolve) => {
$.post(sudojia, (err, response, data) => {
try {
if (err) {
console.log(`login API 请求失败\n${JSON.stringify(err)}`)
} else {
data = JSON.parse(data);
if (data._key) {
console.log(`登录成功~\n`)
// 等级
$.level = data.user.level;
// 令牌
$.key = data._key;
// 昵称
$.nick = data.user.nick;
message += `📣=============账号${$.index}=============📣\n【社区昵称】${$.nick}\n【社区等级】${$.level}\n`
}
}
} catch (err) {
$.logErr(err, response);
} finally {
resolve();
}
})
})
}
/**
* 令牌验证
*
* @returns {*}
*/
function checkToken() {
let param = `user/status/ANDROID/2.1?platform=2&gkey=000000&app_version=4.0.0.6.2&versioncode=20141433&market_id=floor_baidu&_key=${$.key}&device_code=%5Bw%5D02%3A00%3A00%3A00%3A00%3A00`;
return new Promise((resolve) => {
$.get(sendGet(param), (err, response, data) => {
try {
if (err) {
console.log(`checkToken API 请求失败\n${JSON.stringify(err)}`)
} else {
console.log(JSON.parse(data).status === 1 ? "令牌验证成功\n" : "令牌验证失败\n")
}
} catch (err) {
$.logErr(err, response);
} finally {
resolve();
}
})
})
}
/**
* 获取所有社区板块
*
* @returns {*}
*/
function getAllCategory() {
let param = `category/list/ANDROID/2.0?platform=2&gkey=000000&app_version=4.0.0.6.2&versioncode=20141433&market_id=floor_baidu&_key=${$.key}&device_code=%5Bw%5D02%3A00%3A00%3A00%3A00%3A00&is_hidden=1`
return new Promise((resolve) => {
$.get(sendGet(param), async (err, response, data) => {
try {
if (err) {
console.log(`getAllCategory API 请求失败\n${JSON.stringify(err)}`)
} else {
data = JSON.parse(data);
let categoryList = data.categories;
message += '===========签到详细===========\n';
// 排除 ID 为 0 和 94 的版块
for (let c of categoryList) {
if (c.categoryID !== 0 && c.categoryID !== 94) {
$.title = c.title
await signIn(c.categoryID)
await $.wait(888);
}
}
}
} catch (err) {
$.logErr(err, response);
} finally {
resolve();
}
})
})
}
/**
* 签到
*
* @param cat_id 社区 ID
* @returns {*}
*/
function signIn(cat_id) {
let param = `user/signin/ANDROID/4.0?platform=2&gkey=000000&app_version=4.0.0.6.2&versioncode=20141433&market_id=floor_baidu&_key=${$.key}&device_code=%5Bw%5D02%3A00%3A00%3A00%3A00%3A00&cat_id=${cat_id}`
return new Promise((resolve) => {
$.get(sendGet(param), async (err, response, data) => {
try {
if (err) {
console.log(`signIn API 请求失败\n${JSON.stringify(err)}`)
} else {
await signInResp();
}
} catch (err) {
$.logErr(err, response);
} finally {
resolve();
}
})
})
}
function signInResp() {
let param = `user/signin/detail/ANDROID/4.0?platform=2&gkey=000000&app_version=4.0.0.6.2&versioncode=20141433&market_id=floor_baidu&_key=${$.key}&device_code=%5Bw%5D02%3A00%3A00%3A00%3A00%3A00`
return new Promise((resolve) => {
$.get(sendGet(param), (err, response, data) => {
try {
if (err) {
console.log(`signInResp 请求失败\n${JSON.stringify(err)}`)
} else {
data = JSON.parse(data);
if (data.experienceVal) {
console.log(`【${$.title}】签到成功~`)
message += `【${$.title}】签到成功~获得${data.experienceVal}经验,已连续签到${data.continueDays}天\n`
}
}
} catch (err) {
$.logErr(err, response);
} finally {
resolve();
}
})
})
}
function sendGet(param) {
return {
url: `${HLX_API}/${param}`,
headers: headers
}
}