一些机场可以通过签到来领取流量,本脚本可以实现定时自动化签到来实现每天签到的需求,可以通过cloudflare Workers部署,简单方便。
let sites = [];
let BotToken = '';
let ChatID = '';
export default {
async fetch(request, env, ctx) {
await initializeVariables(env);
const url = new URL(request.url);
let output = "";
if (url.pathname === "/tg") {
output = "✅ TG 推送测试成功";
await sendMessage("测试消息", { domain: "", user: "", pass: "" });
} else if (url.pathname === "/checkin") {
output = await runAllCheckins();
} else {
output = "路径错误,请使用 /checkin 或 /tg";
}
return new Response(output, {
status: 200,
headers: { 'Content-Type': 'text/plain;charset=UTF-8' }
});
},
async scheduled(controller, env, ctx) {
await initializeVariables(env);
await runAllCheckins();
}
};
async function initializeVariables(env) {
const configRaw = env.CONFIG || "";
try {
sites = JSON.parse(configRaw);
if (!Array.isArray(sites)) throw new Error("CONFIG 应为数组格式");
} catch (e) {
throw new Error("CONFIG 环境变量解析失败: 请确认是合法 JSON 数组");
}
BotToken = env.TGTOKEN || "";
ChatID = env.TGID || "";
}
async function runAllCheckins() {
const results = [];
for (const site of sites) {
const result = await checkin(site);
results.push(result);
}
return results.join('\n\n');
}
async function checkin({ domain, user, pass }) {
let result = "";
try {
if (!domain.includes("//")) domain = `https://${domain}`;
const loginRes = await fetch(`${domain}/auth/login`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
body: JSON.stringify({
email: user,
passwd: pass,
remember_me: 'on',
code: ""
})
});
if (!loginRes.ok) {
const errText = await loginRes.text();
throw new Error(`登录请求失败: ${errText}`);
}
const loginJson = await loginRes.json();
if (loginJson.ret !== 1) {
throw new Error(`登录失败: ${loginJson.msg || '未知错误'}`);
}
const cookieHeader = loginRes.headers.get('set-cookie');
if (!cookieHeader) throw new Error("登录成功但未获取到 Cookie");
const cookies = cookieHeader.split(',').map(c => c.split(';')[0]).join('; ');
await new Promise(r => setTimeout(r, 1000)); // 等待 1 秒
const checkinRes = await fetch(`${domain}/user/checkin`, {
method: 'POST',
headers: {
'Cookie': cookies,
'Content-Type': 'application/json',
'X-Requested-With': 'XMLHttpRequest'
}
});
const checkinText = await checkinRes.text();
let checkinJson = {};
try {
checkinJson = JSON.parse(checkinText);
} catch (e) {
throw new Error(`签到响应非 JSON: ${checkinText}`);
}
result = `✅ [${domain}] 签到成功: ${checkinJson.msg}`;
} catch (err) {
result = `❌ [${domain}] 签到失败: ${err.message}`;
}
await sendMessage(result, { domain, user, pass });
return result;
}
async function sendMessage(msg, { domain, user, pass }) {
const time = new Date(Date.now() + 8 * 3600 * 1000).toISOString().replace("T", " ").slice(0, 19);
const info = `
🕒 执行时间: ${time}
🌐 域名: ${domain || '-'}
📧 账号: ${user || '-'}
🔑 密码: <tg-spoiler>${pass || '-'}</tg-spoiler>
📢 签到结果: ${msg}
`.trim();
if (BotToken && ChatID) {
const url = `https://api.telegram.org/bot${BotToken}/sendMessage`;
await fetch(`${url}?chat_id=${ChatID}&parse_mode=HTML&text=${encodeURIComponent(info)}`);
}
}
cloudflare设置相关变量
变量名称:CONFIG
[{"domain":"机场域名","user":"注册机场的邮箱","pass":"密码"},{"domain":"机场域名","user":"注册机场的邮箱","pass":"密码"}]
变量名称:TGID 填写你的telegram ID
变量名称:TGTOKEN 填写你的telegram 机器人的Token
所有变量类型为 文本。
然后在项目里面设置一个触发事件就可以了实现每天定时签到了。
手动签到
添加自定义域名以后通过如下格式访问就可以手动签到了
https://自定义域名/checkin