diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AbstractAlipayClient.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AbstractAlipayClient.java index 30cdc1c14..41c473be7 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AbstractAlipayClient.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AbstractAlipayClient.java @@ -2,6 +2,7 @@ package cn.iocoder.yudao.framework.pay.core.client.impl.alipay; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.date.DateUtil; +import cn.hutool.http.HttpUtil; import cn.iocoder.yudao.framework.pay.core.client.AbstractPayCodeMapping; import cn.iocoder.yudao.framework.pay.core.client.PayCommonResult; import cn.iocoder.yudao.framework.pay.core.client.dto.*; @@ -133,17 +134,17 @@ public abstract class AbstractAlipayClient extends AbstractPayClient strToMap(String s) { + // TODO @zxy:这个可以使用 hutool 的 HttpUtil decodeParams 方法么? Map stringStringMap = new HashMap<>(); - //调整时间格式 + // 调整时间格式 String s3 = s.replaceAll("%3A", ":"); - //获取map + // 获取 map String s4 = s3.replace("+", " "); String[] split = s4.split("&"); for (String s1 : split) { @@ -152,4 +153,5 @@ public abstract class AbstractAlipayClient extends AbstractPayClient { @@ -91,15 +92,13 @@ public class WXLitePayClient extends AbstractPayClient { return PayCommonResult.build(CODE_SUCCESS, MESSAGE_SUCCESS, response, codeMapping); } - private WxPayMpOrderResult unifiedOrderV2(PayOrderUnifiedReqDTO reqDTO) throws WxPayException { // 构建 WxPayUnifiedOrderRequest 对象 WxPayUnifiedOrderRequest request = WxPayUnifiedOrderRequest.newBuilder() .outTradeNo(reqDTO.getMerchantOrderId()) .body(reqDTO.getBody()) .totalFee(reqDTO.getAmount().intValue()) // 单位分 - //v2的时间格式 - .timeExpire(DateUtil.format(reqDTO.getExpireTime(), "yyyyMMddHHmmss")) + .timeExpire(DateUtil.format(reqDTO.getExpireTime(), "yyyyMMddHHmmss")) // v2的时间格式 .spbillCreateIp(reqDTO.getUserIp()) .openid(getOpenid(reqDTO)) .notifyUrl(reqDTO.getNotifyUrl()) @@ -119,11 +118,8 @@ public class WXLitePayClient extends AbstractPayClient { .setTotal(reqDTO .getAmount() .intValue())); // 单位分 - //v3的时间格式 - request.setTimeExpire(DateUtil.format(reqDTO.getExpireTime(), "yyyy-MM-dd'T'HH:mm:ssXXX")); - request.setPayer(new WxPayUnifiedOrderV3Request - .Payer() - .setOpenid(getOpenid(reqDTO))); + request.setTimeExpire(DateUtil.format(reqDTO.getExpireTime(), "yyyy-MM-dd'T'HH:mm:ssXXX")); // v3的时间格式 + request.setPayer(new WxPayUnifiedOrderV3Request.Payer().setOpenid(getOpenid(reqDTO))); request.setSceneInfo(new WxPayUnifiedOrderV3Request.SceneInfo().setPayerClientIp(reqDTO.getUserIp())); request.setNotifyUrl(reqDTO.getNotifyUrl()); // 执行请求 @@ -140,7 +136,7 @@ public class WXLitePayClient extends AbstractPayClient { /** * - * 微信支付回调 分v2 和v3 的处理方式 + * 微信支付回调 分 v2 和v3 的处理方式 * * @param data 通知结果 * @return 支付回调对象 @@ -148,7 +144,7 @@ public class WXLitePayClient extends AbstractPayClient { */ @Override public PayOrderNotifyRespDTO parseOrderNotify(PayNotifyDataDTO data) throws WxPayException { - log.info("微信支付回调data数据:{}", data.getBody()); + log.info("[parseOrderNotify][微信支付回调data数据:{}]", data.getBody()); // 微信支付 v2 回调结果处理 switch (config.getApiVersion()) { case WXPayClientConfig.API_VERSION_V2: @@ -158,14 +154,14 @@ public class WXLitePayClient extends AbstractPayClient { default: throw new IllegalArgumentException(String.format("未知的 API 版本(%s)", config.getApiVersion())); } - } private PayOrderNotifyRespDTO parseOrderNotifyV3(PayNotifyDataDTO data) throws WxPayException { WxPayOrderNotifyV3Result wxPayOrderNotifyV3Result = client.parseOrderNotifyV3Result(data.getBody(), null); WxPayOrderNotifyV3Result.DecryptNotifyResult result = wxPayOrderNotifyV3Result.getResult(); // 转换结果 - Assert.isTrue(Objects.equals(wxPayOrderNotifyV3Result.getResult().getTradeState(), "SUCCESS"), "支付结果非 SUCCESS"); + Assert.isTrue(Objects.equals(wxPayOrderNotifyV3Result.getResult().getTradeState(), "SUCCESS"), + "支付结果非 SUCCESS"); return PayOrderNotifyRespDTO .builder() diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/wx/WXNativePayClient.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/wx/WXNativePayClient.java index 87be10024..20ad91c82 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/wx/WXNativePayClient.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/wx/WXNativePayClient.java @@ -29,9 +29,14 @@ import static cn.iocoder.yudao.framework.common.util.json.JsonUtils.toJsonString import static cn.iocoder.yudao.framework.pay.core.client.impl.wx.WXCodeMapping.CODE_SUCCESS; import static cn.iocoder.yudao.framework.pay.core.client.impl.wx.WXCodeMapping.MESSAGE_SUCCESS; - +/** + * 微信 App 支付 + * + * @author zwy + */ @Slf4j public class WXNativePayClient extends AbstractPayClient { + private WxPayService client; public WXNativePayClient(Long channelId, WXPayClientConfig config) { @@ -62,7 +67,7 @@ public class WXNativePayClient extends AbstractPayClient { @Override public PayCommonResult doUnifiedOrder(PayOrderUnifiedReqDTO reqDTO) { // 这里原生的返回的是支付的 url 所以直接使用string接收 - //"invokeResponse": "weixin://wxpay/bizpayurl?pr=EGYAem7zz" + // "invokeResponse": "weixin://wxpay/bizpayurl?pr=EGYAem7zz" String responseV3; try { switch (config.getApiVersion()) { @@ -110,12 +115,9 @@ public class WXNativePayClient extends AbstractPayClient { request.setSceneInfo(new WxPayUnifiedOrderV3Request.SceneInfo().setPayerClientIp(reqDTO.getUserIp())); request.setNotifyUrl(reqDTO.getNotifyUrl()); // 执行请求 - - return client.createOrderV3(TradeTypeEnum.NATIVE, request); } - /** * * 微信支付回调 分v2 和v3 的处理方式 @@ -136,15 +138,14 @@ public class WXNativePayClient extends AbstractPayClient { default: throw new IllegalArgumentException(String.format("未知的 API 版本(%s)", config.getApiVersion())); } - } private PayOrderNotifyRespDTO parseOrderNotifyV3(PayNotifyDataDTO data) throws WxPayException { WxPayOrderNotifyV3Result wxPayOrderNotifyV3Result = client.parseOrderNotifyV3Result(data.getBody(), null); WxPayOrderNotifyV3Result.DecryptNotifyResult result = wxPayOrderNotifyV3Result.getResult(); // 转换结果 - Assert.isTrue(Objects.equals(wxPayOrderNotifyV3Result.getResult().getTradeState(), "SUCCESS"), "支付结果非 SUCCESS"); - + Assert.isTrue(Objects.equals(wxPayOrderNotifyV3Result.getResult().getTradeState(), "SUCCESS"), + "支付结果非 SUCCESS"); return PayOrderNotifyRespDTO .builder() .orderExtensionNo(result.getOutTradeNo()) @@ -171,14 +172,15 @@ public class WXNativePayClient extends AbstractPayClient { @Override public PayRefundNotifyDTO parseRefundNotify(PayNotifyDataDTO notifyData) { - //TODO 需要实现 + // TODO 需要实现 throw new UnsupportedOperationException("需要实现"); } @Override protected PayCommonResult doUnifiedRefund(PayRefundUnifiedReqDTO reqDTO) throws Throwable { - //TODO 需要实现 + // TODO 需要实现 throw new UnsupportedOperationException(); } + } diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/wx/WXPayClientConfig.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/wx/WXPayClientConfig.java index 507243c0b..294f8e4ff 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/wx/WXPayClientConfig.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/wx/WXPayClientConfig.java @@ -11,8 +11,6 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.util.Set; -// TODO 芋艿:参数校验 - /** * 微信支付的 PayClientConfig 实现类 * 属性主要来自 {@link com.github.binarywang.wxpay.config.WxPayConfig} 的必要属性 @@ -22,7 +20,6 @@ import java.util.Set; @Data public class WXPayClientConfig implements PayClientConfig { - // TODO 芋艿:V2 or V3 客户端 /** * API 版本 - V2 * https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_1 diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/wx/WXPubPayClient.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/wx/WXPubPayClient.java index 281f3fea3..238344759 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/wx/WXPubPayClient.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/wx/WXPubPayClient.java @@ -139,7 +139,7 @@ public class WXPubPayClient extends AbstractPayClient { */ @Override public PayOrderNotifyRespDTO parseOrderNotify(PayNotifyDataDTO data) throws WxPayException { - log.info("微信支付回调data数据:{}", data.getBody()); + log.info("[parseOrderNotify][微信支付回调data数据: {}]", data.getBody()); // 微信支付 v2 回调结果处理 switch (config.getApiVersion()) { case WXPayClientConfig.API_VERSION_V2: @@ -155,7 +155,8 @@ public class WXPubPayClient extends AbstractPayClient { WxPayOrderNotifyV3Result wxPayOrderNotifyV3Result = client.parseOrderNotifyV3Result(data.getBody(), null); WxPayOrderNotifyV3Result.DecryptNotifyResult result = wxPayOrderNotifyV3Result.getResult(); // 转换结果 - Assert.isTrue(Objects.equals(wxPayOrderNotifyV3Result.getResult().getTradeState(), "SUCCESS"), "支付结果非 SUCCESS"); + Assert.isTrue(Objects.equals(wxPayOrderNotifyV3Result.getResult().getTradeState(), "SUCCESS"), + "支付结果非 SUCCESS"); return PayOrderNotifyRespDTO .builder() .orderExtensionNo(result.getOutTradeNo()) @@ -182,14 +183,13 @@ public class WXPubPayClient extends AbstractPayClient { @Override public PayRefundNotifyDTO parseRefundNotify(PayNotifyDataDTO notifyData) { - //TODO 需要实现 + // TODO 需要实现 throw new UnsupportedOperationException("需要实现"); } - @Override protected PayCommonResult doUnifiedRefund(PayRefundUnifiedReqDTO reqDTO) throws Throwable { - //TODO 需要实现 + // TODO 需要实现 throw new UnsupportedOperationException(); } diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/enums/PayChannelEnum.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/enums/PayChannelEnum.java index a708faf8e..0754f9dae 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/enums/PayChannelEnum.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/enums/PayChannelEnum.java @@ -22,7 +22,6 @@ public enum PayChannelEnum { WX_APP("wx_app", "微信 App 支付", WXPayClientConfig.class), WX_NATIVE("wx_native", "微信 native 支付", WXPayClientConfig.class), - ALIPAY_PC("alipay_pc", "支付宝 PC 网站支付", AlipayPayClientConfig.class), ALIPAY_WAP("alipay_wap", "支付宝 Wap 网站支付", AlipayPayClientConfig.class), ALIPAY_APP("alipay_app", "支付宝App 支付", AlipayPayClientConfig.class),