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