# Gitea接入 Server酱：自建 Git 仓库事件推送到微信（2026 教程）

> 通过 Webhook 将 Gitea 推送、PR、Issue 等事件通知推送到微信，支持直连简单通知与中转动态内容。

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

# Gitea + Server酱：自建 Git 仓库事件推送到微信

> 效果：Gitea 仓库有推送、PR、Issue 等事件时，自动推送到微信

## 前置条件

- 获取 Server酱 SendKey（[30 秒获取教程](https://sct.ftqq.com/docs/getting-started/sendkey/)）
- 拥有 Gitea 仓库的管理权限

## 配置步骤

Gitea 的 Webhook 只能发送固定格式的 JSON，无法自定义消息模板。根据需求选择以下两种接法。

### 接法一：简单直连（固定标题）

只需知道仓库有新事件，不需要看具体内容。

1. 在 Gitea 仓库的 Settings → Webhooks → 添加 Webhook，选择 `Gitea` 类型。
2. 填写 Target URL（直接复制替换 SendKey 即可）：

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

3. HTTP Method 选择 `POST`，触发事件按需勾选。
4. 点击添加。Server酱会优先读取 URL query 中的 title，忽略 Body 中的 JSON。

### 接法二：中转获取动态内容

若需在通知中查看提交信息或 PR 标题，需部署一层中转（如 Cloudflare Workers 或云函数），从 Gitea 的 JSON 提取字段再转发给 Server酱。

1. 部署中转服务，接收 Gitea Webhook 并解析 JSON。
2. 中转服务将提取的内容作为 `title` 或 `desp`，调用 Server酱 API。
3. 在 Gitea 仓库的 Settings → Webhooks → 添加 Webhook，Target URL 填写你的中转服务地址。

如需推送到企业微信、钉钉或飞书群，可配置[消息通道](https://sct.ftqq.com/docs/getting-started/channels/)。

## 完整示例

以下是一个 Cloudflare Workers 中转脚本示例，提取 push 事件的提交信息并转发：

```javascript
export default {
  async fetch(request) {
    const url = new URL(request.url);
    const sendkey = url.searchParams.get('sendkey');
    const payload = await request.json();

    const repo = payload.repository?.full_name || '未知仓库';
    const commits = payload.commits?.map(c => c.message).join('\n') || '无提交信息';
    const title = `Gitea 推送: ${repo}`;
    const desp = commits;

    await fetch(`https://sctapi.ftqq.com/${sendkey}.send`, {
      method: 'POST',
      headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
      body: `title=${encodeURIComponent(title)}&desp=${encodeURIComponent(desp)}`
    });

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

在 Gitea Webhook 配置中，将 Target URL 指向：

```
https://你的中转域名/forward?sendkey=你的SENDKEY
```

## 常见问题

**免费额度是多少？**

每天可发送 5 条消息，每分钟上限 50 条。订阅会员目前特价最低 3 元/月，一天最多可发 1000 条（[价格详情](https://sct.ftqq.com/subscribe)）。

**配置了 Webhook 但微信没收到消息？**

请检查 SendKey 是否正确、触发事件是否匹配，并参考[常见问题与排查](https://sct.ftqq.com/docs/getting-started/faq/)。

**如何推送动态的提交内容到正文？**

Gitea 的 Webhook 格式固定，无法自定义模板。需通过 Cloudflare Workers 或云函数中转，从请求 JSON 中提取字段后再调用 Server酱 API。

## 相关集成

- [Python 脚本推送](https://sct.ftqq.com/docs/integrations/python/)
- [Uptime Kuma 宕机告警](https://sct.ftqq.com/docs/integrations/uptime-kuma/)
- [青龙面板任务通知](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 条结果摘要即可，批量任务合并成一条，不要每步都推。
请根据我当前的项目和场景直接写好代码/配置并验证。
```

