Commit a30e3c655aa40b9a20b2861e19fdd8c89559204d
1 parent
a9acbca7
添加微信支付回调注解
Showing
3 changed files
with
30 additions
and
7 deletions
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/wx/WXLitePayClient.java
| ... | ... | @@ -138,6 +138,14 @@ public class WXLitePayClient extends AbstractPayClient<WXPayClientConfig> { |
| 138 | 138 | return openid; |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | + /** | |
| 142 | + * | |
| 143 | + * 微信支付回调 分v2 和v3 的处理方式 | |
| 144 | + * | |
| 145 | + * @param data 通知结果 | |
| 146 | + * @return 支付回调对象 | |
| 147 | + * @throws WxPayException 微信异常类 | |
| 148 | + */ | |
| 141 | 149 | @Override |
| 142 | 150 | public PayOrderNotifyRespDTO parseOrderNotify(PayNotifyDataDTO data) throws WxPayException { |
| 143 | 151 | log.info("微信支付回调data数据:{}", data.getBody()); |
| ... | ... | @@ -157,6 +165,7 @@ public class WXLitePayClient extends AbstractPayClient<WXPayClientConfig> { |
| 157 | 165 | WxPayOrderNotifyV3Result wxPayOrderNotifyV3Result = client.parseOrderNotifyV3Result(data.getBody(), null); |
| 158 | 166 | WxPayOrderNotifyV3Result.DecryptNotifyResult result = wxPayOrderNotifyV3Result.getResult(); |
| 159 | 167 | // 转换结果 |
| 168 | + Assert.isTrue(Objects.equals(wxPayOrderNotifyV3Result.getResult().getTradeState(), "SUCCESS"), "支付结果非 SUCCESS"); | |
| 160 | 169 | |
| 161 | 170 | return PayOrderNotifyRespDTO |
| 162 | 171 | .builder() | ... | ... |
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/wx/WXNativePayClient.java
| ... | ... | @@ -85,7 +85,7 @@ public class WXNativePayClient extends AbstractPayClient<WXPayClientConfig> { |
| 85 | 85 | |
| 86 | 86 | private WxPayNativeOrderResult unifiedOrderV2(PayOrderUnifiedReqDTO reqDTO) throws WxPayException { |
| 87 | 87 | //前端 |
| 88 | - String trade_type = reqDTO.getChannelExtras().get("trade_type"); | |
| 88 | + String tradeType = reqDTO.getChannelExtras().get("trade_type"); | |
| 89 | 89 | // 构建 WxPayUnifiedOrderRequest 对象 |
| 90 | 90 | WxPayUnifiedOrderRequest request = WxPayUnifiedOrderRequest |
| 91 | 91 | .newBuilder() |
| ... | ... | @@ -95,7 +95,7 @@ public class WXNativePayClient extends AbstractPayClient<WXPayClientConfig> { |
| 95 | 95 | .timeExpire(DateUtil.format(reqDTO.getExpireTime(), "yyyy-MM-dd'T'HH:mm:ssXXX")) |
| 96 | 96 | .spbillCreateIp(reqDTO.getUserIp()) |
| 97 | 97 | .notifyUrl(reqDTO.getNotifyUrl()) |
| 98 | - .productId(trade_type) | |
| 98 | + .productId(tradeType) | |
| 99 | 99 | .build(); |
| 100 | 100 | // 执行请求 |
| 101 | 101 | return client.createOrder(request); |
| ... | ... | @@ -110,12 +110,20 @@ public class WXNativePayClient extends AbstractPayClient<WXPayClientConfig> { |
| 110 | 110 | request.setSceneInfo(new WxPayUnifiedOrderV3Request.SceneInfo().setPayerClientIp(reqDTO.getUserIp())); |
| 111 | 111 | request.setNotifyUrl(reqDTO.getNotifyUrl()); |
| 112 | 112 | // 执行请求 |
| 113 | -// log.info("支付字段request:{}",request.getTimeExpire()); | |
| 113 | + | |
| 114 | 114 | |
| 115 | 115 | return client.createOrderV3(TradeTypeEnum.NATIVE, request); |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | |
| 119 | + /** | |
| 120 | + * | |
| 121 | + * 微信支付回调 分v2 和v3 的处理方式 | |
| 122 | + * | |
| 123 | + * @param data 通知结果 | |
| 124 | + * @return 支付回调对象 | |
| 125 | + * @throws WxPayException 微信异常类 | |
| 126 | + */ | |
| 119 | 127 | @Override |
| 120 | 128 | public PayOrderNotifyRespDTO parseOrderNotify(PayNotifyDataDTO data) throws WxPayException { |
| 121 | 129 | log.info("微信支付回调data数据:{}", data.getBody()); |
| ... | ... | @@ -135,6 +143,7 @@ public class WXNativePayClient extends AbstractPayClient<WXPayClientConfig> { |
| 135 | 143 | WxPayOrderNotifyV3Result wxPayOrderNotifyV3Result = client.parseOrderNotifyV3Result(data.getBody(), null); |
| 136 | 144 | WxPayOrderNotifyV3Result.DecryptNotifyResult result = wxPayOrderNotifyV3Result.getResult(); |
| 137 | 145 | // 转换结果 |
| 146 | + Assert.isTrue(Objects.equals(wxPayOrderNotifyV3Result.getResult().getTradeState(), "SUCCESS"), "支付结果非 SUCCESS"); | |
| 138 | 147 | |
| 139 | 148 | return PayOrderNotifyRespDTO |
| 140 | 149 | .builder() | ... | ... |
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/wx/WXPubPayClient.java
| ... | ... | @@ -96,7 +96,6 @@ public class WXPubPayClient extends AbstractPayClient<WXPayClientConfig> { |
| 96 | 96 | // 构建 WxPayUnifiedOrderRequest 对象 |
| 97 | 97 | WxPayUnifiedOrderRequest request = WxPayUnifiedOrderRequest.newBuilder() |
| 98 | 98 | .outTradeNo(reqDTO.getMerchantOrderId()) |
| 99 | - // TODO 芋艿:貌似没 title? | |
| 100 | 99 | .body(reqDTO.getBody()) |
| 101 | 100 | .totalFee(reqDTO.getAmount().intValue()) // 单位分 |
| 102 | 101 | .timeExpire(DateUtil.format(reqDTO.getExpireTime(), "yyyy-MM-dd'T'HH:mm:ssXXX")) |
| ... | ... | @@ -112,7 +111,6 @@ public class WXPubPayClient extends AbstractPayClient<WXPayClientConfig> { |
| 112 | 111 | // 构建 WxPayUnifiedOrderRequest 对象 |
| 113 | 112 | WxPayUnifiedOrderV3Request request = new WxPayUnifiedOrderV3Request(); |
| 114 | 113 | request.setOutTradeNo(reqDTO.getMerchantOrderId()); |
| 115 | - // TODO 芋艿:貌似没 title? | |
| 116 | 114 | request.setDescription(reqDTO.getBody()); |
| 117 | 115 | request.setAmount(new WxPayUnifiedOrderV3Request.Amount().setTotal(reqDTO.getAmount().intValue())); // 单位分 |
| 118 | 116 | request.setTimeExpire(DateUtil.format(reqDTO.getExpireTime(), "yyyy-MM-dd'T'HH:mm:ssXXX")); |
| ... | ... | @@ -131,6 +129,14 @@ public class WXPubPayClient extends AbstractPayClient<WXPayClientConfig> { |
| 131 | 129 | return openid; |
| 132 | 130 | } |
| 133 | 131 | |
| 132 | + /** | |
| 133 | + * | |
| 134 | + * 微信支付回调 分v2 和v3 的处理方式 | |
| 135 | + * | |
| 136 | + * @param data 通知结果 | |
| 137 | + * @return 支付回调对象 | |
| 138 | + * @throws WxPayException 微信异常类 | |
| 139 | + */ | |
| 134 | 140 | @Override |
| 135 | 141 | public PayOrderNotifyRespDTO parseOrderNotify(PayNotifyDataDTO data) throws WxPayException { |
| 136 | 142 | log.info("微信支付回调data数据:{}", data.getBody()); |
| ... | ... | @@ -143,14 +149,13 @@ public class WXPubPayClient extends AbstractPayClient<WXPayClientConfig> { |
| 143 | 149 | default: |
| 144 | 150 | throw new IllegalArgumentException(String.format("未知的 API 版本(%s)", config.getApiVersion())); |
| 145 | 151 | } |
| 146 | - | |
| 147 | 152 | } |
| 148 | 153 | |
| 149 | 154 | private PayOrderNotifyRespDTO parseOrderNotifyV3(PayNotifyDataDTO data) throws WxPayException { |
| 150 | 155 | WxPayOrderNotifyV3Result wxPayOrderNotifyV3Result = client.parseOrderNotifyV3Result(data.getBody(), null); |
| 151 | 156 | WxPayOrderNotifyV3Result.DecryptNotifyResult result = wxPayOrderNotifyV3Result.getResult(); |
| 152 | 157 | // 转换结果 |
| 153 | - | |
| 158 | + Assert.isTrue(Objects.equals(wxPayOrderNotifyV3Result.getResult().getTradeState(), "SUCCESS"), "支付结果非 SUCCESS"); | |
| 154 | 159 | return PayOrderNotifyRespDTO |
| 155 | 160 | .builder() |
| 156 | 161 | .orderExtensionNo(result.getOutTradeNo()) | ... | ... |