-
Notifications
You must be signed in to change notification settings - Fork 27
/
flyingbird_checkin.js
361 lines (335 loc) · 11.4 KB
/
flyingbird_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
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
/*
飞鸟机场签到 注册地址:https://www.fyb-aff.com/auth/register?code=MYQJ
以下都以青龙或nodejs环境为准
变量支持账号密码,多账号用\n分割
单账号:export fybCookie = '账号#密码'
多账号:export fybCookie = '账号1#密码\n账号2#密码'
下面一行是建议定时,青龙拉库会自动读取
cron: 0 0 * * *
*/
/*
const和let的区别:
用const定义的变量以后不能再更改
用let定义的变量可以改
进阶内容: const 对象本身不可更改,但是对象里面的属性可以改,与指针有关
*/
const $ = new Env('飞鸟机场签到'); //青龙拉库会把 new Env('qwerty') 里面的名字qwerty作为定时任务名
const got = require('got'); //青龙发包依赖
const env_name = 'fybCookie'; //环境变量名字
const env = process.env[env_name] || ''; //或 process.env.zippoCookie, node读取变量方法. 后面的 || 表示如果前面结果为false或者空字符串或者null或者undifined, 就取后面的值
//got的基本用法, 封装一下方便之后直接调用, 新手可以不动他直接用就行
async function request (opt) {
const DEFAULT_RETRY = 3; //请求出错重试三次
var resp = null, count = 0;
var fn = opt.fn || opt.url;
opt.method = opt?.method?.toUpperCase() || 'GET';
while (count++ < DEFAULT_RETRY) {
try {
var err = null;
const errcodes = ['ECONNRESET', 'EADDRINUSE', 'ENOTFOUND', 'EAI_AGAIN'];
await got(opt).then(t => {
resp = t
}, e => {
err = e;
resp = e.response;
});
if (err) {
if (err.name == 'TimeoutError') {
console.log(`[${fn}]请求超时(${err.code}),重试第${count}次`);
} else if (errcodes.includes(err.code)) {
console.log(`[${fn}]请求错误(${err.code}),重试第${count}次`);
} else {
let statusCode = resp?.statusCode || -1;
console.log(`[${fn}]请求错误(${err.message}), 返回[${statusCode}]`);
break;
}
} else {
break;
}
} catch (e) {
console.log(`[${fn}]请求错误(${e.message}),重试第${count}次`);
};
}
let { statusCode = -1, headers = null, body = null } = resp;
if (body) try { body = JSON.parse(body); } catch { };
return { statusCode, headers, result: body };
}
//脚本入口函数main()
async function main () {
if (env == '') {
//没有设置变量,直接退出
console.log(`没有填写变量: ${env_name}`);
return;
}
// console.log('账号信息', env);
//多账号分割,这里默认是换行(\n)分割,其他情况自己实现
//split('\n')会把字符串按照换行符分割, 并把结果存在user_ck数组里
let user_ck = env.includes('\n') ? env.split('\n') : env.split('&');
// console.log('user_ck', user_ck);
let index = 1; //用来给账号标记序号, 从1开始
//循环遍历每个账号
for (let ck of user_ck) {
if (!ck) continue; //跳过空行
// console.log('ck:', ck);
// 账号用#分割
const account = ck.split('#')
// 邮箱
let email = account[0]
// 密码
let passwd = account[1]
let user = {
index,
email,
passwd,
};
index = index + 1; //每次用完序号+1
//开始账号任务
await userTask(user);
//每个账号之间等1~5秒随机时间
// let rnd_time = Math.floor(Math.random() * 4000) + 1000;
// console.log(`账号[${user.index}]随机等待${rnd_time / 1000}秒...`);
// await $.wait(rnd_time);
}
}
async function userTask (user) {
//任务逻辑都放这里了, 与脚本入口分开, 方便分类控制并模块化
console.log(`\n============= 账号[${user.index}]开始任务 =============`)
await login(user)
// await signin(user)
}
/** 登录 */
const login = async (user) => {
try {
const options = {
method: 'post', //post方法
//url问号前面的地址
url: 'http://flyingbird.pro/auth/login',
//请求头, 所有接口通用
headers: {
Connection: 'keep-alive',
'Accept-Encoding': 'gzip,compress,br,deflate',
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 16_1_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/8.0.32(0x1800202f) NetType/WIFI Language/zh_CN',
Referer: 'https://servicewechat.com/wxaa75ffd8c2d75da7/56/page-frame.html',
},
json: {
email: user.email,
passwd: user.passwd,
},
//超时设置
timeout: 15000,
}
//解构返回
// console.log('登录的结果', await request(options));
const { result, headers } = await request(options);
// console.log('登录result', result);
// console.log('处理后的cookie', cookie);
if (result?.ret === 1) {
// console.log('cookie====', headers['set-cookie']);
const cookieArr = headers['set-cookie']
let cookie = ''
cookieArr.forEach(item => {
cookie += item
})
// console.log('处理前的cookie', cookie);
// 处理cookie格式
cookie = cookie.replace(/'/g, '').replace(/\s+/g, '').replace(/path\=\//g, '');
console.log(`账号${user.email},${result?.msg}`)
console.log('====开始执行签到任务====');
await signin(cookie, user)
} else {
//打印请求错误信息
console.log(`账号${user.email}(${result?.ret}): ${result?.msg}`);
}
} catch (error) {
//打印错误信息
console.log(error);
}
}
/**
* 签到接口
* @param {string} cookie 登录后返回的cookie
* @param {object} user 用户信息
*/
async function signin (cookie, user) {
try {
let urlObject = {
method: 'post', //post方法
//url问号前面的地址
url: 'http://flyingbird.pro/user/checkin',
//请求头, 所有接口通用
headers: {
Connection: 'keep-alive',
'Accept-Encoding': 'gzip,compress,br,deflate',
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 16_1_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/8.0.32(0x1800202f) NetType/WIFI Language/zh_CN',
Referer: 'https://servicewechat.com/wxaa75ffd8c2d75da7/56/page-frame.html',
Cookie: cookie
},
//超时设置
timeout: 15000,
}
//解构返回
const { result } = await request(urlObject);
// console.log('====签到result', result);
if (result?.ret === 1) {
console.log(`账号[${user.email}]签到成功,${result?.msg}`)
} else {
//打印请求错误信息
console.log(`账号[${user.email}]签到失败[${result?.ret}]: ${result?.msg}`);
}
} catch (e) {
//打印错误信息
console.log(e);
}
}
//调用main()
main();
function Env (name) {
return new class {
constructor(name) {
this.name = name;
this.startTime = Date.now();
this.log(`[${this.name}]开始运行\n`, { time: true });
this.notifyStr = [];
this.notifyFlag = true;
this.userIdx = 0;
this.userList = [];
this.userCount = 0;
}
log (msg, options = {}) {
let opt = { console: true };
Object.assign(opt, options);
if (opt.time) {
let fmt = opt.fmt || 'hh:mm:ss';
msg = `[${this.time(fmt)}]` + msg;
}
if (opt.notify) this.notifyStr.push(msg);
if (opt.console) console.log(msg);
}
read_env (Class) {
let envStrList = ckNames.map(x => process.env[x]);
for (let env_str of envStrList.filter(x => !!x)) {
let sp = envSplitor.filter(x => env_str.includes(x));
let splitor = sp.length > 0 ? sp[0] : envSplitor[0];
for (let ck of env_str.split(splitor).filter(x => !!x)) {
this.userList.push(new Class(ck));
}
}
this.userCount = this.userList.length;
if (!this.userCount) {
this.log(`未找到变量,请检查变量${ckNames.map(x => '[' + x + ']').join('或')}`, { notify: true });
return false;
}
this.log(`共找到${this.userCount}个账号`);
return true;
}
async threads (taskName, conf, opt = {}) {
while (conf.idx < $.userList.length) {
let user = $.userList[conf.idx++];
if (!user.valid) continue;
await user[taskName](opt);
}
}
async threadTask (taskName, thread) {
let taskAll = [];
let taskConf = { idx: 0 };
while (thread--) taskAll.push(this.threads(taskName, taskConf));
await Promise.all(taskAll);
}
time (t, x = null) {
let xt = x ? new Date(x) : new Date;
let e = {
"M+": xt.getMonth() + 1,
"d+": xt.getDate(),
"h+": xt.getHours(),
"m+": xt.getMinutes(),
"s+": xt.getSeconds(),
"q+": Math.floor((xt.getMonth() + 3) / 3),
S: this.padStr(xt.getMilliseconds(), 3)
};
/(y+)/.test(t) && (t = t.replace(RegExp.$1, (xt.getFullYear() + "").substr(4 - RegExp.$1.length)));
for (let s in e) new RegExp("(" + s + ")").test(t) && (t = t.replace(RegExp.$1, 1 == RegExp.$1.length ? e[s] : ("00" + e[s]).substr(("" + e[s]).length)));
return t;
}
async showmsg () {
if (!this.notifyFlag) return;
if (!this.notifyStr.length) return;
var notify = require('./sendNotify');
this.log('\n============== 推送 ==============');
await notify.sendNotify(this.name, this.notifyStr.join('\n'));
}
padStr (num, length, opt = {}) {
let padding = opt.padding || '0';
let mode = opt.mode || 'l';
let numStr = String(num);
let numPad = (length > numStr.length) ? (length - numStr.length) : 0;
let pads = '';
for (let i = 0; i < numPad; i++) {
pads += padding;
}
if (mode == 'r') {
numStr = numStr + pads;
} else {
numStr = pads + numStr;
}
return numStr;
}
json2str (obj, c, encode = false) {
let ret = [];
for (let keys of Object.keys(obj).sort()) {
let v = obj[keys];
if (v && encode) v = encodeURIComponent(v);
ret.push(keys + '=' + v);
}
return ret.join(c);
}
str2json (str, decode = false) {
let ret = {};
for (let item of str.split('&')) {
if (!item) continue;
let idx = item.indexOf('=');
if (idx == -1) continue;
let k = item.substr(0, idx);
let v = item.substr(idx + 1);
if (decode) v = decodeURIComponent(v);
ret[k] = v;
}
return ret;
}
randomPattern (pattern, charset = 'abcdef0123456789') {
let str = '';
for (let chars of pattern) {
if (chars == 'x') {
str += charset.charAt(Math.floor(Math.random() * charset.length));
} else if (chars == 'X') {
str += charset.charAt(Math.floor(Math.random() * charset.length)).toUpperCase();
} else {
str += chars;
}
}
return str;
}
randomString (len, charset = 'abcdef0123456789') {
let str = '';
for (let i = 0; i < len; i++) {
str += charset.charAt(Math.floor(Math.random() * charset.length));
}
return str;
}
randomList (a) {
let idx = Math.floor(Math.random() * a.length);
return a[idx];
}
wait (t) {
return new Promise(e => setTimeout(e, t));
}
async exitNow () {
await this.showmsg();
let e = Date.now();
let s = (e - this.startTime) / 1000;
this.log('');
this.log(`[${this.name}]运行结束,共运行了${s}秒`, { time: true });
process.exit(0);
}
}
(name)
}