Commit 156a591070586ed343ecface0808ba784cb8dffe

Authored by YunaiV
1 parent 17483e8b

code review 支付的提交,补充相关的注释

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