{"id":258,"date":"2025-05-29T09:44:12","date_gmt":"2025-05-29T01:44:12","guid":{"rendered":"https:\/\/feiyangblog.eu.org\/?p=258"},"modified":"2026-03-10T15:14:50","modified_gmt":"2026-03-10T07:14:50","slug":"%e6%9c%ba%e5%9c%ba%e8%87%aa%e5%8a%a8%e7%ad%be%e5%88%b0%e8%84%9a%e6%9c%ac","status":"publish","type":"post","link":"https:\/\/feiyangblog.eu.org\/?p=258","title":{"rendered":"\u673a\u573a\u81ea\u52a8\u7b7e\u5230\u811a\u672c"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u4e00\u4e9b\u673a\u573a\u53ef\u4ee5\u901a\u8fc7\u7b7e\u5230\u6765\u9886\u53d6\u6d41\u91cf\uff0c\u672c\u811a\u672c\u53ef\u4ee5\u5b9e\u73b0\u5b9a\u65f6\u81ea\u52a8\u5316\u7b7e\u5230\u6765\u5b9e\u73b0\u6bcf\u5929\u7b7e\u5230\u7684\u9700\u6c42\uff0c\u53ef\u4ee5\u901a\u8fc7cloudflare Workers\u90e8\u7f72\uff0c\u7b80\u5355\u65b9\u4fbf\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>let sites = &#91;];\nlet BotToken = '';\nlet ChatID = '';\n\nexport default {\n\tasync fetch(request, env, ctx) {\n\t\tawait initializeVariables(env);\n\t\tconst url = new URL(request.url);\n\t\tlet output = \"\";\n\n\t\t\/\/ \u65b0\u589e Telegram webhook \u63a5\u6536\uff0c\u8def\u5f84\u6539\u4e3a \/telegram\uff0c\u4e14\u53ea\u63a5\u53d7 POST\n\t\tif (url.pathname === \"\/telegram\" &amp;&amp; request.method === \"POST\") {\n\t\t\tconst update = await request.json();\n\t\t\tawait handleTelegramWebhook(update);\n\t\t\treturn new Response(\"OK\", { status: 200 });\n\t\t}\n\n\t\t\/\/ \u4fdd\u7559 \/tg \u6d4b\u8bd5\u63a8\u9001\uff0cGET \u8bf7\u6c42\n\t\tif (url.pathname === \"\/tg\" &amp;&amp; request.method === \"GET\") {\n\t\t\toutput = \"\u2705 TG \u63a8\u9001\u6d4b\u8bd5\u6210\u529f\";\n\t\t\tawait sendMessage(\"\u6d4b\u8bd5\u6d88\u606f\", { domain: \"\", user: \"\", pass: \"\" });\n\t\t} else if (url.pathname === \"\/checkin\" &amp;&amp; request.method === \"GET\") {\n\t\t\toutput = await runAllCheckins();\n\t\t} else {\n\t\t\toutput = \"\u274c \u8def\u5f84\u9519\u8bef\uff0c\u8bf7\u4f7f\u7528 \/checkin\u3001\/tg \u6216 POST \/telegram\";\n\t\t}\n\n\t\treturn new Response(output, {\n\t\t\tstatus: 200,\n\t\t\theaders: { 'Content-Type': 'text\/plain;charset=UTF-8' }\n\t\t});\n\t},\n\n\tasync scheduled(controller, env, ctx) {\n\t\tawait initializeVariables(env);\n\t\tawait runAllCheckins();\n\t\tawait registerTelegramWebhook(env); \/\/\u5b9a\u671f\u6ce8\u518c Webhook\n\t}\n};\n\nasync function initializeVariables(env) {\n\tconst configRaw = env.CONFIG || \"\";\n\ttry {\n\t\tsites = JSON.parse(configRaw);\n\t\tif (!Array.isArray(sites)) throw new Error(\"CONFIG \u5e94\u4e3a\u6570\u7ec4\u683c\u5f0f\");\n\t} catch (e) {\n\t\tthrow new Error(\"CONFIG \u73af\u5883\u53d8\u91cf\u89e3\u6790\u5931\u8d25: \u8bf7\u786e\u8ba4\u662f\u5408\u6cd5 JSON \u6570\u7ec4\");\n\t}\n\tBotToken = env.TGTOKEN || \"\";\n\tChatID = env.TGID || \"\";\n}\n\nasync function runAllCheckins() {\n\tconst results = &#91;];\n\tfor (const site of sites) {\n\t\tconst result = await checkin(site);\n\t\tresults.push(result);\n\t}\n\treturn results.join('\\n\\n');\n}\n\nasync function checkin({ domain, user, pass }) {\n\tlet result = \"\";\n\ttry {\n\t\tif (!domain.includes(\"\/\/\")) domain = `https:\/\/${domain}`;\n\t\tconst loginRes = await fetch(`${domain}\/auth\/login`, {\n\t\t\tmethod: 'POST',\n\t\t\theaders: {\n\t\t\t\t'Content-Type': 'application\/json',\n\t\t\t\t'Accept': 'application\/json',\n\t\t\t},\n\t\t\tbody: JSON.stringify({\n\t\t\t\temail: user,\n\t\t\t\tpasswd: pass,\n\t\t\t\tremember_me: 'on',\n\t\t\t\tcode: \"\"\n\t\t\t})\n\t\t});\n\n\t\tif (!loginRes.ok) {\n\t\t\tconst errText = await loginRes.text();\n\t\t\tthrow new Error(`\u767b\u5f55\u8bf7\u6c42\u5931\u8d25: ${errText}`);\n\t\t}\n\n\t\tconst loginJson = await loginRes.json();\n\t\tif (loginJson.ret !== 1) {\n\t\t\tthrow new Error(`\u767b\u5f55\u5931\u8d25: ${loginJson.msg || '\u672a\u77e5\u9519\u8bef'}`);\n\t\t}\n\n\t\tconst cookieHeader = loginRes.headers.get('set-cookie');\n\t\tif (!cookieHeader) throw new Error(\"\u767b\u5f55\u6210\u529f\u4f46\u672a\u83b7\u53d6\u5230 Cookie\");\n\n\t\tconst cookies = cookieHeader.split(',').map(c =&gt; c.split(';')&#91;0]).join('; ');\n\t\tawait new Promise(r =&gt; setTimeout(r, 1000)); \/\/ \u7b49\u5f85 1 \u79d2\n\n\t\tconst checkinRes = await fetch(`${domain}\/user\/checkin`, {\n\t\t\tmethod: 'POST',\n\t\t\theaders: {\n\t\t\t\t'Cookie': cookies,\n\t\t\t\t'Content-Type': 'application\/json',\n\t\t\t\t'X-Requested-With': 'XMLHttpRequest'\n\t\t\t}\n\t\t});\n\n\t\tconst checkinText = await checkinRes.text();\n\t\tlet checkinJson = {};\n\t\ttry {\n\t\t\tcheckinJson = JSON.parse(checkinText);\n\t\t} catch (e) {\n\t\t\tthrow new Error(`\u7b7e\u5230\u54cd\u5e94\u975e JSON: ${checkinText}`);\n\t\t}\n\n\t\tresult = `\u2705 &#91;${domain}] \u7b7e\u5230\u6210\u529f: ${checkinJson.msg}`;\n\t} catch (err) {\n\t\tresult = `\u274c &#91;${domain}] \u7b7e\u5230\u5931\u8d25: ${err.message}`;\n\t}\n\tawait sendMessage(result, { domain, user, pass });\n\treturn result;\n}\n\nasync function sendMessage(msg, { domain, user, pass }) {\n\tconst time = new Date(Date.now() + 8 * 3600 * 1000).toISOString().replace(\"T\", \" \").slice(0, 19);\n\tconst info = `\n\ud83d\udd52 \u6267\u884c\u65f6\u95f4: ${time}\n\ud83c\udf10 \u57df\u540d: ${domain || '-'}\n\ud83d\udce7 \u8d26\u53f7: ${user || '-'}\n\ud83d\udd11 \u5bc6\u7801: &lt;tg-spoiler&gt;${pass || '-'}&lt;\/tg-spoiler&gt;\n\n\ud83d\udce2 \u7b7e\u5230\u7ed3\u679c: ${msg}\n\t`.trim();\n\n\tif (BotToken &amp;&amp; ChatID) {\n\t\tconst url = `https:\/\/api.telegram.org\/bot${BotToken}\/sendMessage`;\n\t\tawait fetch(`${url}?chat_id=${ChatID}&amp;parse_mode=HTML&amp;text=${encodeURIComponent(info)}`);\n\t}\n}\n\n\/\/ \u65b0\u589e\uff1a\u5904\u7406 Telegram Bot \u6d88\u606f webhook\nasync function handleTelegramWebhook(update) {\n\tif (!update.message || !update.message.text) return;\n\n\tconst text = update.message.text.trim();\n\tconst chatId = update.message.chat.id;\n\n\tif (text === \"\/checkin\") {\n\t\tconst result = await runAllCheckins();\n\t} else {\n\t\tawait sendPlainText(chatId, \"\ud83e\udd16 \u53d1\u9001 \/checkin \u6765\u6267\u884c\u7b7e\u5230\u64cd\u4f5c\");\n\t}\n}\n\nasync function sendPlainText(chatId, msg) {\n\tif (!BotToken) return;\n\tconst url = `https:\/\/api.telegram.org\/bot${BotToken}\/sendMessage`;\n\tawait fetch(`${url}?chat_id=${chatId}&amp;text=${encodeURIComponent(msg)}`);\n}\nasync function registerTelegramWebhook(env) {\n\tif (!BotToken || !env.TGURL) return;\n\tif (!env.TGURL.includes(\"\/\/\")) {\n\t\tenv.TGURL = `https:\/\/${env.TGURL}`;\n\t}\n\tconst url = `https:\/\/api.telegram.org\/bot${BotToken}\/setWebhook?url=${encodeURIComponent(env.TGURL)}`;\n\ttry {\n\t\tconst res = await fetch(url);\n\t\tconst result = await res.json();\n\n\t\tif (!result.ok) {\n\t\t\tconsole.warn(\"\u274c \u8bbe\u7f6e Telegram Webhook \u5931\u8d25:\", result);\n\t\t}\n\t} catch (e) {\n\t\tconsole.error(\"\u274c \u8bbe\u7f6e Telegram Webhook \u51fa\u73b0\u5f02\u5e38:\", e.message);\n\t}\n}\n\n\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">cloudflare\u8bbe\u7f6e\u76f8\u5173\u53d8\u91cf<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td>\u53d8\u91cf\u540d\u79f0<\/td><td>  \u793a\u4f8b\u503c<\/td><td>\u63cf\u8ff0<\/td><\/tr><tr><td>CONFIG<\/td><td>[{&#8220;domain&#8221;:&#8221;\u673a\u573a\u57df\u540d&#8221;,&#8221;user&#8221;:&#8221;\u6ce8\u518c\u673a\u573a\u7684\u90ae\u7bb1&#8221;,&#8221;pass&#8221;:&#8221;\u5bc6\u7801&#8221;},{&#8220;domain&#8221;:&#8221;\u673a\u573a\u57df\u540d&#8221;,&#8221;user&#8221;:&#8221;\u6ce8\u518c\u673a\u573a\u7684\u90ae\u7bb1&#8221;,&#8221;pass&#8221;:&#8221;\u5bc6\u7801&#8221;}]<\/td><td>\u652f\u6301\u591a\u673a\u573a\u7b7e\u5230<\/td><\/tr><tr><td>TGID        \uff08\u53ef\u9009\uff09<\/td><td>123456<\/td><td>\u4f60\u7684telegram ID<\/td><\/tr><tr><td>TGTOKEN   \uff08\u53ef\u9009\uff09<\/td><td>7520123456:AAEWbcLnzbcpHSozTjcydffrMRmDyHkjgXA<\/td><td>\u4f60\u7684telegram \u673a\u5668\u4eba\u7684Token<\/td><\/tr><tr><td>TGURL (\u53ef\u9009)<\/td><td>https:\/\/\u81ea\u5b9a\u4e49\u57df\u540d\/telegram<\/td><td>telegram hooks\u8bbf\u95ee\u7684url<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u6240\u6709\u53d8\u91cf\u7c7b\u578b\u4e3a \u6587\u672c\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u81ea\u52a8\u7b7e\u5230<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u9879\u76ee\u91cc\u9762\u8bbe\u7f6e\u4e00\u4e2a\u89e6\u53d1\u4e8b\u4ef6\u5c31\u53ef\u4ee5\u4e86\u5b9e\u73b0\u6bcf\u5929\u5b9a\u65f6\u7b7e\u5230\u4e86\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/feiyangblog.eu.org\/wp-content\/uploads\/2025\/05\/image.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"257\" data-original=\"https:\/\/feiyangblog.eu.org\/wp-content\/uploads\/2025\/05\/image.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-296\"  sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/div><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u624b\u52a8\u7b7e\u5230<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u65b9\u6cd5\u4e00\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6253\u5f00\u6d4f\u89c8\u5668\u8bbf\u95ee\uff1a <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>https:&#47;&#47;\u81ea\u5b9a\u4e49\u57df\u540d\/checkin <\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u65b9\u6cd5\u4e8c\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6253\u5f00\u6d4f\u89c8\u5668\u8bbf\u95ee\uff1a<a href=\"https:\/\/api.telegram.org\/bot7520424041:AAEWbcLnzbcpHSozTjcydffrMRmDyHkjgXA\/setWebhook?url=https:\/\/airportcheckin.feiyang0104.gq\/checkin\">https:\/\/api.telegram.org\/bot&lt;\u4f60\u7684telegram \u673a\u5668\u4eba\u7684Token&gt;\/setWebhook?url=https:\/\/\u81ea\u5b9a\u4e49\u57df\u540d\/telegram<\/a> \uff08\u4ec5\u4e00\u6b21\u5373\u53ef\uff09<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u540e\u7eed  telegram\u673a\u5668\u4eba\u53d1\u9001    <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> \/checkin         <\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5373\u53ef\u5b9e\u73b0\u624b\u52a8\u7b7e\u5230<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u4e9b\u673a\u573a\u53ef\u4ee5\u901a\u8fc7\u7b7e\u5230\u6765\u9886\u53d6\u6d41\u91cf\uff0c\u672c\u811a\u672c\u53ef\u4ee5\u5b9e\u73b0\u5b9a\u65f6\u81ea\u52a8\u5316\u7b7e\u5230\u6765\u5b9e\u73b0\u6bcf\u5929\u7b7e\u5230\u7684\u9700\u6c42\uff0c\u53ef\u4ee5\u901a\u8fc7cloudflare [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_total_topic_count_hidden":0,"_bbp_total_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"wpai_generated_summary":"","wpai_meta_description":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-258","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"views":8977,"_links":{"self":[{"href":"https:\/\/feiyangblog.eu.org\/index.php?rest_route=\/wp\/v2\/posts\/258","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/feiyangblog.eu.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/feiyangblog.eu.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/feiyangblog.eu.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/feiyangblog.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=258"}],"version-history":[{"count":14,"href":"https:\/\/feiyangblog.eu.org\/index.php?rest_route=\/wp\/v2\/posts\/258\/revisions"}],"predecessor-version":[{"id":384,"href":"https:\/\/feiyangblog.eu.org\/index.php?rest_route=\/wp\/v2\/posts\/258\/revisions\/384"}],"wp:attachment":[{"href":"https:\/\/feiyangblog.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=258"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/feiyangblog.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=258"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/feiyangblog.eu.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=258"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}