# Stripe 接入 Server酱：支付事件实时推送到微信（2026 教程）

> 通过 Stripe Webhook 将付款、订阅、退款等事件实时推送到微信，支持直连和中转两种方案

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

# Stripe + Server酱：支付事件实时推送到微信

> 效果：Stripe 收到新付款、订阅、退款等事件时，自动推送到微信

## 前置条件

- Server酱 SendKey：登录 sct.ftqq.com，在「SendKey」页面复制（[30 秒获取教程](https://sct.ftqq.com/docs/getting-started/sendkey/)）
- Stripe 账户，且有权限访问 Developers 设置
- （可选）Cloudflare Workers 或其他云函数平台，用于中转动态内容

## 配置步骤

### 方案一：直连（固定标题，最简单）

在 Stripe 中进入 Developers → Webhooks → 添加端点，Endpoint URL 填入以下地址（中文已 URL 编码）：

```
https://sctapi.ftqq.com/你的SENDKEY.send?title=Stripe%E6%9C%89%E6%96%B0%E4%BA%8B%E4%BB%B6
```

选择要监听的事件类型，保存即可。Stripe 每次触发事件都会向该 URL POST JSON，Server酱 服务端优先读取 URL query 中的 `title` 作为消息标题。

> 如果你的 SendKey 以 `sctp` 开头（Server酱³），端点改为 `https://{uid}.push.ft07.com/send/{SendKey}.send`，其中 uid 是 sctp 后面的数字。

Server酱 支持推送到微信服务号/企业微信/钉钉/飞书等多个通道，详见 [/getting-started/channels/](https://sct.ftqq.com/docs/getting-started/channels/)。

### 方案二：中转（动态标题+正文，可校验签名）

直连方案只能推送固定标题。若要把金额、客户邮箱等动态内容送进 `desp`，需要一层中转：用 Cloudflare Workers 或云函数接收 Stripe 的 Webhook，解析 JSON 后再转发给 Server酱。

中转服务地址填入 Stripe Webhook 的 Endpoint URL，例如：

```
https://your-worker.your-subdomain.workers.dev/
```

## 完整示例

以下 Cloudflare Workers 代码接收 Stripe Webhook，提取事件类型与关键字段，转发到 Server酱：

```javascript
export default {
  async fetch(request, env) {
    const payload = await request.json();
    const eventType = payload.type || 'unknown';
    const obj = payload.data?.object || {};

    const title = `Stripe: ${eventType}`;
    const desp = [
      `**事件类型**: ${eventType}`,
      `**金额**: ${obj.amount ? (obj.amount / 100).toFixed(2) : 'N/A'} ${obj.currency || ''}`,
      `**客户邮箱**: ${obj.customer_email || obj.receipt_email || 'N/A'}`,
      `**事件ID**: ${payload.id || 'N/A'}`,
    ].join('\n\n');

    const apiUrl = `https://sctapi.ftqq.com/${env.SERVERCHAN_SENDKEY}.send`;
    await fetch(apiUrl, {
      method: 'POST',
      headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
      body: new URLSearchParams({ title, desp }),
    });

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

部署后在 Workers 设置中添加环境变量 `SERVERCHAN_SENDKEY`，值为你的 SendKey。Stripe 会在请求头中携带签名，请根据 Stripe 官方文档在代码中增加签名校验逻辑后再处理请求。

## 常见问题

**免费额度够用吗？**

Server酱 免费版每天 5 条消息，每分钟上限 50 条。Stripe 事件量不大时完全够用；订阅会员目前特价最低 3 元/月，一天最多可发 1000 条（[价格详情](https://sct.ftqq.com/subscribe)）。

**配置后收不到消息怎么办？**

先检查 Stripe Webhook 日志中请求是否返回 2xx，再确认 SendKey 是否正确。更多排查步骤见 [/getting-started/faq/](https://sct.ftqq.com/docs/getting-started/faq/)。

**Stripe 事件太多会触发频率限制吗？**

Server酱 每分钟上限 50 条。如果短时间内大量事件并发（如批量退款），建议在中转层做合并或限流。

**直连方案能看到付款金额吗？**

不能。直连方案 `title` 固定，`desp` 为空。需要动态内容请使用方案二的中转方式。

## 相关集成

- [/integrations/python/](https://sct.ftqq.com/docs/integrations/python/) —— Python 脚本推送
- [/integrations/uptime-kuma/](https://sct.ftqq.com/docs/integrations/uptime-kuma/) —— Uptime Kuma 宕机告警
- [/integrations/qinglong/](https://sct.ftqq.com/docs/integrations/qinglong/) —— 青龙面板任务通知


## 懒人方案：把这段话复制给你的 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 条结果摘要即可，批量任务合并成一条，不要每步都推。
请根据我当前的项目和场景直接写好代码/配置并验证。
```

