admin/docs/微信在线支付联调清单.md
zzh d0618509e5 feat: 订单余额优先+微信补差混合支付
新增 order_pay 支付单行与创建/回调入账,复用微信 status/close,未成功前不扣余额。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-12-01 18:01:18 +08:00

55 lines
3.2 KiB
Markdown
Raw Permalink 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.

# 微信在线支付联调清单(Native + JSAPI)
## 前置
- [ ] 商户平台已开通 **Native**、**JSAPI**,并绑定运营公众号 AppId(与系统「微信公众号」配置一致)
- [ ] 已执行 `sql/migrate_payment_order_wechat_20261201.sql`(或新库已含 `t_payment_order`)
- [ ] 收款配置 → **微信支付商户**:MchId、证书序列号、APIv3 Key、私钥 PEM、NotifyUrl、启用开关
- [ ] NotifyUrl 为公网 HTTPS,形如 `https://{api-host}/pay/wechat/notify`;本地需隧道(frp/ngrok)
- [ ] 防火墙放行微信支付回调网段(若有 IP 限制)
## 金额与幂等
- [ ] 金额换算:OMS 元 → 微信 **分**(`AwayFromZero`),禁止浮点误差
- [ ] 回调:原始 body 验签 → AES-GCM 解密 → `trade_state=SUCCESS` → 校验金额/商户号 → 幂等入账
- [ ] 重复回调返回 200,余额只加一次
- [ ] 前端成功页不可信;以 `/recharge/pay/wechat/status` 或本地 Success 为准
## PC Native
- [ ] 充值页选「微信在线支付」→ 生成动态码(`code_url`)
- [ ] 微信扫码支付成功 → 约 2s 内轮询到 Success → 结果页;余额到账、充值单 Approved
- [ ] 取消支付 → 调关单,本地 Closed
- [ ] 丢回调场景:后台 `WeChatPayReconcileWorker`(约 2 分钟一轮,创建超过 3 分钟未终态)查单补入账
## 公众号 / H5 JSAPI
- [ ] 微信内打开客户中心充值 →「微信在线支付」→ 调起收银台
- [ ] 客户无 `WechatOpenid` 时走 `snsapi_base` 授权,后端换 openid 并回写客户后再下单
- [ ] 支付成功后查单确认 → 成功文案「余额已到账」
- [ ] 非微信浏览器:提示改用微信内打开或 PC 扫码(首期不做手机浏览器 H5 支付)
## 与凭证充值并存
- [ ] 静态收款码 / 银行转账仍走截图 + 审批入账
- [ ] 在线微信 **不走** ApprovalGate
## 订单混合支付(余额优先 + 微信补差)
- [ ] 已执行 `sql/migrate_payment_order_order_pay_20261201.sql`(`t_payment_order.BalanceAmount`、`t_payment_order_line`;`BizType=order_pay`)
- [ ] 单客户、余额充足:PC/H5 仍走余额,create 返回 `paidImmediately=true`(不调微信)
- [ ] 单客户、余额不足:创建时写入 PaymentOrder + lines,**未付成功前不扣余额**
- [ ] PC Native:确认支付 → 二维码 → 轮询 Success → 订单已付、余额按 `BalanceAmount` 扣减、券/积分与 `/order/pay` 一致
- [ ] H5 JSAPI:微信内调起 → 成功以 status 确认;取消/失败调 close;未确认不伪造成功(确认中文案)
- [ ] 同客户多票:一笔微信补差覆盖多条 line;Finalize 时已付 line 跳过
- [ ] 多客户批量:仅余额;前端禁用微信补差并提示按客户拆分
- [ ] 关单 / 微信 CLOSED:只关支付单,订单仍待付、余额未动
- [ ] 金额校验:微信实付仅比对补差 `Amount`(非应付总额)
- [ ] 复用 `/recharge/pay/wechat/status|close|notify`;创建走 `POST /order/pay/wechat/create`
## 监控建议
- 日志关键字:`微信支付回调验签失败`、`入账失败`、`查单补偿失败`
- 关注:Creating/Paying 堆积、Notify 5xx 比例、关单后仍 Success 的对账差异;订单混合支付另关注 `order_pay` Finalize 跳过已付 line