Commit d76bc7aa82f0cc49a40a7c0c99780b0ca75f0a37
1 parent
3f33ca2d
mall + pay:
1、初步完成微信扫码支付,暂时缺少状态的处理
Showing
7 changed files
with
107 additions
and
11 deletions
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/dto/order/PayOrderUnifiedRespDTO.java
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/PayClientFactoryImpl.java
| ... | ... | @@ -5,10 +5,7 @@ import cn.iocoder.yudao.framework.pay.core.client.PayClient; |
| 5 | 5 | import cn.iocoder.yudao.framework.pay.core.client.PayClientConfig; |
| 6 | 6 | import cn.iocoder.yudao.framework.pay.core.client.PayClientFactory; |
| 7 | 7 | import cn.iocoder.yudao.framework.pay.core.client.impl.alipay.*; |
| 8 | -import cn.iocoder.yudao.framework.pay.core.client.impl.weixin.WxLitePayClient; | |
| 9 | -import cn.iocoder.yudao.framework.pay.core.client.impl.weixin.WXNativePayClient; | |
| 10 | -import cn.iocoder.yudao.framework.pay.core.client.impl.weixin.WxPayClientConfig; | |
| 11 | -import cn.iocoder.yudao.framework.pay.core.client.impl.weixin.WxPubPayClient; | |
| 8 | +import cn.iocoder.yudao.framework.pay.core.client.impl.weixin.*; | |
| 12 | 9 | import cn.iocoder.yudao.framework.pay.core.enums.PayChannelEnum; |
| 13 | 10 | import lombok.extern.slf4j.Slf4j; |
| 14 | 11 | |
| ... | ... | @@ -58,11 +55,14 @@ public class PayClientFactoryImpl implements PayClientFactory { |
| 58 | 55 | PayChannelEnum channelEnum = PayChannelEnum.getByCode(channelCode); |
| 59 | 56 | Assert.notNull(channelEnum, String.format("支付渠道(%s) 为空", channelEnum)); |
| 60 | 57 | // 创建客户端 |
| 61 | - // TODO @芋艿 WX_LITE WX_APP 如果不添加在 项目启动的时候去初始化会报错无法启动。所以我手动加了两个,具体需要你来配 | |
| 58 | + // TODO @芋艿 WX_APP 如果不添加在 项目启动的时候去初始化会报错无法启动。所以我手动加了两个,具体需要你来配 | |
| 62 | 59 | switch (channelEnum) { |
| 60 | + // 微信支付 | |
| 63 | 61 | case WX_PUB: return (AbstractPayClient<Config>) new WxPubPayClient(channelId, (WxPayClientConfig) config); |
| 64 | 62 | case WX_LITE: return (AbstractPayClient<Config>) new WxLitePayClient(channelId, (WxPayClientConfig) config); |
| 65 | 63 | case WX_APP: return (AbstractPayClient<Config>) new WxPubPayClient(channelId, (WxPayClientConfig) config); |
| 64 | + case WX_BAR: return (AbstractPayClient<Config>) new WxBarPayClient(channelId, (WxPayClientConfig) config); | |
| 65 | + // 支付宝支付 | |
| 66 | 66 | case WX_NATIVE: return (AbstractPayClient<Config>) new WXNativePayClient(channelId, (WxPayClientConfig) config); |
| 67 | 67 | case ALIPAY_WAP: return (AbstractPayClient<Config>) new AlipayWapPayClient(channelId, (AlipayPayClientConfig) config); |
| 68 | 68 | case ALIPAY_QR: return (AbstractPayClient<Config>) new AlipayQrPayClient(channelId, (AlipayPayClientConfig) config); | ... | ... |
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/weixin/WxBarPayClient.java
0 → 100644
| 1 | +package cn.iocoder.yudao.framework.pay.core.client.impl.weixin; | |
| 2 | + | |
| 3 | +import cn.hutool.core.map.MapUtil; | |
| 4 | +import cn.hutool.core.util.StrUtil; | |
| 5 | +import cn.iocoder.yudao.framework.common.util.json.JsonUtils; | |
| 6 | +import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDTO; | |
| 7 | +import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedRespDTO; | |
| 8 | +import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundUnifiedReqDTO; | |
| 9 | +import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundUnifiedRespDTO; | |
| 10 | +import cn.iocoder.yudao.framework.pay.core.enums.PayChannelEnum; | |
| 11 | +import cn.iocoder.yudao.framework.pay.core.enums.PayDisplayModeEnum; | |
| 12 | +import com.github.binarywang.wxpay.bean.request.WxPayMicropayRequest; | |
| 13 | +import com.github.binarywang.wxpay.bean.result.WxPayMicropayResult; | |
| 14 | +import com.github.binarywang.wxpay.constant.WxPayConstants; | |
| 15 | +import com.github.binarywang.wxpay.exception.WxPayException; | |
| 16 | + | |
| 17 | +public class WxBarPayClient extends AbstractWxPayClient { | |
| 18 | + | |
| 19 | + public WxBarPayClient(Long channelId, WxPayClientConfig config) { | |
| 20 | + super(channelId, PayChannelEnum.WX_BAR.getCode(), config); | |
| 21 | + } | |
| 22 | + | |
| 23 | + @Override | |
| 24 | + protected void doInit() { | |
| 25 | + super.doInit(WxPayConstants.TradeType.MICROPAY); | |
| 26 | + } | |
| 27 | + | |
| 28 | + @Override | |
| 29 | + protected PayOrderUnifiedRespDTO doUnifiedOrderV2(PayOrderUnifiedReqDTO reqDTO) throws WxPayException { | |
| 30 | + // 构建 WxPayMicropayRequest 对象 | |
| 31 | + WxPayMicropayRequest request = WxPayMicropayRequest.newBuilder() | |
| 32 | + .outTradeNo(reqDTO.getMerchantOrderId()) | |
| 33 | + .body(reqDTO.getSubject()) | |
| 34 | + .detail(reqDTO.getBody()) | |
| 35 | + .totalFee(reqDTO.getAmount()) // 单位分 | |
| 36 | + .timeExpire(formatDateV2(reqDTO.getExpireTime())) | |
| 37 | + .spbillCreateIp(reqDTO.getUserIp()) | |
| 38 | + .authCode(getAuthCode(reqDTO)) | |
| 39 | + .build(); | |
| 40 | + // 执行请求 | |
| 41 | + WxPayMicropayResult response = client.micropay(request); | |
| 42 | + | |
| 43 | + // 转换结果 | |
| 44 | + // TODO 芋艿:这里后面要看看 | |
| 45 | + return new PayOrderUnifiedRespDTO().setDisplayMode(PayDisplayModeEnum.CUSTOM.getMode()) | |
| 46 | + .setDisplayContent(JsonUtils.toJsonString(response)); | |
| 47 | + } | |
| 48 | + | |
| 49 | + @Override | |
| 50 | + protected PayOrderUnifiedRespDTO doUnifiedOrderV3(PayOrderUnifiedReqDTO reqDTO) throws WxPayException { | |
| 51 | + return doUnifiedOrderV2(reqDTO); | |
| 52 | + } | |
| 53 | + | |
| 54 | + @Override | |
| 55 | + protected PayRefundUnifiedRespDTO doUnifiedRefund(PayRefundUnifiedReqDTO reqDTO) { | |
| 56 | + return null; | |
| 57 | + } | |
| 58 | + | |
| 59 | + // ========== 各种工具方法 ========== | |
| 60 | + static String getAuthCode(PayOrderUnifiedReqDTO reqDTO) { | |
| 61 | + String authCode = MapUtil.getStr(reqDTO.getChannelExtras(), "authCode"); | |
| 62 | + if (StrUtil.isEmpty(authCode)) { | |
| 63 | + throw new IllegalArgumentException("支付请求的 authCode 不能为空!"); | |
| 64 | + } | |
| 65 | + return authCode; | |
| 66 | + } | |
| 67 | + | |
| 68 | +} | ... | ... |
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/weixin/WxPubPayClient.java
| ... | ... | @@ -42,7 +42,8 @@ public class WxPubPayClient extends AbstractWxPayClient { |
| 42 | 42 | // 构建 WxPayUnifiedOrderRequest 对象 |
| 43 | 43 | WxPayUnifiedOrderRequest request = WxPayUnifiedOrderRequest.newBuilder() |
| 44 | 44 | .outTradeNo(reqDTO.getMerchantOrderId()) |
| 45 | - .body(reqDTO.getBody()) | |
| 45 | + .body(reqDTO.getSubject()) | |
| 46 | + .detail(reqDTO.getBody()) | |
| 46 | 47 | .totalFee(reqDTO.getAmount()) // 单位分 |
| 47 | 48 | .timeExpire(formatDateV2(reqDTO.getExpireTime())) |
| 48 | 49 | .spbillCreateIp(reqDTO.getUserIp()) |
| ... | ... | @@ -62,7 +63,7 @@ public class WxPubPayClient extends AbstractWxPayClient { |
| 62 | 63 | // 构建 WxPayUnifiedOrderRequest 对象 |
| 63 | 64 | WxPayUnifiedOrderV3Request request = new WxPayUnifiedOrderV3Request(); |
| 64 | 65 | request.setOutTradeNo(reqDTO.getMerchantOrderId()); |
| 65 | - request.setDescription(reqDTO.getBody()); | |
| 66 | + request.setDescription(reqDTO.getSubject()); | |
| 66 | 67 | request.setAmount(new WxPayUnifiedOrderV3Request.Amount().setTotal(reqDTO.getAmount())); // 单位分 |
| 67 | 68 | request.setTimeExpire(formatDateV3(reqDTO.getExpireTime())); |
| 68 | 69 | request.setPayer(new WxPayUnifiedOrderV3Request.Payer().setOpenid(getOpenid(reqDTO))); | ... | ... |
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/enums/PayChannelEnum.java
| ... | ... | @@ -9,7 +9,6 @@ import lombok.Getter; |
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | 11 | * 支付渠道的编码的枚举 |
| 12 | - * 枚举值 | |
| 13 | 12 | * |
| 14 | 13 | * @author 芋道源码 |
| 15 | 14 | */ |
| ... | ... | @@ -21,6 +20,7 @@ public enum PayChannelEnum { |
| 21 | 20 | WX_LITE("wx_lite", "微信小程序支付", WxPayClientConfig.class), |
| 22 | 21 | WX_APP("wx_app", "微信 App 支付", WxPayClientConfig.class), |
| 23 | 22 | WX_NATIVE("wx_native", "微信 native 支付", WxPayClientConfig.class), |
| 23 | + WX_BAR("wx_bar", "微信付款码支付", WxPayClientConfig.class), | |
| 24 | 24 | |
| 25 | 25 | ALIPAY_PC("alipay_pc", "支付宝 PC 网站支付", AlipayPayClientConfig.class), |
| 26 | 26 | ALIPAY_WAP("alipay_wap", "支付宝 Wap 网站支付", AlipayPayClientConfig.class), | ... | ... |
yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/order/PayOrderStatusEnum.java
| ... | ... | @@ -17,7 +17,7 @@ public enum PayOrderStatusEnum implements IntArrayValuable { |
| 17 | 17 | |
| 18 | 18 | WAITING(0, "未支付"), |
| 19 | 19 | SUCCESS(10, "支付成功"), |
| 20 | - CLOSED(20, "支付关闭"), // 未付款交易超时关闭,或支付完成后全额退款 TODO 芋艿:需要优化下 | |
| 20 | + CLOSED(20, "支付关闭"), // 未付款交易超时关闭,或支付完成后全额退款 | |
| 21 | 21 | ; |
| 22 | 22 | |
| 23 | 23 | private final Integer status; | ... | ... |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/order/AppPayOrderController.http
| 1 | -### /pay/create 提交支付订单 | |
| 1 | +### /pay/create 提交支付订单【alipay_pc】 | |
| 2 | 2 | POST {{appApi}}/pay/order/submit |
| 3 | 3 | Content-Type: application/json |
| 4 | 4 | Authorization: Bearer {{appToken}} |
| ... | ... | @@ -8,3 +8,31 @@ tenant-id: {{appTenentId}} |
| 8 | 8 | "id": 174, |
| 9 | 9 | "channelCode": "alipay_pc" |
| 10 | 10 | } |
| 11 | + | |
| 12 | +### /pay/create 提交支付订单【wx_bar】 | |
| 13 | +POST {{appApi}}/pay/order/submit | |
| 14 | +Content-Type: application/json | |
| 15 | +Authorization: Bearer {{appToken}} | |
| 16 | +tenant-id: {{appTenentId}} | |
| 17 | + | |
| 18 | +{ | |
| 19 | + "id": 202, | |
| 20 | + "channelCode": "wx_bar", | |
| 21 | + "channelExtras": { | |
| 22 | + "authCode": "132527737910208222" | |
| 23 | + } | |
| 24 | +} | |
| 25 | + | |
| 26 | +### /pay/create 提交支付订单【wx_pub】 | |
| 27 | +POST {{appApi}}/pay/order/submit | |
| 28 | +Content-Type: application/json | |
| 29 | +Authorization: Bearer {{appToken}} | |
| 30 | +tenant-id: {{appTenentId}} | |
| 31 | + | |
| 32 | +{ | |
| 33 | + "id": 202, | |
| 34 | + "channelCode": "wx_pub", | |
| 35 | + "channelExtras": { | |
| 36 | + "openid": "ockUAwIZ-0OeMZl9ogcZ4ILrGba0" | |
| 37 | + } | |
| 38 | +} | ... | ... |