Commit a9acbca78774583a55519397424d7ec6ef3e40ff

Authored by zwy
1 parent 7b17e3bc

:bug:

【微信支付回调】:
WXLitePayClient.java:   添加 v2和 v3的回调数据处理
WXNativePayClient.java: 添加 v2和 v3的回调数据处理
WXPubPayClient.java:    添加 v2和 v3的回调数据处理
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/wx/WXLitePayClient.java
@@ -12,6 +12,7 @@ import cn.iocoder.yudao.framework.pay.core.client.dto.*; @@ -12,6 +12,7 @@ import cn.iocoder.yudao.framework.pay.core.client.dto.*;
12 import cn.iocoder.yudao.framework.pay.core.client.impl.AbstractPayClient; 12 import cn.iocoder.yudao.framework.pay.core.client.impl.AbstractPayClient;
13 import cn.iocoder.yudao.framework.pay.core.enums.PayChannelEnum; 13 import cn.iocoder.yudao.framework.pay.core.enums.PayChannelEnum;
14 import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult; 14 import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult;
  15 +import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyV3Result;
15 import com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult; 16 import com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult;
16 import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest; 17 import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
17 import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderV3Request; 18 import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderV3Request;
@@ -139,13 +140,46 @@ public class WXLitePayClient extends AbstractPayClient<WXPayClientConfig> { @@ -139,13 +140,46 @@ public class WXLitePayClient extends AbstractPayClient<WXPayClientConfig> {
139 140
140 @Override 141 @Override
141 public PayOrderNotifyRespDTO parseOrderNotify(PayNotifyDataDTO data) throws WxPayException { 142 public PayOrderNotifyRespDTO parseOrderNotify(PayNotifyDataDTO data) throws WxPayException {
  143 + log.info("微信支付回调data数据:{}", data.getBody());
  144 + // 微信支付 v2 回调结果处理
  145 + switch (config.getApiVersion()) {
  146 + case WXPayClientConfig.API_VERSION_V2:
  147 + return parseOrderNotifyV2(data);
  148 + case WXPayClientConfig.API_VERSION_V3:
  149 + return parseOrderNotifyV3(data);
  150 + default:
  151 + throw new IllegalArgumentException(String.format("未知的 API 版本(%s)", config.getApiVersion()));
  152 + }
  153 +
  154 + }
  155 +
  156 + private PayOrderNotifyRespDTO parseOrderNotifyV3(PayNotifyDataDTO data) throws WxPayException {
  157 + WxPayOrderNotifyV3Result wxPayOrderNotifyV3Result = client.parseOrderNotifyV3Result(data.getBody(), null);
  158 + WxPayOrderNotifyV3Result.DecryptNotifyResult result = wxPayOrderNotifyV3Result.getResult();
  159 + // 转换结果
  160 +
  161 + return PayOrderNotifyRespDTO
  162 + .builder()
  163 + .orderExtensionNo(result.getOutTradeNo())
  164 + .channelOrderNo(result.getTradeState())
  165 + .successTime(DateUtil.parse(result.getSuccessTime(), "yyyy-MM-dd'T'HH:mm:ssXXX"))
  166 + .data(data.getBody())
  167 + .build();
  168 + }
  169 +
  170 + private PayOrderNotifyRespDTO parseOrderNotifyV2(PayNotifyDataDTO data) throws WxPayException {
142 WxPayOrderNotifyResult notifyResult = client.parseOrderNotifyResult(data.getBody()); 171 WxPayOrderNotifyResult notifyResult = client.parseOrderNotifyResult(data.getBody());
143 Assert.isTrue(Objects.equals(notifyResult.getResultCode(), "SUCCESS"), "支付结果非 SUCCESS"); 172 Assert.isTrue(Objects.equals(notifyResult.getResultCode(), "SUCCESS"), "支付结果非 SUCCESS");
144 // 转换结果 173 // 转换结果
145 - return PayOrderNotifyRespDTO.builder().orderExtensionNo(notifyResult.getOutTradeNo())  
146 - .channelOrderNo(notifyResult.getTransactionId()).channelUserId(notifyResult.getOpenid()) 174 + return PayOrderNotifyRespDTO
  175 + .builder()
  176 + .orderExtensionNo(notifyResult.getOutTradeNo())
  177 + .channelOrderNo(notifyResult.getTransactionId())
  178 + .channelUserId(notifyResult.getOpenid())
147 .successTime(DateUtil.parse(notifyResult.getTimeEnd(), "yyyyMMddHHmmss")) 179 .successTime(DateUtil.parse(notifyResult.getTimeEnd(), "yyyyMMddHHmmss"))
148 - .data(data.getBody()).build(); 180 + .data(data.getBody())
  181 + .build();
  182 +
149 } 183 }
150 184
151 @Override 185 @Override
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/wx/WXNativePayClient.java
@@ -11,6 +11,7 @@ import cn.iocoder.yudao.framework.pay.core.client.dto.*; @@ -11,6 +11,7 @@ import cn.iocoder.yudao.framework.pay.core.client.dto.*;
11 import cn.iocoder.yudao.framework.pay.core.client.impl.AbstractPayClient; 11 import cn.iocoder.yudao.framework.pay.core.client.impl.AbstractPayClient;
12 import cn.iocoder.yudao.framework.pay.core.enums.PayChannelEnum; 12 import cn.iocoder.yudao.framework.pay.core.enums.PayChannelEnum;
13 import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult; 13 import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult;
  14 +import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyV3Result;
14 import com.github.binarywang.wxpay.bean.order.WxPayNativeOrderResult; 15 import com.github.binarywang.wxpay.bean.order.WxPayNativeOrderResult;
15 import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest; 16 import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
16 import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderV3Request; 17 import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderV3Request;
@@ -117,13 +118,46 @@ public class WXNativePayClient extends AbstractPayClient<WXPayClientConfig> { @@ -117,13 +118,46 @@ public class WXNativePayClient extends AbstractPayClient<WXPayClientConfig> {
117 118
118 @Override 119 @Override
119 public PayOrderNotifyRespDTO parseOrderNotify(PayNotifyDataDTO data) throws WxPayException { 120 public PayOrderNotifyRespDTO parseOrderNotify(PayNotifyDataDTO data) throws WxPayException {
  121 + log.info("微信支付回调data数据:{}", data.getBody());
  122 + // 微信支付 v2 回调结果处理
  123 + switch (config.getApiVersion()) {
  124 + case WXPayClientConfig.API_VERSION_V2:
  125 + return parseOrderNotifyV2(data);
  126 + case WXPayClientConfig.API_VERSION_V3:
  127 + return parseOrderNotifyV3(data);
  128 + default:
  129 + throw new IllegalArgumentException(String.format("未知的 API 版本(%s)", config.getApiVersion()));
  130 + }
  131 +
  132 + }
  133 +
  134 + private PayOrderNotifyRespDTO parseOrderNotifyV3(PayNotifyDataDTO data) throws WxPayException {
  135 + WxPayOrderNotifyV3Result wxPayOrderNotifyV3Result = client.parseOrderNotifyV3Result(data.getBody(), null);
  136 + WxPayOrderNotifyV3Result.DecryptNotifyResult result = wxPayOrderNotifyV3Result.getResult();
  137 + // 转换结果
  138 +
  139 + return PayOrderNotifyRespDTO
  140 + .builder()
  141 + .orderExtensionNo(result.getOutTradeNo())
  142 + .channelOrderNo(result.getTradeState())
  143 + .successTime(DateUtil.parse(result.getSuccessTime(), "yyyy-MM-dd'T'HH:mm:ssXXX"))
  144 + .data(data.getBody())
  145 + .build();
  146 + }
  147 +
  148 + private PayOrderNotifyRespDTO parseOrderNotifyV2(PayNotifyDataDTO data) throws WxPayException {
120 WxPayOrderNotifyResult notifyResult = client.parseOrderNotifyResult(data.getBody()); 149 WxPayOrderNotifyResult notifyResult = client.parseOrderNotifyResult(data.getBody());
121 Assert.isTrue(Objects.equals(notifyResult.getResultCode(), "SUCCESS"), "支付结果非 SUCCESS"); 150 Assert.isTrue(Objects.equals(notifyResult.getResultCode(), "SUCCESS"), "支付结果非 SUCCESS");
122 // 转换结果 151 // 转换结果
123 - return PayOrderNotifyRespDTO.builder().orderExtensionNo(notifyResult.getOutTradeNo())  
124 - .channelOrderNo(notifyResult.getTransactionId()).channelUserId(notifyResult.getOpenid())  
125 - .successTime(DateUtil.parse(notifyResult.getTimeEnd(), "yyyy-MM-dd'T'HH:mm:ssXXX"))  
126 - .data(data.getBody()).build(); 152 + return PayOrderNotifyRespDTO
  153 + .builder()
  154 + .orderExtensionNo(notifyResult.getOutTradeNo())
  155 + .channelOrderNo(notifyResult.getTransactionId())
  156 + .channelUserId(notifyResult.getOpenid())
  157 + .successTime(DateUtil.parse(notifyResult.getTimeEnd(), "yyyyMMddHHmmss"))
  158 + .data(data.getBody())
  159 + .build();
  160 +
127 } 161 }
128 162
129 @Override 163 @Override
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/wx/WXPubPayClient.java
@@ -12,6 +12,7 @@ import cn.iocoder.yudao.framework.pay.core.client.dto.*; @@ -12,6 +12,7 @@ import cn.iocoder.yudao.framework.pay.core.client.dto.*;
12 import cn.iocoder.yudao.framework.pay.core.client.impl.AbstractPayClient; 12 import cn.iocoder.yudao.framework.pay.core.client.impl.AbstractPayClient;
13 import cn.iocoder.yudao.framework.pay.core.enums.PayChannelEnum; 13 import cn.iocoder.yudao.framework.pay.core.enums.PayChannelEnum;
14 import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult; 14 import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult;
  15 +import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyV3Result;
15 import com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult; 16 import com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult;
16 import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest; 17 import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
17 import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderV3Request; 18 import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderV3Request;
@@ -132,13 +133,46 @@ public class WXPubPayClient extends AbstractPayClient<WXPayClientConfig> { @@ -132,13 +133,46 @@ public class WXPubPayClient extends AbstractPayClient<WXPayClientConfig> {
132 133
133 @Override 134 @Override
134 public PayOrderNotifyRespDTO parseOrderNotify(PayNotifyDataDTO data) throws WxPayException { 135 public PayOrderNotifyRespDTO parseOrderNotify(PayNotifyDataDTO data) throws WxPayException {
  136 + log.info("微信支付回调data数据:{}", data.getBody());
  137 + // 微信支付 v2 回调结果处理
  138 + switch (config.getApiVersion()) {
  139 + case WXPayClientConfig.API_VERSION_V2:
  140 + return parseOrderNotifyV2(data);
  141 + case WXPayClientConfig.API_VERSION_V3:
  142 + return parseOrderNotifyV3(data);
  143 + default:
  144 + throw new IllegalArgumentException(String.format("未知的 API 版本(%s)", config.getApiVersion()));
  145 + }
  146 +
  147 + }
  148 +
  149 + private PayOrderNotifyRespDTO parseOrderNotifyV3(PayNotifyDataDTO data) throws WxPayException {
  150 + WxPayOrderNotifyV3Result wxPayOrderNotifyV3Result = client.parseOrderNotifyV3Result(data.getBody(), null);
  151 + WxPayOrderNotifyV3Result.DecryptNotifyResult result = wxPayOrderNotifyV3Result.getResult();
  152 + // 转换结果
  153 +
  154 + return PayOrderNotifyRespDTO
  155 + .builder()
  156 + .orderExtensionNo(result.getOutTradeNo())
  157 + .channelOrderNo(result.getTradeState())
  158 + .successTime(DateUtil.parse(result.getSuccessTime(), "yyyy-MM-dd'T'HH:mm:ssXXX"))
  159 + .data(data.getBody())
  160 + .build();
  161 + }
  162 +
  163 + private PayOrderNotifyRespDTO parseOrderNotifyV2(PayNotifyDataDTO data) throws WxPayException {
135 WxPayOrderNotifyResult notifyResult = client.parseOrderNotifyResult(data.getBody()); 164 WxPayOrderNotifyResult notifyResult = client.parseOrderNotifyResult(data.getBody());
136 Assert.isTrue(Objects.equals(notifyResult.getResultCode(), "SUCCESS"), "支付结果非 SUCCESS"); 165 Assert.isTrue(Objects.equals(notifyResult.getResultCode(), "SUCCESS"), "支付结果非 SUCCESS");
137 // 转换结果 166 // 转换结果
138 - return PayOrderNotifyRespDTO.builder().orderExtensionNo(notifyResult.getOutTradeNo())  
139 - .channelOrderNo(notifyResult.getTransactionId()).channelUserId(notifyResult.getOpenid()) 167 + return PayOrderNotifyRespDTO
  168 + .builder()
  169 + .orderExtensionNo(notifyResult.getOutTradeNo())
  170 + .channelOrderNo(notifyResult.getTransactionId())
  171 + .channelUserId(notifyResult.getOpenid())
140 .successTime(DateUtil.parse(notifyResult.getTimeEnd(), "yyyyMMddHHmmss")) 172 .successTime(DateUtil.parse(notifyResult.getTimeEnd(), "yyyyMMddHHmmss"))
141 - .data(data.getBody()).build(); 173 + .data(data.getBody())
  174 + .build();
  175 +
142 } 176 }
143 177
144 @Override 178 @Override