# Cloudflare 接入 Server酱：安全与健康事件推送到微信（2026 教程）

> 通过 Notifications 直连或 Workers 中转，将 Cloudflare 告警推送到微信。含配置步骤与 Worker 代码示例。

- 网页版：https://sct.ftqq.com/docs/integrations/cloudflare/
- 更新日期：2026-07-17

# Cloudflare + Server酱：安全与健康事件推送到微信

> 效果：Cloudflare 的安全与健康事件触发时，微信立即收到推送通知。

## 前置条件

- 获取 Server酱 SendKey（参考 [30 秒获取 SendKey](https://sct.ftqq.com/docs/getting-started/sendkey/)）
- 拥有 Cloudflare 账号及需要监控的域名/服务

## 配置步骤

Cloudflare Notifications 支持 Webhook，可通过两种方式接入 Server酱。

### 方法一：Notifications 直连（固定标题）

在 Cloudflare Notifications 中添加 Webhook destination，URL 直接填写以下地址（中文需 urlencode）：

```text
https://sctapi.ftqq.com/你的SENDKEY.send?title=Cloudflare%E5%91%8A%E8%AD%A6
```

随后在具体的通知规则中选择此 Webhook 作为目标即可。此方式 title 固定为"Cloudflare告警"，正文为 Cloudflare 默认发送的 JSON 内容。

### 方法二：Workers 通用中转（自定义内容）

如果需要提取告警 JSON 中的具体字段作为标题或正文，可使用 Cloudflare Workers 做中转。这也是所有"只发固定 JSON"平台的通用中转方案。

1. 创建 Worker 并绑定环境变量 `SERVERCHAN_SENDKEY`，值为你的 SendKey。如果是 Server酱³（SendKey 以 `sctp` 开头），还需绑定 `SERVERCHAN_UID`（UID 取自 sctp 后的数字）。
2. 部署 Worker 代码（见下方完整示例）。
3. 在 Cloudflare Notifications 中添加 Webhook destination，URL 填写该 Worker 的路由地址。

## 完整示例

以下为 Cloudflare Worker 中转代码，接收任意平台 POST 过来的固定 JSON，提取字段后转发到 Server酱：

```javascript
export default {
  async fetch(request, env) {
    if (request.method !== 'POST') return new Response('ok');

    const sendkey = env.SERVERCHAN_SENDKEY;
    const uid = env.SERVERCHAN_UID || '';
    const apiUrl = uid
      ? `https://${uid}.push.ft07.com/send/${sendkey}.send`
      : `https://sctapi.ftqq.com/${sendkey}.send`;

    try {
      const payload = await request.json();
      // 根据实际平台 JSON 结构提取字段，以下为示例
      const title = payload.name || 'Cloudflare 告警';
      const desp = payload.text || JSON.stringify(payload, null, 2);

      await fetch(apiUrl, {
        method: 'POST',
        headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
        body: `title=${encodeURIComponent(title)}&desp=${encodeURIComponent(desp)}`
      });
    } catch (e) {
      // 忽略解析错误
    }

    return new Response('ok');
  }
};
```

## 常见问题

**免费额度用完了怎么办？**
Server酱免费版每日提供 5 条推送。订阅会员目前特价最低 3 元/月，一天最多可发 1000 条（[价格详情](https://sct.ftqq.com/subscribe)）。

**配置后没收到消息？**
检查 SendKey 是否正确，以及是否在 Cloudflare 触发了对应事件。也可参考 [常见问题与排查](https://sct.ftqq.com/docs/getting-started/faq/)。

**推送频率有限制吗？**
Server酱 API 限制每分钟请求上限为 50 次，会员每日 API 请求上限为 1000 次。高频告警场景建议在 Worker 中做简单合并。

## 相关集成

- [Uptime Kuma 接入 Server酱](https://sct.ftqq.com/docs/integrations/uptime-kuma/)
- [青龙面板接入 Server酱](https://sct.ftqq.com/docs/integrations/qinglong/)
- [Python 脚本接入 Server酱](https://sct.ftqq.com/docs/integrations/python/)


## 懒人方案：把这段话复制给你的 AI 助手

把下面这段文字原样粘贴给 Claude Code、Cursor 或任何 AI 编程助手，它就会替你完成 Server酱 的接入：

```text
请帮我把 Server酱 微信通知接入到我当前的项目/工具中：
1. API：POST https://sctapi.ftqq.com/{SendKey}.send，参数 title（必填，不能含换行）、desp（正文，支持 Markdown，可选）；成功时返回 JSON 的 code 为 0。
2. 如果我的 SendKey 以 sctp 开头，则改用 https://{uid}.push.ft07.com/send/{SendKey}.send，uid 是 SendKey 中 sctp 与 t 之间的数字。
3. SendKey 从环境变量 SERVERCHAN_SENDKEY 读取；如果没有，提醒我到 https://sct.ftqq.com 免费获取（每天 5 条额度）。
4. 安全要求：不要把 SendKey 硬编码进代码、不要打印到日志、不要提交到 git。
5. 频率约定：任务结束发 1 条结果摘要即可，批量任务合并成一条，不要每步都推。
请根据我当前的项目和场景直接写好代码/配置并验证。
```

