{"id":1026,"date":"2025-07-11T21:48:38","date_gmt":"2025-07-11T13:48:38","guid":{"rendered":"https:\/\/www.jumoon.top\/?p=1026"},"modified":"2026-01-08T22:58:36","modified_gmt":"2026-01-08T14:58:36","slug":"cf-workers%e7%bb%93%e5%90%88%e9%92%89%e9%92%89%e5%bc%80%e5%8f%91%e5%ae%9e%e7%8e%b0%e6%8c%aa%e8%bd%a6%e6%8f%90%e9%86%92","status":"publish","type":"post","link":"https:\/\/www.jumoon.top\/?p=1026","title":{"rendered":"CF\u524d\u7aef+\u9489\u9489\u540e\u7aef\u5b9e\u73b0\u626b\u7801\u4e00\u952e\u632a\u8f66\u5b9e\u65f6\u63a8\u9001\u6d88\u606f\u5230\u9489\u9489"},"content":{"rendered":"\n<p class=\"has-text-align-center\">\u4e4b\u524d\u770b\u5230\u6709\u4eba\u505a\u4e86\u4e2a\u57fa\u4e8e\u5fae\u4fe1\u7b2c\u4e09\u65b9\u516c\u4f17\u53f7\u7684\u632a\u8f66\u63d0\u9192\uff0c\u4f46\u516c\u4f17\u53f7\u9650\u5236\uff0c\u76ee\u524d\u6ca1\u6cd5\u5b9e\u73b0\u5b9e\u65f6\u63d0\u9192\uff0c\u6240\u4ee5\u8bd5\u7740\u641e\u4e86\u4e2a\u9489\u9489\u7684\u7248\u672c\u3002\u524d\u7aef\u4f7f\u7528CF\uff0c\u540e\u7aef\u4f7f\u7528\u9489\u9489\u5f00\u653e\u5e73\u53f0\uff0c\u521b\u5efa\u5e94\u7528\uff0c\u6388\u6743\u6210\u5458\u4fe1\u606f\u8bfb\u6743\u9650\uff0c\u8c03\u7528\u4f01\u4e1aAPI\u57fa\u7840\u6743\u9650\uff0c\u901a\u8fc7\u4ee3\u7801\u8c03\u7528API\u63a5\u53e3\u5b9e\u73b0\u63a8\u9001\u4fe1\u606f\u3002\u53ef\u7ed1\u5b9a\u81ea\u5b9a\u4e49\u57df\u540d\uff0c\u81f3\u4e8e\u4e8c\u7ef4\u7801\u6709\u5f88\u591a\u5e73\u53f0\u53ef\u4ee5\u751f\u6210\u3002\u672c\u7ad9 \u670d\u52a1-IT\u5de5\u5177 \u4e2d\u4e5f\u53ef\u4ee5\u751f\u6210\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"964\" height=\"436\" src=\"https:\/\/www.jumoon.top\/wp-content\/uploads\/2025\/07\/\u632a\u8f667.png\" alt=\"\" class=\"wp-image-1047\" srcset=\"https:\/\/www.jumoon.top\/wp-content\/uploads\/2025\/07\/\u632a\u8f667.png 964w, https:\/\/www.jumoon.top\/wp-content\/uploads\/2025\/07\/\u632a\u8f667-300x136.png 300w, https:\/\/www.jumoon.top\/wp-content\/uploads\/2025\/07\/\u632a\u8f667-768x347.png 768w\" sizes=\"auto, (max-width: 964px) 100vw, 964px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"683\" height=\"526\" src=\"https:\/\/www.jumoon.top\/wp-content\/uploads\/2025\/07\/\u632a\u8f665-1.png\" alt=\"\" class=\"wp-image-1054\" srcset=\"https:\/\/www.jumoon.top\/wp-content\/uploads\/2025\/07\/\u632a\u8f665-1.png 683w, https:\/\/www.jumoon.top\/wp-content\/uploads\/2025\/07\/\u632a\u8f665-1-300x231.png 300w\" sizes=\"auto, (max-width: 683px) 100vw, 683px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>\u57fa\u4e8e\u5ba2\u6237\u7aefCookie\u8ba1\u65f6\uff0c\u5e26\u65f6\u95f4\u6233\u7248\u672c\uff0c\u65f6\u533a\u4f7f\u7528(UTC+8)\u5373\u5317\u4eac\u65f6\u95f4\uff0c\u52a0\u65f6\u95f4\u6233\u7684\u76ee\u7684\u662f\u786e\u4fdd\u6bcf\u6761\u6d88\u606f\u6587\u672c\u5185\u5bb9\u4e0d\u4e00\u6837\u907f\u514d\u88ab\u9489\u9489\u7684\u53cd\u5783\u573e\u62e6\u622a\u3002<\/p>\n\n\n\n<p class=\"has-text-align-center\">\u90e8\u7f72\u662f\u9700\u8981\u7528\u5230\u8fd95\u4e2a\u73af\u5883\u53d8\u91cf\uff1a<br>APP_KEY &#8211; \u5f00\u653e\u5e73\u53f0\u5e94\u7528\u7684AppKey<br>APP_SECRET &#8211; \u5f00\u653e\u5e73\u53f0\u5e94\u7528\u7684AppSecret<br>AGENT_ID &#8211; \u5e94\u7528\u8be6\u60c5\u9875\u4e2d\u7684AgentId<br>RECEIVER_IDS &#8211; \u63a5\u6536\u4eba\u9489\u9489ID\uff0c\u591a\u4e2a\u65f6\u7528\u9017\u53f7\u5206\u9694\uff0c\u5982\uff1auser001,user002,user003<br>PUSH_INTERVAL &#8211; \u63a8\u9001\u95f4\u9694\u65f6\u95f4\uff08\u5206\u949f\uff09\uff0c\u8bbe\u4e3a0\u8868\u793a\u4e0d\u9650\u5236<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"405\" src=\"https:\/\/www.jumoon.top\/wp-content\/uploads\/2025\/07\/\u632a\u8f661-1024x405.png\" alt=\"\" class=\"wp-image-1027\" srcset=\"https:\/\/www.jumoon.top\/wp-content\/uploads\/2025\/07\/\u632a\u8f661-1024x405.png 1024w, https:\/\/www.jumoon.top\/wp-content\/uploads\/2025\/07\/\u632a\u8f661-300x119.png 300w, https:\/\/www.jumoon.top\/wp-content\/uploads\/2025\/07\/\u632a\u8f661-768x304.png 768w, https:\/\/www.jumoon.top\/wp-content\/uploads\/2025\/07\/\u632a\u8f661.png 1153w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"658\" src=\"https:\/\/www.jumoon.top\/wp-content\/uploads\/2025\/07\/\u632a\u8f666-1024x658.png\" alt=\"\" class=\"wp-image-1044\" srcset=\"https:\/\/www.jumoon.top\/wp-content\/uploads\/2025\/07\/\u632a\u8f666-1024x658.png 1024w, https:\/\/www.jumoon.top\/wp-content\/uploads\/2025\/07\/\u632a\u8f666-300x193.png 300w, https:\/\/www.jumoon.top\/wp-content\/uploads\/2025\/07\/\u632a\u8f666-768x493.png 768w, https:\/\/www.jumoon.top\/wp-content\/uploads\/2025\/07\/\u632a\u8f666.png 1400w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"has-text-align-center\"><br>\u4ee5\u4e0b\u662f\u4ee3\u7801<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>export default {\n  async fetch(request, env, context) {\n    const url = new URL(request.url);\n    \n    \/\/ \u5904\u7406API\u8bf7\u6c42\n    if (url.pathname === '\/api\/send' &amp;&amp; request.method === 'POST') {\n      try {\n        const pushInterval = parseInt(env.PUSH_INTERVAL || \"0\") * 60; \/\/ \u8f6c\u6362\u4e3a\u79d2\n        const now = Math.floor(Date.now() \/ 1000); \/\/ \u5f53\u524d\u65f6\u95f4\u6233(\u79d2)\n        \n        \/\/ \u68c0\u67e5Cookie\u4e2d\u7684\u4e0a\u6b21\u63a8\u9001\u65f6\u95f4\n        const cookie = request.headers.get('Cookie') || '';\n        const lastPushMatch = cookie.match(\/last_push=(\\d+)\/);\n        \n        if (pushInterval &gt; 0 &amp;&amp; lastPushMatch) {\n          const lastPush = parseInt(lastPushMatch&#91;1]);\n          const remainingTime = pushInterval - (now - lastPush);\n          \n          if (remainingTime &gt; 0) {\n            const remainingMinutes = Math.floor(remainingTime \/ 60);\n            const remainingSeconds = remainingTime % 60;\n            \n            return new Response(JSON.stringify({\n              errcode: -2,\n              errmsg: `\u64cd\u4f5c\u8fc7\u4e8e\u9891\u7e41\uff0c\u8bf7${remainingMinutes}:${remainingSeconds.toString().padStart(2, '0')}\u540e\u518d\u8bd5`\n            }), {\n              status: 429,\n              headers: { \n                'Content-Type': 'application\/json',\n                'Set-Cookie': `last_push=${lastPush}; Path=\/; Max-Age=${pushInterval}`\n              }\n            });\n          }\n        }\n        \n        \/\/ \u83b7\u53d6access_token\n        const token = await getAccessToken(env);\n        if (!token) {\n          return new Response(JSON.stringify({\n            errcode: -1,\n            errmsg: \"\u83b7\u53d6access_token\u5931\u8d25\"\n          }), {\n            status: 500,\n            headers: { 'Content-Type': 'application\/json' }\n          });\n        }\n        \n        \/\/ \u89e3\u6790\u8bf7\u6c42\u53c2\u6570\n        const { content = \"\" } = await request.json();\n        const userIds = env.RECEIVER_IDS.split(',').map(id =&gt; id.trim()).filter(id =&gt; id);\n        if (userIds.length === 0) {\n          return new Response(JSON.stringify({\n            errcode: -1,\n            errmsg: \"\u73af\u5883\u53d8\u91cf\u4e2d\u672a\u914d\u7f6e\u6709\u6548\u7684\u63a5\u6536\u4ebaID\"\n          }), {\n            status: 400,\n            headers: { 'Content-Type': 'application\/json' }\n          });\n        }\n        \n        \/\/ \u53d1\u9001\u6d88\u606f\n        const result = await sendDingTalkMessage(userIds, content, token, env);\n        \n        \/\/ \u8bbe\u7f6eCookie\u8bb0\u5f55\u672c\u6b21\u63a8\u9001\u65f6\u95f4\n        const responseHeaders = {\n          'Content-Type': 'application\/json'\n        };\n        \n        if (result.errcode === 0) {\n          responseHeaders&#91;'Set-Cookie'] = `last_push=${now}; Path=\/; Max-Age=${pushInterval}`;\n        }\n        \n        return new Response(JSON.stringify(result), {\n          headers: responseHeaders\n        });\n      } catch (error) {\n        return new Response(JSON.stringify({ \n          errcode: -1,\n          errmsg: error.message \n        }), {\n          status: 500,\n          headers: { 'Content-Type': 'application\/json' }\n        });\n      }\n    }\n\n    \/\/ \u8fd4\u56deHTML\u9875\u9762\n    return new Response(`\n      &lt;!DOCTYPE html&gt;\n      &lt;html lang=\"zh-CN\"&gt;\n      &lt;head&gt;\n          &lt;meta charset=\"UTF-8\"&gt;\n          &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"&gt;\n          &lt;title&gt;\u632a\u8f66\u901a\u77e5&lt;\/title&gt;\n          &lt;style&gt;\n              body {\n                  font-family: Arial, sans-serif;\n                  max-width: 600px;\n                  margin: 0 auto;\n                  padding: 20px;\n                  text-align: center;\n              }\n              h2 {\n                  color: #333;\n              }\n              .container {\n                  margin-top: 30px;\n              }\n              input, button {\n                  margin: 10px 0;\n                  padding: 8px;\n                  width: 100%;\n                  box-sizing: border-box;\n              }\n              button {\n                  background-color: #0080FF;\n                  color: white;\n                  border: none;\n                  padding: 12px 20px;\n                  font-size: 16px;\n                  cursor: pointer;\n                  border-radius: 4px;\n              }\n              button:hover {\n                  background-color: #0066CC;\n              }\n              .form-group {\n                  margin-bottom: 15px;\n                  text-align: left;\n              }\n              label {\n                  display: block;\n                  margin-bottom: 5px;\n                  font-weight: bold;\n              }\n              .info-text {\n                  font-size: 14px;\n                  color: #666;\n                  margin-top: 20px;\n              }\n          &lt;\/style&gt;\n      &lt;\/head&gt;\n      &lt;body&gt;\n          &lt;h2&gt;\u5982\u9700\u901a\u77e5\u8f66\u4e3b\uff0c\u8bf7\u70b9\u51fb\u4e0b\u65b9\u6309\u94ae&lt;\/h2&gt;\n          &lt;div class=\"container\"&gt;\n              &lt;div class=\"form-group\"&gt;\n                  &lt;label for=\"content\"&gt;\u7559\u8a00\u8bf7\u8f93\u5165:&lt;\/label&gt;\n                  &lt;input type=\"text\" id=\"content\" placeholder=\"\u8bf7\u8f93\u5165\u60a8\u7684\u8054\u7cfb\u65b9\u5f0f\uff0c\u6216\u76f4\u63a5\u70b9\u51fb \u901a\u77e5\u8f66\u4e3b\" value=\"\"&gt;\n              &lt;\/div&gt;\n              \n              &lt;button id=\"sendBtn\"&gt;\u901a\u77e5\u8f66\u4e3b&lt;\/button&gt;\n              &lt;div id=\"result\" style=\"margin-top: 20px;\"&gt;&lt;\/div&gt;\n          &lt;\/div&gt;\n\n          &lt;script&gt;\n              document.getElementById('sendBtn').addEventListener('click', async function() {\n                  const customContent = document.getElementById('content').value.trim();\n                  const fixedContent = \"\u60a8\u7684\u8f66\u8f86\u53ef\u80fd\u5360\u9053\u4e86\";\n                  const fullContent = fixedContent + (customContent ? \" -- \" + customContent : \"\");\n                  const resultDiv = document.getElementById('result');\n                  const btn = this;\n                  \n                  btn.disabled = true;\n                  resultDiv.innerHTML = '&lt;p&gt;\u53d1\u9001\u4e2d...&lt;\/p&gt;';\n                  \n                  try {\n                      const response = await fetch('\/api\/send', {\n                          method: 'POST',\n                          headers: {\n                              'Content-Type': 'application\/json'\n                          },\n                          body: JSON.stringify({\n                              content: fullContent\n                          }),\n                          credentials: 'include' \/\/ \u786e\u4fdd\u53d1\u9001Cookie\n                      });\n                      \n                      const result = await response.json();\n                      \n                      if (result.errcode === 0) {\n                          resultDiv.innerHTML = '&lt;p style=\"color:green;\"&gt;\u6d88\u606f\u63a8\u9001\u6210\u529f\uff01&lt;\/p&gt;';\n                      } else if (result.errcode === -2) {\n                          resultDiv.innerHTML = '&lt;p style=\"color:orange;\"&gt;' + result.errmsg + '&lt;\/p&gt;';\n                      } else {\n                          resultDiv.innerHTML = '&lt;p style=\"color:red;\"&gt;\u6d88\u606f\u63a8\u9001\u5931\u8d25: ' + (result.errmsg || '\u672a\u77e5\u9519\u8bef') + '&lt;\/p&gt;';\n                      }\n                  } catch (error) {\n                      resultDiv.innerHTML = '&lt;p style=\"color:red;\"&gt;\u8bf7\u6c42\u51fa\u9519: ' + error.message + '&lt;\/p&gt;';\n                  } finally {\n                      btn.disabled = false;\n                  }\n              });\n          &lt;\/script&gt;\n      &lt;\/body&gt;\n      &lt;\/html&gt;\n    `, {\n      headers: {\n        'Content-Type': 'text\/html; charset=utf-8'\n      }\n    });\n  }\n}\n\n\/\/ \u83b7\u53d6\u9489\u9489access_token\nasync function getAccessToken(env) {\n  const tokenUrl = `https:\/\/oapi.dingtalk.com\/gettoken?appkey=${env.APP_KEY}&amp;appsecret=${env.APP_SECRET}`;\n  \n  const response = await fetch(tokenUrl);\n  const data = await response.json();\n  \n  return data.access_token || null;\n}\n\n\/\/ \u53d1\u9001\u5de5\u4f5c\u901a\u77e5\uff08\u6dfb\u52a0\u4e1c\u516b\u533a\u65f6\u95f4\u6233\u786e\u4fdd\u552f\u4e00\u6027\uff09\nasync function sendDingTalkMessage(userIds, content, token, env) {\n  const apiUrl = `https:\/\/oapi.dingtalk.com\/topapi\/message\/corpconversation\/asyncsend_v2?access_token=${token}`;\n  \n  \/\/ \u83b7\u53d6\u4e1c\u516b\u533a\u65f6\u95f4 (UTC+8)\n  const now = new Date();\n  const utc8Offset = 8 * 60 * 60 * 1000; \/\/ 8\u5c0f\u65f6\u7684\u6beb\u79d2\u6570\n  const beijingTime = new Date(now.getTime() + utc8Offset);\n  \n  \/\/ \u683c\u5f0f\u5316\u4e3aHH:MM:SS\n  const hours = String(beijingTime.getUTCHours()).padStart(2, '0');\n  const minutes = String(beijingTime.getUTCMinutes()).padStart(2, '0');\n  const seconds = String(beijingTime.getUTCSeconds()).padStart(2, '0');\n  const timeStamp = `${hours}:${minutes}:${seconds}`;\n  \n  \/\/ \u5728\u539f\u59cb\u5185\u5bb9\u540e\u6dfb\u52a0\u65f6\u95f4\u6233\n  const uniqueContent = `${content} &#91;${timeStamp}]`;\n  \n  const message = {\n    agent_id: env.AGENT_ID,\n    userid_list: userIds.join(','),\n    msg: {\n      msgtype: \"text\",\n      text: {\n        content: uniqueContent\n      }\n    }\n  };\n  \n  const response = await fetch(apiUrl, {\n    method: 'POST',\n    headers: {\n      'Content-Type': 'application\/json'\n    },\n    body: JSON.stringify(message)\n  });\n  \n  return await response.json();\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4e4b\u524d\u770b\u5230\u6709\u4eba\u505a\u4e86\u4e2a\u57fa\u4e8e\u5fae\u4fe1\u7b2c\u4e09\u65b9\u516c\u4f17\u53f7\u7684\u632a\u8f66\u63d0\u9192\uff0c\u4f46\u516c\u4f17\u53f7\u9650\u5236\uff0c\u76ee\u524d\u6ca1\u6cd5\u5b9e\u73b0\u5b9e\u65f6\u63d0\u9192\uff0c\u6240\u4ee5\u8bd5\u7740\u641e\u4e86\u4e2a\u9489\u9489\u7684\u7248\u672c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-container-style":"default","site-container-layout":"default","site-sidebar-layout":"default","site-transparent-header":"default","disable-article-header":"default","disable-site-header":"default","disable-site-footer":"default","disable-content-area-spacing":"default","footnotes":""},"categories":[19],"tags":[],"class_list":["post-1026","post","type-post","status-publish","format-standard","hentry","category-19"],"_links":{"self":[{"href":"https:\/\/www.jumoon.top\/index.php?rest_route=\/wp\/v2\/posts\/1026","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jumoon.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jumoon.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jumoon.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jumoon.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1026"}],"version-history":[{"count":10,"href":"https:\/\/www.jumoon.top\/index.php?rest_route=\/wp\/v2\/posts\/1026\/revisions"}],"predecessor-version":[{"id":1055,"href":"https:\/\/www.jumoon.top\/index.php?rest_route=\/wp\/v2\/posts\/1026\/revisions\/1055"}],"wp:attachment":[{"href":"https:\/\/www.jumoon.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1026"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jumoon.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1026"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jumoon.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1026"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}