# 服务器迁移 — 企微回调恢复清单

Hermes 服务器迁移后，按此顺序检查企微功能恢复。

## 1. Cloudflared Tunnel 确认

```bash
# 确认 tunnel 运行中
systemctl status cloudflared-tunnel

# 确认 ingress 包含 callback 路由
grep -A2 "callback" ~/.cloudflared/config.yml
```

## 2. Cloudflare Dashboard — Public Hostname

⚠️ **config.yml 有 ingress 规则 ≠ 公网可达**

必须去 Cloudflare Zero Trust 后台逐条确认：
1. Networks → Tunnels → 找到 tunnel
2. Public Hostname → 确认 `callback.yourdomain.com` 存在
3. Service: `HTTP → localhost:8645`

验证：`curl -sI https://callback.yourdomain.com/wecom/callback | grep server`
- `server: cloudflare` → 后台 Public Hostname 缺失
- `server: Python/3.11 aiohttp` → 已到达 Hermes

## 3. Hermes wecom_callback 配置

确认 `~/.hermes/config.yaml`：
```yaml
wecom_callback:
  enabled: true
  extra:
    host: "0.0.0.0"
    port: 8645
    path: "/wecom/callback"
```

确认端口监听：`ss -tlnp | grep 8645`

## 4. 企微后台回调 URL

企微后台 → 应用管理 → 自建应用 → 接收消息：
- URL: `https://callback.yourdomain.com/wecom/callback`
- Token + EncodingAESKey 需与 config.yaml 一致

## 5. IP 白名单（最易遗漏）

**回调验证成功 ≠ 能收发消息**

企微后台 → 应用管理 → 自建应用 → 企业可信IP → **添加新服务器公网 IP**

诊断：
```bash
curl -s "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=<ID>&corpsecret=<SECRET>"
# errcode 60020 = IP 不在白名单
```

## 快速全链路测试

```bash
# 1. 外网可达性
curl -sI https://callback.gdcjgk.net/wecom/callback | grep server

# 2. 端口监听
ss -tlnp | grep 8645

# 3. 企微 API 可达性
curl -s "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=wwbcfb7cbc0f8912d7&corpsecret=2ad1mn5mqxMuopQxWpc0QCZG0EEfAlu9pr7DIA66p4s" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('errmsg','OK'))"

# 4. 最近回调日志
grep -i "callback\|verify" ~/.hermes/logs/gateway.log | tail -5
```
