-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathairport_checkin.js
More file actions
481 lines (403 loc) · 14.5 KB
/
Copy pathairport_checkin.js
File metadata and controls
481 lines (403 loc) · 14.5 KB
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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
/*
* 机场自动签到 - 青龙面板专用
* cron: 0 8 * * *
* 环境变量: AIRPORT_TOKEN (必需)
* 通知环境变量: TG_BOT_TOKEN, TG_USER_ID (可选)
*/
const axios = require('axios');
// =============== 配置区 ===============
const CONFIG = {
name: '我的机场',
url: 'https://7m9gi9norz.1095813.xyz',
checkinPath: '/api/v1/user/trial/checkin',
userInfoPath: '/api/v1/user/info',
subscribePath: '/api/v1/user/getSubscribe',
};
// =============== 获取Token ===============
function getTokens() {
const token = process.env.AIRPORT_TOKEN || '';
if (!token) {
console.log('❌ 错误:未配置 AIRPORT_TOKEN 环境变量');
return [];
}
return token.split(/[&\n]/).map(t => t.trim()).filter(t => t);
}
// =============== 格式化流量(修复版)===============
function formatTraffic(bytes) {
if (!bytes || bytes === 0 || isNaN(bytes)) {
return '0 B';
}
bytes = Number(bytes);
if (bytes < 0) {
return '0 B';
}
const units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
const k = 1024;
if (bytes < k) {
return bytes.toFixed(2) + ' B';
}
const i = Math.floor(Math.log(bytes) / Math.log(k));
const unitIndex = Math.min(Math.max(i, 0), units.length - 1);
const value = bytes / Math.pow(k, unitIndex);
return value.toFixed(2) + ' ' + units[unitIndex];
}
// =============== 获取在线设备信息 ===============
async function getOnlineDevices(token) {
try {
// 尝试获取会话/设备信息
const possiblePaths = [
'/api/v1/user/server/session',
'/api/v1/user/session',
'/api/v1/user/devices'
];
for (const path of possiblePaths) {
try {
const url = `${CONFIG.url}${path}`;
const response = await axios({
method: 'GET',
url: url,
headers: {
'Authorization': token,
'Accept': 'application/json',
},
timeout: 5000,
validateStatus: () => true
});
if (response.status === 200 && response.data) {
const data = response.data.data || response.data;
// 尝试提取在线设备数
let onlineCount = 0;
if (Array.isArray(data)) {
onlineCount = data.length;
} else if (data.online !== undefined) {
onlineCount = data.online;
} else if (data.count !== undefined) {
onlineCount = data.count;
}
console.log(`✅ 获取到在线设备数: ${onlineCount}`);
return onlineCount;
}
} catch (e) {
// 继续尝试下一个路径
}
}
console.log('ℹ️ 无法获取在线设备信息');
return null;
} catch (error) {
return null;
}
}
// =============== 获取流量信息(从订阅接口)===============
async function getSubscribeInfo(token) {
try {
const url = `${CONFIG.url}${CONFIG.subscribePath}`;
console.log(`📡 获取订阅信息: ${url}`);
const response = await axios({
method: 'GET',
url: url,
headers: {
'Authorization': token,
'Accept': 'application/json',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
},
timeout: 10000,
validateStatus: () => true
});
if (response.status === 200 && response.data) {
const data = response.data.data || response.data;
let transferUsed = 0;
let transferTotal = 0;
if (data.u !== undefined && data.d !== undefined) {
transferUsed = Number(data.u || 0) + Number(data.d || 0);
transferTotal = Number(data.transfer_enable || 0);
console.log('✅ 从订阅信息获取到流量数据');
}
return {
transferUsed: Number(transferUsed) || 0,
transferTotal: Number(transferTotal) || 0
};
}
return null;
} catch (error) {
console.log(`⚠️ 订阅信息获取失败:`, error.message);
return null;
}
}
// =============== 获取用户信息 ===============
async function getUserInfo(token) {
try {
const url = `${CONFIG.url}${CONFIG.userInfoPath}`;
console.log(`📡 获取用户信息: ${url}`);
const response = await axios({
method: 'GET',
url: url,
headers: {
'Authorization': token,
'Accept': 'application/json',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
},
timeout: 10000,
validateStatus: () => true
});
if (response.status === 200 && response.data) {
const data = response.data.data || response.data;
let transferUsed = 0;
let transferTotal = 0;
if (data.u !== undefined && data.d !== undefined) {
transferUsed = Number(data.u || 0) + Number(data.d || 0);
transferTotal = Number(data.transfer_enable || 0);
console.log('✅ 从用户信息获取到流量数据');
} else {
console.log('ℹ️ 用户信息中无流量数据,尝试订阅接口...');
const subscribeInfo = await getSubscribeInfo(token);
if (subscribeInfo) {
transferUsed = Number(subscribeInfo.transferUsed || 0);
transferTotal = Number(subscribeInfo.transferTotal || 0);
}
}
transferUsed = Number(transferUsed) || 0;
transferTotal = Number(transferTotal) || 0;
// 获取在线设备数
const onlineDevices = await getOnlineDevices(token);
const userInfo = {
email: data.email || '未知',
transferUsed: transferUsed,
transferTotal: transferTotal,
expireTime: data.expired_at,
planId: data.plan_id,
deviceLimit: data.device_limit || null,
onlineDevices: onlineDevices,
uuid: data.uuid
};
console.log(`\n✅ 解析后的用户信息:`);
console.log(` 📧 邮箱: ${userInfo.email}`);
console.log(` 📊 已用: ${formatTraffic(userInfo.transferUsed)}`);
console.log(` 📊 总量: ${formatTraffic(userInfo.transferTotal)}`);
if (userInfo.deviceLimit) {
console.log(` 📱 在线设备: ${userInfo.onlineDevices !== null ? userInfo.onlineDevices : '?'}/${userInfo.deviceLimit}`);
}
return userInfo;
} else {
console.log(`⚠️ 用户信息获取失败: HTTP ${response.status}`);
return null;
}
} catch (error) {
console.log(`⚠️ 获取用户信息异常:`, error.message);
return null;
}
}
// =============== 签到函数 ===============
async function checkin(token, index) {
const name = `账号${index}`;
console.log(`\n${'='.repeat(50)}`);
console.log(`【${name}】开始签到`);
console.log(`${'='.repeat(50)}`);
const userInfo = await getUserInfo(token);
try {
const url = `${CONFIG.url}${CONFIG.checkinPath}`;
console.log(`📍 请求地址: ${url}`);
console.log(`🔑 Token前缀: ${token.substring(0, 30)}...`);
const response = await axios({
method: 'POST',
url: url,
headers: {
'Content-Type': 'application/json',
'Authorization': token,
'Accept': '*/*',
'Origin': CONFIG.url,
'Referer': `${CONFIG.url}/index.php`,
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
},
data: {},
timeout: 10000,
validateStatus: () => true
});
console.log(`\n📊 响应状态: ${response.status}`);
console.log(`📦 响应数据:`, response.data);
let message = '';
let success = false;
let rewardTraffic = 0;
if (response.status === 200) {
success = true;
const data = response.data;
if (typeof data === 'object') {
if (data.data && data.data.bonus) {
rewardTraffic = data.data.bonus;
}
const rawMsg = data.message || data.msg || '';
if (data.data?.success === true) {
console.log(`✅ 【${name}】签到成功!`);
message = `签到成功${rewardTraffic ? `,获得 ${rewardTraffic}GB 流量` : ''}`;
} else if (data.data?.success === false && data.data?.reason === 'already') {
console.log(`ℹ️ 【${name}】今天已签到过`);
message = '今日已签到';
} else if (rawMsg && (rawMsg.includes('重复') || rawMsg.includes('已签到'))) {
console.log(`ℹ️ 【${name}】今天已签到过`);
message = '今日已签到';
} else {
console.log(`✅ 【${name}】签到完成`);
message = rawMsg || '签到完成';
}
} else {
message = String(data);
console.log(`✅ 【${name}】签到成功`);
}
} else {
console.log(`❌ 【${name}】签到失败`);
message = `签到失败 (HTTP ${response.status})`;
}
console.log(`📝 签到信息: ${message}`);
return {
success,
name,
message,
userInfo,
rewardTraffic,
data: response.data
};
} catch (error) {
console.log(`❌ 【${name}】签到异常`);
let errorMsg = '';
if (error.response) {
errorMsg = `HTTP ${error.response.status}`;
console.log(`📛 服务器返回:`, error.response.data);
} else if (error.request) {
errorMsg = '网络超时或无响应';
console.log(`📛 网络错误`);
} else {
errorMsg = error.message;
console.log(`📛 错误:`, error.message);
}
return {
success: false,
name,
message: errorMsg,
userInfo,
error: errorMsg
};
}
}
// =============== 发送通知 ===============
async function sendNotify(title, content) {
try {
const paths = ['./sendNotify', '../sendNotify', '/ql/scripts/sendNotify'];
for (const path of paths) {
try {
const notify = require(path);
await notify.sendNotify(title, content);
console.log('✅ 通知发送成功(sendNotify)');
return true;
} catch (e) {}
}
} catch (e) {}
const TG_BOT_TOKEN = process.env.TG_BOT_TOKEN || process.env.TELEGRAM_BOT_TOKEN;
const TG_USER_ID = process.env.TG_USER_ID || process.env.TELEGRAM_CHAT_ID;
if (!TG_BOT_TOKEN || !TG_USER_ID) {
console.log('ℹ️ 未配置通知');
return false;
}
try {
const url = `https://api.telegram.org/bot${TG_BOT_TOKEN}/sendMessage`;
const response = await axios.post(url, {
chat_id: TG_USER_ID,
text: `${title}\n\n${content}`,
parse_mode: 'HTML'
}, { timeout: 15000 });
if (response.data.ok) {
console.log('✅ Telegram 通知发送成功');
return true;
}
} catch (error) {
console.log('❌ 通知发送失败:', error.message);
}
return false;
}
// =============== 主程序 ===============
async function main() {
console.log('\n🚀 ========== 机场自动签到脚本 ==========');
console.log(`⏰ 执行时间: ${new Date().toLocaleString('zh-CN', {timeZone: 'Asia/Shanghai'})}`);
console.log(`📱 机场名称: ${CONFIG.name}`);
const tokens = getTokens();
if (tokens.length === 0) {
console.log('\n❌ 未找到有效的Token,脚本终止');
return;
}
console.log(`📊 找到 ${tokens.length} 个账号`);
const results = [];
for (let i = 0; i < tokens.length; i++) {
const result = await checkin(tokens[i], i + 1);
results.push(result);
if (i < tokens.length - 1) {
console.log('\n⏳ 等待3秒后继续...');
await new Promise(resolve => setTimeout(resolve, 3000));
}
}
console.log(`\n${'='.repeat(50)}`);
console.log('📊 签到汇总');
console.log(`${'='.repeat(50)}`);
const successCount = results.filter(r => r.success).length;
const failCount = results.length - successCount;
console.log(`✅ 成功: ${successCount} 个`);
console.log(`❌ 失败: ${failCount} 个\n`);
results.forEach(r => {
const icon = r.success ? '✅' : '❌';
console.log(`${icon} ${r.name}: ${r.message}`);
if (r.userInfo) {
console.log(` 📧 ${r.userInfo.email}`);
if (r.userInfo.transferUsed > 0 || r.userInfo.transferTotal > 0) {
const used = formatTraffic(r.userInfo.transferUsed);
const total = formatTraffic(r.userInfo.transferTotal);
let infoStr = ` 📊 已用 ${used} / 总计 ${total}`;
if (r.userInfo.deviceLimit) {
const online = r.userInfo.onlineDevices !== null ? r.userInfo.onlineDevices : '?';
infoStr += ` 在线设备 ${online}/${r.userInfo.deviceLimit}`;
}
console.log(infoStr);
}
}
});
// =============== 构建通知消息(官网风格)===============
let notifyMsg = `📢 <b>✈️ ${CONFIG.name}签到通知</b>\n\n`;
notifyMsg += `⏰ ${new Date().toLocaleString('zh-CN', {timeZone: 'Asia/Shanghai'})}\n`;
notifyMsg += `📊 统计: 成功 ${successCount} / 失败 ${failCount}\n\n`;
notifyMsg += `${'─'.repeat(30)}\n\n`;
results.forEach((r, index) => {
const icon = r.success ? '✅' : '❌';
notifyMsg += `${icon} <b>${r.name}</b>\n`;
notifyMsg += ` ${r.message}\n\n`;
if (r.userInfo) {
notifyMsg += ` 📧 账号: <code>${r.userInfo.email}</code>\n`;
if (r.userInfo.transferUsed > 0 || r.userInfo.transferTotal > 0) {
const used = formatTraffic(r.userInfo.transferUsed);
const total = formatTraffic(r.userInfo.transferTotal);
// 官网风格:已用 XXX / 总计 XXX 在线设备 X/X
let trafficInfo = ` 📊 已用 ${used} / 总计 ${total}`;
if (r.userInfo.deviceLimit) {
const online = r.userInfo.onlineDevices !== null ? r.userInfo.onlineDevices : '?';
trafficInfo += ` 在线设备 ${online}/${r.userInfo.deviceLimit}`;
}
notifyMsg += trafficInfo + '\n';
} else {
notifyMsg += ` 📊 流量: 试用账号 / 无统计\n`;
}
// 到期时间(如果有)
if (r.userInfo.expireTime) {
const expireDate = new Date(r.userInfo.expireTime * 1000).toLocaleDateString('zh-CN');
notifyMsg += ` ⏰ 到期: ${expireDate}\n`;
}
}
notifyMsg += '\n';
// 每个账号之间加分隔线(除了最后一个)
if (index < results.length - 1) {
notifyMsg += `${'─'.repeat(30)}\n\n`;
}
});
await sendNotify(`✈️ ${CONFIG.name}签到通知`, notifyMsg);
console.log('\n🎉 脚本执行完成!');
console.log(`${'='.repeat(50)}\n`);
}
// =============== 执行 ===============
main().catch(err => {
console.error('\n💥 脚本执行失败:', err);
process.exit(1);
});