export default { async fetch(request) { const url = new URL(request.url); // 兼容 ?key= 或 ?data= 参数 const rawData = url.searchParams.get("key") || url.searchParams.get("data"); // 如果没有传入参数,显示一个极简的输入网页 if (!rawData) { const html = ` 邮箱Token接码

📩 邮箱 Token 自动提取

`; return new Response(html, { headers: { "Content-Type": "text/html;charset=UTF-8" } }); } // --- 开始处理 Token --- 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 { // 请求商家的取件 API (获取收件箱最新邮件) 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" // 可根据需要改为 "Junk" }) }); const data = await apiRes.json(); // 解析 API 返回的内容 if (data.code === 200 && data.content) { // 使用正则提取验证码,通常是 6 位纯数字 (兼容 4-8 位) 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("请求失败", "无法连接到取件API:" + error.message); } }, // 辅助渲染结果网页的函数 renderPage(title, content, isSuccess = false) { const color = isSuccess ? "#4caf50" : "#ff5252"; const size = isSuccess ? "4rem" : "1.5rem"; const html = ` ${title}
${title}
${content}
如果没有新邮件,请等待几秒后点击刷新
`; return new Response(html, { headers: { "Content-Type": "text/html;charset=UTF-8" } }); } };