export default {
async fetch(request) {
const url = new URL(request.url);
const rawData = url.searchParams.get("key") || url.searchParams.get("data");
// 1. 如果没有传入参数,显示输入网页
if (!rawData) {
const html = `
邮箱Token接码
📩 邮箱 Token 自动提取
`;
return new Response(html, { headers: { "Content-Type": "text/html;charset=UTF-8" } });
}
// 2. 如果带了参数,Worker 作为后端直接去请求商家接口 (无跨域问题)
const parts = rawData.split('----');
if (parts.length < 4) {
return this.renderPage("格式解析错误", "数据必须包含 '----' 分隔符且至少4段");
}
const email = parts[0];
const clientId = parts[2];
const refreshToken = parts[3];
try {
// 在云端发起请求
const apiRes = await fetch("https://apple.882263.xyz/api/mail-new", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
email: email,
client_id: clientId,
refresh_token: refreshToken,
mailbox: "INBOX"
})
});
const data = await apiRes.json();
// 3. 解析结果并返回网页
if (data.code === 200 && data.content) {
const match = data.content.match(/\b\d{4,8}\b/);
if (match) {
return this.renderPage("最新验证码", match[0], true);
} else {
return this.renderPage("未提取到纯数字", "邮件内容: " + data.content.substring(0, 50) + "...");
}
} else if (data.msg) {
return this.renderPage("接口提示", data.msg);
} else {
return this.renderPage("未知响应", JSON.stringify(data));
}
} catch (error) {
return this.renderPage("请求彻底失败", "接口无法连接:" + error.message);
}
},
// 渲染结果页的函数
renderPage(title, content, isSuccess = false) {
const color = isSuccess ? "#4caf50" : "#ff5252";
const size = isSuccess ? "4rem" : "1.2rem";
const html = `
${title}
${title}
${content}
遇到错误或没出验证码?点刷新
`;
return new Response(html, { headers: { "Content-Type": "text/html;charset=UTF-8" } });
}
};