Files
AIclinicalresearch/backend/DEPLOY_TO_SAE_FOR_WECHAT_MP.md
HaHafeng 61cdc97eeb feat(platform): Fix pg-boss queue conflict and add safety standards
Summary:
- Fix pg-boss queue conflict (duplicate key violation on queue_pkey)
- Add global error listener to prevent process crash
- Reduce connection pool from 10 to 4
- Add graceful shutdown handling (SIGTERM/SIGINT)
- Fix researchWorker recursive call bug in catch block
- Make screeningWorker idempotent using upsert

Security Standards (v1.1):
- Prohibit recursive retry in Worker catch blocks
- Prohibit payload bloat (only store fileKey/ID in job.data)
- Require Worker idempotency (upsert + unique constraint)
- Recommend task-specific expireInSeconds settings
- Document graceful shutdown pattern

New Features:
- PKB signed URL endpoint for document preview/download
- pg_bigm installation guide for Docker
- Dockerfile.postgres-with-extensions for pgvector + pg_bigm

Documentation:
- Update Postgres-Only async task processing guide (v1.1)
- Add troubleshooting SQL queries
- Update safety checklist

Tested: Local verification passed
2026-01-23 22:07:26 +08:00

169 lines
2.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 部署微信服务号到SAE快速指南
## 🎯 目标
将微信服务号回调服务部署到SAE生产环境使用域名`iit.xunzhengyixue.com`
---
## 📋 Step 1: 确认环境变量配置
编辑 `backend/.env`,确认以下配置存在:
```env
# 微信服务号配置
WECHAT_MP_APP_ID=wx062568ff49e4570c
WECHAT_MP_APP_SECRET=c0d19435d1a1e948939c16d767ec0faf
WECHAT_MP_TOKEN=IitPatientWechat2026JanToken
WECHAT_MP_ENCODING_AES_KEY=VIzwMGRG4Ll8Sd7fPxPXLlBaWdsh2rK2qIGpyaEoc1v
```
---
## 📋 Step 2: 在SAE控制台配置环境变量
1. **登录阿里云SAE控制台**
2. **进入应用管理 → 选择应用**
3. **配置管理 → 环境变量**
4. **添加以下环境变量**
```
WECHAT_MP_APP_ID=wx062568ff49e4570c
WECHAT_MP_APP_SECRET=c0d19435d1a1e948939c16d767ec0faf
WECHAT_MP_TOKEN=IitPatientWechat2026JanToken
WECHAT_MP_ENCODING_AES_KEY=VIzwMGRG4Ll8Sd7fPxPXLlBaWdsh2rK2qIGpyaEoc1v
```
5. **保存配置**
---
## 📋 Step 3: 部署代码到SAE
```bash
cd D:\MyCursor\AIclinicalresearch\backend
.\deploy-to-sae.ps1
```
**等待部署完成**约5-10分钟
---
## 📋 Step 4: 验证部署
访问以下URL确认服务正常
```
https://iit.xunzhengyixue.com/api/v1/iit/health
```
**期望返回**
```json
{
"status": "ok",
"module": "iit-manager",
"version": "1.1.0"
}
```
---
## 📋 Step 5: 配置微信公众平台
1. **登录微信公众平台**https://mp.weixin.qq.com/
2. **进入:设置与开发 → 基本配置 → 服务器配置**
3. **点击"修改配置"**
4. **填写以下信息**
| 配置项 | 值 |
|--------|-----|
| **URL** | `https://iit.xunzhengyixue.com/wechat/patient/callback` |
| **Token** | `IitPatientWechat2026JanToken` |
| **EncodingAESKey** | `VIzwMGRG4Ll8Sd7fPxPXLlBaWdsh2rK2qIGpyaEoc1v` |
| **消息加解密方式** | **安全模式(推荐)** |
| **数据格式** | **XML** |
5. **点击"提交"**
6. **验证成功后点击"启用"**
---
## ✅ 验证成功标志
### 配置阶段:
- ✅ 页面显示"配置成功"
- ✅ 服务器配置状态为"已启用"
### 测试阶段:
1. **关注公众号**AI for 临床研究
2. **查看SAE日志**,应该看到:
```
📥 收到微信服务号回调消息
🔐 检测到加密消息,开始解密...
✅ 消息解密成功
👤 用户关注公众号
```
---
## 🔧 如何查看SAE日志
1. **登录阿里云SAE控制台**
2. **应用管理 → 选择应用 → 实例管理**
3. **点击"日志" → "实时日志"**
4. **查看最近的日志输出**
---
## 📝 优势
使用生产环境的优势:
- ✅ 域名 `iit.xunzhengyixue.com` 已备案
- ✅ HTTPS证书已配置
- ✅ 已在企业微信中验证过
- ✅ 无需natapp内网穿透
- ✅ 稳定性更好
- ✅ 无需配置域名验证
---
## ⏱️ 预计用时
- 配置环境变量2分钟
- 部署到SAE5-10分钟
- 配置微信公众平台3分钟
- **总计10-15分钟**
---
**立即开始部署!** 🚀