feat: add payment provider webhooks

This commit is contained in:
Codex
2026-06-28 22:42:27 +08:00
parent dee82e670f
commit db65295ddc
11 changed files with 1286 additions and 39 deletions
+69 -1
View File
@@ -146,7 +146,7 @@ tenant:<tenantId>:theme
| 知识手册 | `/api/catalog/handbook-subjects``handbook-chapters``handbook-entries` |
| 分数线 | `/api/scoreline/fields``schools``majors``records``trend``years` |
| 资料下载 | `/api/catalog/assets``/api/catalog/assets/download` |
| 商城 | `/api/catalog/svip-plans``POST /api/commerce/orders` |
| 商城 | `/api/catalog/svip-plans``POST /api/commerce/orders``POST /api/commerce/payments/create` |
| 订单/权益 | `/api/commerce/orders``/api/commerce/entitlements` |
| 激活码兑换 | `POST /api/commerce/activation-codes/redeem` |
| 个人中心 | `GET/PATCH /api/profile/me` |
@@ -245,6 +245,74 @@ identity.unionId
- 如果登录前已经解析到推广码,登录成功后再调用 `/api/referral/bind` 完成首绑保护。
- 手机号授权后续应走独立的“绑定手机号”接口,不要把微信手机号解密逻辑写在页面里。
## 支付对接
支付流程必须以后端订单金额和后端回调为准,前端只负责拉起支付。
### 创建订单
```text
POST /api/commerce/orders
body: {
"planId": "<svipPlanId>",
"quantity": 1,
"payProvider": "wechat_pay | alipay",
"payMethod": "jsapi | wap",
"regionId": "<regionId>"
}
```
返回 `orderNo` 后,再创建支付参数:
```text
POST /api/commerce/payments/create
body: {
"orderNo": "<orderNo>",
"provider": "wechat_pay",
"openId": "<微信小程序登录后的 openId>"
}
```
微信小程序返回的 `paymentParams` 可直接映射到 `Taro.requestPayment`
```text
appId
timeStamp
nonceStr
package
signType
paySign
```
支付宝 H5/WAP 返回:
```text
paymentParams.url
```
H5 可以跳转到该 URL。小程序端如果后续要接支付宝小程序,需要新增独立 provider/method,不要复用 H5 WAP URL。
支付完成后前端不要自行开通会员。前端应轮询或重新请求:
```text
GET /api/commerce/orders
GET /api/commerce/entitlements
```
后端支付回调地址由租户支付账户配置:
```text
/api/commerce/payments/notify/wechat_pay?tenantId=<tenantId>
/api/commerce/payments/notify/alipay?tenantId=<tenantId>
```
前端禁止:
- 传入自定义金额。
- 伪造支付成功状态。
- 保存商户号私钥、API v3 key、支付宝应用私钥。
- 在页面里实现 webhook 验签或权益开通。
## 第一阶段页面建议
1. `pages/bootstrap/index`