Commit 156a591070586ed343ecface0808ba784cb8dffe
1 parent
17483e8b
code review 支付的提交,补充相关的注释
Showing
6 changed files
with
32 additions
and
36 deletions
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; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.bean.BeanUtil; |
| 4 | 4 | import cn.hutool.core.date.DateUtil; |
| 5 | +import cn.hutool.http.HttpUtil; | |
| 5 | 6 | import cn.iocoder.yudao.framework.pay.core.client.AbstractPayCodeMapping; |
| 6 | 7 | import cn.iocoder.yudao.framework.pay.core.client.PayCommonResult; |
| 7 | 8 | import cn.iocoder.yudao.framework.pay.core.client.dto.*; |
| ... | ... | @@ -133,17 +134,17 @@ public abstract class AbstractAlipayClient extends AbstractPayClient<AlipayPayCl |
| 133 | 134 | |
| 134 | 135 | |
| 135 | 136 | /** |
| 136 | - * | |
| 137 | - * 支付宝统一回调参数 str转map | |
| 137 | + * 支付宝统一回调参数 str 转 map | |
| 138 | 138 | * |
| 139 | 139 | * @param s 支付宝支付通知回调参数 |
| 140 | 140 | * @return map 支付宝集合 |
| 141 | 141 | */ |
| 142 | 142 | public static Map<String, String> strToMap(String s) { |
| 143 | + // TODO @zxy:这个可以使用 hutool 的 HttpUtil decodeParams 方法么? | |
| 143 | 144 | Map<String, String> stringStringMap = new HashMap<>(); |
| 144 | - //调整时间格式 | |
| 145 | + // 调整时间格式 | |
| 145 | 146 | String s3 = s.replaceAll("%3A", ":"); |
| 146 | - //获取map | |
| 147 | + // 获取 map | |
| 147 | 148 | String s4 = s3.replace("+", " "); |
| 148 | 149 | String[] split = s4.split("&"); |
| 149 | 150 | for (String s1 : split) { |
| ... | ... | @@ -152,4 +153,5 @@ public abstract class AbstractAlipayClient extends AbstractPayClient<AlipayPayCl |
| 152 | 153 | } |
| 153 | 154 | return stringStringMap; |
| 154 | 155 | } |
| 156 | + | |
| 155 | 157 | } | ... | ... |
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/wx/WXLitePayClient.java
| ... | ... | @@ -33,8 +33,9 @@ import static cn.iocoder.yudao.framework.pay.core.client.impl.wx.WXCodeMapping.M |
| 33 | 33 | |
| 34 | 34 | |
| 35 | 35 | /** |
| 36 | - * | |
| 37 | 36 | * 微信小程序下支付 |
| 37 | + * | |
| 38 | + * @author zwy | |
| 38 | 39 | */ |
| 39 | 40 | @Slf4j |
| 40 | 41 | public class WXLitePayClient extends AbstractPayClient<WXPayClientConfig> { |
| ... | ... | @@ -91,15 +92,13 @@ public class WXLitePayClient extends AbstractPayClient<WXPayClientConfig> { |
| 91 | 92 | return PayCommonResult.build(CODE_SUCCESS, MESSAGE_SUCCESS, response, codeMapping); |
| 92 | 93 | } |
| 93 | 94 | |
| 94 | - | |
| 95 | 95 | private WxPayMpOrderResult unifiedOrderV2(PayOrderUnifiedReqDTO reqDTO) throws WxPayException { |
| 96 | 96 | // 构建 WxPayUnifiedOrderRequest 对象 |
| 97 | 97 | WxPayUnifiedOrderRequest request = WxPayUnifiedOrderRequest.newBuilder() |
| 98 | 98 | .outTradeNo(reqDTO.getMerchantOrderId()) |
| 99 | 99 | .body(reqDTO.getBody()) |
| 100 | 100 | .totalFee(reqDTO.getAmount().intValue()) // 单位分 |
| 101 | - //v2的时间格式 | |
| 102 | - .timeExpire(DateUtil.format(reqDTO.getExpireTime(), "yyyyMMddHHmmss")) | |
| 101 | + .timeExpire(DateUtil.format(reqDTO.getExpireTime(), "yyyyMMddHHmmss")) // v2的时间格式 | |
| 103 | 102 | .spbillCreateIp(reqDTO.getUserIp()) |
| 104 | 103 | .openid(getOpenid(reqDTO)) |
| 105 | 104 | .notifyUrl(reqDTO.getNotifyUrl()) |
| ... | ... | @@ -119,11 +118,8 @@ public class WXLitePayClient extends AbstractPayClient<WXPayClientConfig> { |
| 119 | 118 | .setTotal(reqDTO |
| 120 | 119 | .getAmount() |
| 121 | 120 | .intValue())); // 单位分 |
| 122 | - //v3的时间格式 | |
| 123 | - request.setTimeExpire(DateUtil.format(reqDTO.getExpireTime(), "yyyy-MM-dd'T'HH:mm:ssXXX")); | |
| 124 | - request.setPayer(new WxPayUnifiedOrderV3Request | |
| 125 | - .Payer() | |
| 126 | - .setOpenid(getOpenid(reqDTO))); | |
| 121 | + request.setTimeExpire(DateUtil.format(reqDTO.getExpireTime(), "yyyy-MM-dd'T'HH:mm:ssXXX")); // v3的时间格式 | |
| 122 | + request.setPayer(new WxPayUnifiedOrderV3Request.Payer().setOpenid(getOpenid(reqDTO))); | |
| 127 | 123 | request.setSceneInfo(new WxPayUnifiedOrderV3Request.SceneInfo().setPayerClientIp(reqDTO.getUserIp())); |
| 128 | 124 | request.setNotifyUrl(reqDTO.getNotifyUrl()); |
| 129 | 125 | // 执行请求 |
| ... | ... | @@ -140,7 +136,7 @@ public class WXLitePayClient extends AbstractPayClient<WXPayClientConfig> { |
| 140 | 136 | |
| 141 | 137 | /** |
| 142 | 138 | * |
| 143 | - * 微信支付回调 分v2 和v3 的处理方式 | |
| 139 | + * 微信支付回调 分 v2 和v3 的处理方式 | |
| 144 | 140 | * |
| 145 | 141 | * @param data 通知结果 |
| 146 | 142 | * @return 支付回调对象 |
| ... | ... | @@ -148,7 +144,7 @@ public class WXLitePayClient extends AbstractPayClient<WXPayClientConfig> { |
| 148 | 144 | */ |
| 149 | 145 | @Override |
| 150 | 146 | public PayOrderNotifyRespDTO parseOrderNotify(PayNotifyDataDTO data) throws WxPayException { |
| 151 | - log.info("微信支付回调data数据:{}", data.getBody()); | |
| 147 | + log.info("[parseOrderNotify][微信支付回调data数据:{}]", data.getBody()); | |
| 152 | 148 | // 微信支付 v2 回调结果处理 |
| 153 | 149 | switch (config.getApiVersion()) { |
| 154 | 150 | case WXPayClientConfig.API_VERSION_V2: |
| ... | ... | @@ -158,14 +154,14 @@ public class WXLitePayClient extends AbstractPayClient<WXPayClientConfig> { |
| 158 | 154 | default: |
| 159 | 155 | throw new IllegalArgumentException(String.format("未知的 API 版本(%s)", config.getApiVersion())); |
| 160 | 156 | } |
| 161 | - | |
| 162 | 157 | } |
| 163 | 158 | |
| 164 | 159 | private PayOrderNotifyRespDTO parseOrderNotifyV3(PayNotifyDataDTO data) throws WxPayException { |
| 165 | 160 | WxPayOrderNotifyV3Result wxPayOrderNotifyV3Result = client.parseOrderNotifyV3Result(data.getBody(), null); |
| 166 | 161 | WxPayOrderNotifyV3Result.DecryptNotifyResult result = wxPayOrderNotifyV3Result.getResult(); |
| 167 | 162 | // 转换结果 |
| 168 | - Assert.isTrue(Objects.equals(wxPayOrderNotifyV3Result.getResult().getTradeState(), "SUCCESS"), "支付结果非 SUCCESS"); | |
| 163 | + Assert.isTrue(Objects.equals(wxPayOrderNotifyV3Result.getResult().getTradeState(), "SUCCESS"), | |
| 164 | + "支付结果非 SUCCESS"); | |
| 169 | 165 | |
| 170 | 166 | return PayOrderNotifyRespDTO |
| 171 | 167 | .builder() | ... | ... |
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 |
| 29 | 29 | import static cn.iocoder.yudao.framework.pay.core.client.impl.wx.WXCodeMapping.CODE_SUCCESS; |
| 30 | 30 | import static cn.iocoder.yudao.framework.pay.core.client.impl.wx.WXCodeMapping.MESSAGE_SUCCESS; |
| 31 | 31 | |
| 32 | - | |
| 32 | +/** | |
| 33 | + * 微信 App 支付 | |
| 34 | + * | |
| 35 | + * @author zwy | |
| 36 | + */ | |
| 33 | 37 | @Slf4j |
| 34 | 38 | public class WXNativePayClient extends AbstractPayClient<WXPayClientConfig> { |
| 39 | + | |
| 35 | 40 | private WxPayService client; |
| 36 | 41 | |
| 37 | 42 | public WXNativePayClient(Long channelId, WXPayClientConfig config) { |
| ... | ... | @@ -62,7 +67,7 @@ public class WXNativePayClient extends AbstractPayClient<WXPayClientConfig> { |
| 62 | 67 | @Override |
| 63 | 68 | public PayCommonResult<String> doUnifiedOrder(PayOrderUnifiedReqDTO reqDTO) { |
| 64 | 69 | // 这里原生的返回的是支付的 url 所以直接使用string接收 |
| 65 | - //"invokeResponse": "weixin://wxpay/bizpayurl?pr=EGYAem7zz" | |
| 70 | + // "invokeResponse": "weixin://wxpay/bizpayurl?pr=EGYAem7zz" | |
| 66 | 71 | String responseV3; |
| 67 | 72 | try { |
| 68 | 73 | switch (config.getApiVersion()) { |
| ... | ... | @@ -110,12 +115,9 @@ public class WXNativePayClient extends AbstractPayClient<WXPayClientConfig> { |
| 110 | 115 | request.setSceneInfo(new WxPayUnifiedOrderV3Request.SceneInfo().setPayerClientIp(reqDTO.getUserIp())); |
| 111 | 116 | request.setNotifyUrl(reqDTO.getNotifyUrl()); |
| 112 | 117 | // 执行请求 |
| 113 | - | |
| 114 | - | |
| 115 | 118 | return client.createOrderV3(TradeTypeEnum.NATIVE, request); |
| 116 | 119 | } |
| 117 | 120 | |
| 118 | - | |
| 119 | 121 | /** |
| 120 | 122 | * |
| 121 | 123 | * 微信支付回调 分v2 和v3 的处理方式 |
| ... | ... | @@ -136,15 +138,14 @@ public class WXNativePayClient extends AbstractPayClient<WXPayClientConfig> { |
| 136 | 138 | default: |
| 137 | 139 | throw new IllegalArgumentException(String.format("未知的 API 版本(%s)", config.getApiVersion())); |
| 138 | 140 | } |
| 139 | - | |
| 140 | 141 | } |
| 141 | 142 | |
| 142 | 143 | private PayOrderNotifyRespDTO parseOrderNotifyV3(PayNotifyDataDTO data) throws WxPayException { |
| 143 | 144 | WxPayOrderNotifyV3Result wxPayOrderNotifyV3Result = client.parseOrderNotifyV3Result(data.getBody(), null); |
| 144 | 145 | WxPayOrderNotifyV3Result.DecryptNotifyResult result = wxPayOrderNotifyV3Result.getResult(); |
| 145 | 146 | // 转换结果 |
| 146 | - Assert.isTrue(Objects.equals(wxPayOrderNotifyV3Result.getResult().getTradeState(), "SUCCESS"), "支付结果非 SUCCESS"); | |
| 147 | - | |
| 147 | + Assert.isTrue(Objects.equals(wxPayOrderNotifyV3Result.getResult().getTradeState(), "SUCCESS"), | |
| 148 | + "支付结果非 SUCCESS"); | |
| 148 | 149 | return PayOrderNotifyRespDTO |
| 149 | 150 | .builder() |
| 150 | 151 | .orderExtensionNo(result.getOutTradeNo()) |
| ... | ... | @@ -171,14 +172,15 @@ public class WXNativePayClient extends AbstractPayClient<WXPayClientConfig> { |
| 171 | 172 | |
| 172 | 173 | @Override |
| 173 | 174 | public PayRefundNotifyDTO parseRefundNotify(PayNotifyDataDTO notifyData) { |
| 174 | - //TODO 需要实现 | |
| 175 | + // TODO 需要实现 | |
| 175 | 176 | throw new UnsupportedOperationException("需要实现"); |
| 176 | 177 | } |
| 177 | 178 | |
| 178 | 179 | |
| 179 | 180 | @Override |
| 180 | 181 | protected PayCommonResult<PayRefundUnifiedRespDTO> doUnifiedRefund(PayRefundUnifiedReqDTO reqDTO) throws Throwable { |
| 181 | - //TODO 需要实现 | |
| 182 | + // TODO 需要实现 | |
| 182 | 183 | throw new UnsupportedOperationException(); |
| 183 | 184 | } |
| 185 | + | |
| 184 | 186 | } | ... | ... |
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; |
| 11 | 11 | import java.io.FileNotFoundException; |
| 12 | 12 | import java.util.Set; |
| 13 | 13 | |
| 14 | -// TODO 芋艿:参数校验 | |
| 15 | - | |
| 16 | 14 | /** |
| 17 | 15 | * 微信支付的 PayClientConfig 实现类 |
| 18 | 16 | * 属性主要来自 {@link com.github.binarywang.wxpay.config.WxPayConfig} 的必要属性 |
| ... | ... | @@ -22,7 +20,6 @@ import java.util.Set; |
| 22 | 20 | @Data |
| 23 | 21 | public class WXPayClientConfig implements PayClientConfig { |
| 24 | 22 | |
| 25 | - // TODO 芋艿:V2 or V3 客户端 | |
| 26 | 23 | /** |
| 27 | 24 | * API 版本 - V2 |
| 28 | 25 | * https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_1 | ... | ... |
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<WXPayClientConfig> { |
| 139 | 139 | */ |
| 140 | 140 | @Override |
| 141 | 141 | public PayOrderNotifyRespDTO parseOrderNotify(PayNotifyDataDTO data) throws WxPayException { |
| 142 | - log.info("微信支付回调data数据:{}", data.getBody()); | |
| 142 | + log.info("[parseOrderNotify][微信支付回调data数据: {}]", data.getBody()); | |
| 143 | 143 | // 微信支付 v2 回调结果处理 |
| 144 | 144 | switch (config.getApiVersion()) { |
| 145 | 145 | case WXPayClientConfig.API_VERSION_V2: |
| ... | ... | @@ -155,7 +155,8 @@ public class WXPubPayClient extends AbstractPayClient<WXPayClientConfig> { |
| 155 | 155 | WxPayOrderNotifyV3Result wxPayOrderNotifyV3Result = client.parseOrderNotifyV3Result(data.getBody(), null); |
| 156 | 156 | WxPayOrderNotifyV3Result.DecryptNotifyResult result = wxPayOrderNotifyV3Result.getResult(); |
| 157 | 157 | // 转换结果 |
| 158 | - Assert.isTrue(Objects.equals(wxPayOrderNotifyV3Result.getResult().getTradeState(), "SUCCESS"), "支付结果非 SUCCESS"); | |
| 158 | + Assert.isTrue(Objects.equals(wxPayOrderNotifyV3Result.getResult().getTradeState(), "SUCCESS"), | |
| 159 | + "支付结果非 SUCCESS"); | |
| 159 | 160 | return PayOrderNotifyRespDTO |
| 160 | 161 | .builder() |
| 161 | 162 | .orderExtensionNo(result.getOutTradeNo()) |
| ... | ... | @@ -182,14 +183,13 @@ public class WXPubPayClient extends AbstractPayClient<WXPayClientConfig> { |
| 182 | 183 | |
| 183 | 184 | @Override |
| 184 | 185 | public PayRefundNotifyDTO parseRefundNotify(PayNotifyDataDTO notifyData) { |
| 185 | - //TODO 需要实现 | |
| 186 | + // TODO 需要实现 | |
| 186 | 187 | throw new UnsupportedOperationException("需要实现"); |
| 187 | 188 | } |
| 188 | 189 | |
| 189 | - | |
| 190 | 190 | @Override |
| 191 | 191 | protected PayCommonResult<PayRefundUnifiedRespDTO> doUnifiedRefund(PayRefundUnifiedReqDTO reqDTO) throws Throwable { |
| 192 | - //TODO 需要实现 | |
| 192 | + // TODO 需要实现 | |
| 193 | 193 | throw new UnsupportedOperationException(); |
| 194 | 194 | } |
| 195 | 195 | ... | ... |
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 { |
| 22 | 22 | WX_APP("wx_app", "微信 App 支付", WXPayClientConfig.class), |
| 23 | 23 | WX_NATIVE("wx_native", "微信 native 支付", WXPayClientConfig.class), |
| 24 | 24 | |
| 25 | - | |
| 26 | 25 | ALIPAY_PC("alipay_pc", "支付宝 PC 网站支付", AlipayPayClientConfig.class), |
| 27 | 26 | ALIPAY_WAP("alipay_wap", "支付宝 Wap 网站支付", AlipayPayClientConfig.class), |
| 28 | 27 | ALIPAY_APP("alipay_app", "支付宝App 支付", AlipayPayClientConfig.class), | ... | ... |