Files
OpticalSystem/jy_pay/README.md
一休哥哥6666 e186d45bec Initial commit
2026-06-14 14:39:51 +08:00

75 lines
3.0 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.

# jy_pay 支付模块
基于 **微信支付 APIv3** 的 Native 支付能力与支付日志记录。
## 功能
- **微信 Native 预下单**:生成 `code_url`,供前台生成二维码,用户扫码支付。
- **支付结果回调**:验签、解密并更新支付日志;可在此扩展订单状态等业务逻辑。
- **支付日志表** `jy_pay_log`:记录每笔预下单与支付结果,便于对账与排查。
## 依赖与接入
- 根工程 `pom.xml` 已加入模块:`<module>jy_pay</module>`,并在 `dependencyManagement` 中声明 `jy_pay`
- 主应用(如 `back`)在 `pom.xml` 中增加对 `jy_pay` 的依赖后,会通过 `@MapperScan("com.ruoyi.**.mapper")``classpath*:mapper/**/*Mapper.xml` 自动扫描本模块的 Mapper 与 XML。
## 数据库
执行项目根目录下 `sql/jy_pay.sql`,创建表 `jy_pay_log`(与主库同库即可)。
## 配置
`application-xxx.yml` 中增加微信支付配置(可参考 `jy_pay/src/main/resources/application-jypay.yml`
```yaml
wechat:
pay:
enabled: true
merchant-id: "你的商户号"
private-key-path: "/绝对路径/apiclient_key.pem"
merchant-serial-number: "商户API证书序列号"
api-v3-key: "32字节APIv3密钥"
app-id: "公众号/开放平台appid"
notify-url: "https://你的域名/pay/api/wechat/native/notify"
```
`notify-url` 需在微信商户平台配置,且公网可访问。未配置或 `enabled: false` 时,仅不创建微信 Config不影响启动。
## 接口说明
| 说明 | 方法 | 路径 |
|------------|------|------------------------------------|
| Native 预下单 | POST | `/pay/api/wechat/native/prepay` |
| 微信支付回调 | POST | `/pay/api/wechat/native/notify` |
### 预下单请求参数
- `outTradeNo`(必填):商户订单号,唯一。
- `description`(必填):商品描述。
- `totalFen`(必填):金额,单位:分。
- `bizType`(可选):业务类型,默认 `ORDER`
- `bizId`(可选):业务主键,如订单 ID默认与 `outTradeNo` 一致。
### 预下单响应
- 成功:`{"codeUrl":"weixin://wxpay/...", "payLogId": 1}`,前台用 `codeUrl` 生成二维码。
- 失败:`{"errorCode":"xxx", "errorMsg":"xxx"}`
## 支付日志状态
- `0`:待支付(预下单成功)
- `1`:已支付
- `2`:已关闭
- `3`:已退款
- `4`:失败
## 与订单联动
- 支付日志:回调中会调用 `payLogService.updateToPaid(...)` 更新 `jy_pay_log`
- 订单表 `shop_order`:当预下单时 `bizType=ORDER``outTradeNo` 为订单的 `order_number` 时,回调中会调用 jy-shop 的 `IOrderService`,将对应订单更新为已支付:
- `status = 1`(待发货)
- `is_payed = 1`
- `pay_time``update_time` 为当前时间
仅当订单当前为待付款(`status=0`)时才会更新,避免重复回调导致错误。
- jy_pay 已依赖 jy-shop主应用需同时引入 jy-shop 与 jy_pay订单回写才会生效。