mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-10-31 18:28:43 +08:00 
			
		
		
		
	code review 支付的提交,补充相关的注释
This commit is contained in:
		| @@ -2,6 +2,7 @@ package cn.iocoder.yudao.framework.pay.core.client.impl.alipay; | ||||
|  | ||||
| import cn.hutool.core.bean.BeanUtil; | ||||
| import cn.hutool.core.date.DateUtil; | ||||
| import cn.hutool.http.HttpUtil; | ||||
| import cn.iocoder.yudao.framework.pay.core.client.AbstractPayCodeMapping; | ||||
| import cn.iocoder.yudao.framework.pay.core.client.PayCommonResult; | ||||
| import cn.iocoder.yudao.framework.pay.core.client.dto.*; | ||||
| @@ -133,17 +134,17 @@ public abstract class AbstractAlipayClient extends AbstractPayClient<AlipayPayCl | ||||
|  | ||||
|  | ||||
|     /** | ||||
|      * | ||||
|      * 支付宝统一回调参数  str转map | ||||
|      * 支付宝统一回调参数  str 转 map | ||||
|      * | ||||
|      * @param s 支付宝支付通知回调参数 | ||||
|      * @return map 支付宝集合 | ||||
|      */ | ||||
|     public static Map<String, String> strToMap(String s) { | ||||
|         // TODO @zxy:这个可以使用 hutool 的 HttpUtil decodeParams 方法么? | ||||
|         Map<String, String> stringStringMap = new HashMap<>(); | ||||
|         //调整时间格式 | ||||
|         // 调整时间格式 | ||||
|         String s3 = s.replaceAll("%3A", ":"); | ||||
|         //获取map | ||||
|         // 获取 map | ||||
|         String s4 = s3.replace("+", " "); | ||||
|         String[] split = s4.split("&"); | ||||
|         for (String s1 : split) { | ||||
| @@ -152,4 +153,5 @@ public abstract class AbstractAlipayClient extends AbstractPayClient<AlipayPayCl | ||||
|         } | ||||
|         return stringStringMap; | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -33,8 +33,9 @@ import static cn.iocoder.yudao.framework.pay.core.client.impl.wx.WXCodeMapping.M | ||||
|  | ||||
|  | ||||
| /** | ||||
|  * | ||||
|  * 微信小程序下支付 | ||||
|  * | ||||
|  * @author zwy | ||||
|  */ | ||||
| @Slf4j | ||||
| public class WXLitePayClient extends AbstractPayClient<WXPayClientConfig> { | ||||
| @@ -91,15 +92,13 @@ public class WXLitePayClient extends AbstractPayClient<WXPayClientConfig> { | ||||
|         return PayCommonResult.build(CODE_SUCCESS, MESSAGE_SUCCESS, response, codeMapping); | ||||
|     } | ||||
|  | ||||
|  | ||||
|     private WxPayMpOrderResult unifiedOrderV2(PayOrderUnifiedReqDTO reqDTO) throws WxPayException { | ||||
|         // 构建 WxPayUnifiedOrderRequest 对象 | ||||
|         WxPayUnifiedOrderRequest request = WxPayUnifiedOrderRequest.newBuilder() | ||||
|                 .outTradeNo(reqDTO.getMerchantOrderId()) | ||||
|                 .body(reqDTO.getBody()) | ||||
|                 .totalFee(reqDTO.getAmount().intValue()) // 单位分 | ||||
|                 //v2的时间格式 | ||||
|                 .timeExpire(DateUtil.format(reqDTO.getExpireTime(), "yyyyMMddHHmmss")) | ||||
|                 .timeExpire(DateUtil.format(reqDTO.getExpireTime(), "yyyyMMddHHmmss")) // v2的时间格式 | ||||
|                 .spbillCreateIp(reqDTO.getUserIp()) | ||||
|                 .openid(getOpenid(reqDTO)) | ||||
|                 .notifyUrl(reqDTO.getNotifyUrl()) | ||||
| @@ -119,11 +118,8 @@ public class WXLitePayClient extends AbstractPayClient<WXPayClientConfig> { | ||||
|                 .setTotal(reqDTO | ||||
|                         .getAmount() | ||||
|                         .intValue())); // 单位分 | ||||
|         //v3的时间格式 | ||||
|         request.setTimeExpire(DateUtil.format(reqDTO.getExpireTime(), "yyyy-MM-dd'T'HH:mm:ssXXX")); | ||||
|         request.setPayer(new WxPayUnifiedOrderV3Request | ||||
|                 .Payer() | ||||
|                 .setOpenid(getOpenid(reqDTO))); | ||||
|         request.setTimeExpire(DateUtil.format(reqDTO.getExpireTime(), "yyyy-MM-dd'T'HH:mm:ssXXX")); // v3的时间格式 | ||||
|         request.setPayer(new WxPayUnifiedOrderV3Request.Payer().setOpenid(getOpenid(reqDTO))); | ||||
|         request.setSceneInfo(new WxPayUnifiedOrderV3Request.SceneInfo().setPayerClientIp(reqDTO.getUserIp())); | ||||
|         request.setNotifyUrl(reqDTO.getNotifyUrl()); | ||||
|         // 执行请求 | ||||
| @@ -140,7 +136,7 @@ public class WXLitePayClient extends AbstractPayClient<WXPayClientConfig> { | ||||
|  | ||||
|     /** | ||||
|      * | ||||
|      * 微信支付回调 分v2 和v3 的处理方式 | ||||
|      * 微信支付回调 分 v2 和v3 的处理方式 | ||||
|      * | ||||
|      * @param data 通知结果 | ||||
|      * @return 支付回调对象 | ||||
| @@ -148,7 +144,7 @@ public class WXLitePayClient extends AbstractPayClient<WXPayClientConfig> { | ||||
|      */ | ||||
|     @Override | ||||
|     public PayOrderNotifyRespDTO parseOrderNotify(PayNotifyDataDTO data) throws WxPayException { | ||||
|         log.info("微信支付回调data数据:{}", data.getBody()); | ||||
|         log.info("[parseOrderNotify][微信支付回调data数据:{}]", data.getBody()); | ||||
|         // 微信支付 v2 回调结果处理 | ||||
|         switch (config.getApiVersion()) { | ||||
|             case WXPayClientConfig.API_VERSION_V2: | ||||
| @@ -158,14 +154,14 @@ public class WXLitePayClient extends AbstractPayClient<WXPayClientConfig> { | ||||
|             default: | ||||
|                 throw new IllegalArgumentException(String.format("未知的 API 版本(%s)", config.getApiVersion())); | ||||
|         } | ||||
|  | ||||
|     } | ||||
|  | ||||
|     private PayOrderNotifyRespDTO parseOrderNotifyV3(PayNotifyDataDTO data) throws WxPayException { | ||||
|         WxPayOrderNotifyV3Result wxPayOrderNotifyV3Result = client.parseOrderNotifyV3Result(data.getBody(), null); | ||||
|         WxPayOrderNotifyV3Result.DecryptNotifyResult result = wxPayOrderNotifyV3Result.getResult(); | ||||
|         // 转换结果 | ||||
|         Assert.isTrue(Objects.equals(wxPayOrderNotifyV3Result.getResult().getTradeState(), "SUCCESS"), "支付结果非 SUCCESS"); | ||||
|         Assert.isTrue(Objects.equals(wxPayOrderNotifyV3Result.getResult().getTradeState(), "SUCCESS"), | ||||
|                 "支付结果非 SUCCESS"); | ||||
|  | ||||
|         return PayOrderNotifyRespDTO | ||||
|                 .builder() | ||||
|   | ||||
| @@ -29,9 +29,14 @@ import static cn.iocoder.yudao.framework.common.util.json.JsonUtils.toJsonString | ||||
| import static cn.iocoder.yudao.framework.pay.core.client.impl.wx.WXCodeMapping.CODE_SUCCESS; | ||||
| import static cn.iocoder.yudao.framework.pay.core.client.impl.wx.WXCodeMapping.MESSAGE_SUCCESS; | ||||
|  | ||||
|  | ||||
| /** | ||||
|  * 微信 App 支付 | ||||
|  * | ||||
|  * @author zwy | ||||
|  */ | ||||
| @Slf4j | ||||
| public class WXNativePayClient extends AbstractPayClient<WXPayClientConfig> { | ||||
|  | ||||
|     private WxPayService client; | ||||
|  | ||||
|     public WXNativePayClient(Long channelId, WXPayClientConfig config) { | ||||
| @@ -62,7 +67,7 @@ public class WXNativePayClient extends AbstractPayClient<WXPayClientConfig> { | ||||
|     @Override | ||||
|     public PayCommonResult<String> doUnifiedOrder(PayOrderUnifiedReqDTO reqDTO) { | ||||
|         // 这里原生的返回的是支付的 url 所以直接使用string接收 | ||||
|         //"invokeResponse": "weixin://wxpay/bizpayurl?pr=EGYAem7zz" | ||||
|         // "invokeResponse": "weixin://wxpay/bizpayurl?pr=EGYAem7zz" | ||||
|         String responseV3; | ||||
|         try { | ||||
|             switch (config.getApiVersion()) { | ||||
| @@ -110,12 +115,9 @@ public class WXNativePayClient extends AbstractPayClient<WXPayClientConfig> { | ||||
|         request.setSceneInfo(new WxPayUnifiedOrderV3Request.SceneInfo().setPayerClientIp(reqDTO.getUserIp())); | ||||
|         request.setNotifyUrl(reqDTO.getNotifyUrl()); | ||||
|         // 执行请求 | ||||
|  | ||||
|  | ||||
|         return client.createOrderV3(TradeTypeEnum.NATIVE, request); | ||||
|     } | ||||
|  | ||||
|  | ||||
|     /** | ||||
|      * | ||||
|      * 微信支付回调 分v2 和v3 的处理方式 | ||||
| @@ -136,15 +138,14 @@ public class WXNativePayClient extends AbstractPayClient<WXPayClientConfig> { | ||||
|             default: | ||||
|                 throw new IllegalArgumentException(String.format("未知的 API 版本(%s)", config.getApiVersion())); | ||||
|         } | ||||
|  | ||||
|     } | ||||
|  | ||||
|     private PayOrderNotifyRespDTO parseOrderNotifyV3(PayNotifyDataDTO data) throws WxPayException { | ||||
|         WxPayOrderNotifyV3Result wxPayOrderNotifyV3Result = client.parseOrderNotifyV3Result(data.getBody(), null); | ||||
|         WxPayOrderNotifyV3Result.DecryptNotifyResult result = wxPayOrderNotifyV3Result.getResult(); | ||||
|         // 转换结果 | ||||
|         Assert.isTrue(Objects.equals(wxPayOrderNotifyV3Result.getResult().getTradeState(), "SUCCESS"), "支付结果非 SUCCESS"); | ||||
|  | ||||
|         Assert.isTrue(Objects.equals(wxPayOrderNotifyV3Result.getResult().getTradeState(), "SUCCESS"), | ||||
|                 "支付结果非 SUCCESS"); | ||||
|         return PayOrderNotifyRespDTO | ||||
|                 .builder() | ||||
|                 .orderExtensionNo(result.getOutTradeNo()) | ||||
| @@ -171,14 +172,15 @@ public class WXNativePayClient extends AbstractPayClient<WXPayClientConfig> { | ||||
|  | ||||
|     @Override | ||||
|     public PayRefundNotifyDTO parseRefundNotify(PayNotifyDataDTO notifyData) { | ||||
|         //TODO 需要实现 | ||||
|         // TODO 需要实现 | ||||
|         throw new UnsupportedOperationException("需要实现"); | ||||
|     } | ||||
|  | ||||
|  | ||||
|     @Override | ||||
|     protected PayCommonResult<PayRefundUnifiedRespDTO> doUnifiedRefund(PayRefundUnifiedReqDTO reqDTO) throws Throwable { | ||||
|         //TODO 需要实现 | ||||
|         // TODO 需要实现 | ||||
|         throw new UnsupportedOperationException(); | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -11,8 +11,6 @@ import java.io.FileInputStream; | ||||
| import java.io.FileNotFoundException; | ||||
| import java.util.Set; | ||||
|  | ||||
| // TODO 芋艿:参数校验 | ||||
|  | ||||
| /** | ||||
|  * 微信支付的 PayClientConfig 实现类 | ||||
|  * 属性主要来自 {@link com.github.binarywang.wxpay.config.WxPayConfig} 的必要属性 | ||||
| @@ -22,7 +20,6 @@ import java.util.Set; | ||||
| @Data | ||||
| public class WXPayClientConfig implements PayClientConfig { | ||||
|  | ||||
|     // TODO 芋艿:V2 or V3 客户端 | ||||
|     /** | ||||
|      * API 版本 - V2 | ||||
|      * https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_1 | ||||
|   | ||||
| @@ -139,7 +139,7 @@ public class WXPubPayClient extends AbstractPayClient<WXPayClientConfig> { | ||||
|      */ | ||||
|     @Override | ||||
|     public PayOrderNotifyRespDTO parseOrderNotify(PayNotifyDataDTO data) throws WxPayException { | ||||
|         log.info("微信支付回调data数据:{}", data.getBody()); | ||||
|         log.info("[parseOrderNotify][微信支付回调data数据: {}]", data.getBody()); | ||||
|         // 微信支付 v2 回调结果处理 | ||||
|         switch (config.getApiVersion()) { | ||||
|             case WXPayClientConfig.API_VERSION_V2: | ||||
| @@ -155,7 +155,8 @@ public class WXPubPayClient extends AbstractPayClient<WXPayClientConfig> { | ||||
|         WxPayOrderNotifyV3Result wxPayOrderNotifyV3Result = client.parseOrderNotifyV3Result(data.getBody(), null); | ||||
|         WxPayOrderNotifyV3Result.DecryptNotifyResult result = wxPayOrderNotifyV3Result.getResult(); | ||||
|         // 转换结果 | ||||
|         Assert.isTrue(Objects.equals(wxPayOrderNotifyV3Result.getResult().getTradeState(), "SUCCESS"), "支付结果非 SUCCESS"); | ||||
|         Assert.isTrue(Objects.equals(wxPayOrderNotifyV3Result.getResult().getTradeState(), "SUCCESS"), | ||||
|                 "支付结果非 SUCCESS"); | ||||
|         return PayOrderNotifyRespDTO | ||||
|                 .builder() | ||||
|                 .orderExtensionNo(result.getOutTradeNo()) | ||||
| @@ -182,14 +183,13 @@ public class WXPubPayClient extends AbstractPayClient<WXPayClientConfig> { | ||||
|  | ||||
|     @Override | ||||
|     public PayRefundNotifyDTO parseRefundNotify(PayNotifyDataDTO notifyData) { | ||||
|         //TODO 需要实现 | ||||
|         // TODO 需要实现 | ||||
|         throw new UnsupportedOperationException("需要实现"); | ||||
|     } | ||||
|  | ||||
|  | ||||
|     @Override | ||||
|     protected PayCommonResult<PayRefundUnifiedRespDTO> doUnifiedRefund(PayRefundUnifiedReqDTO reqDTO) throws Throwable { | ||||
|         //TODO 需要实现 | ||||
|         // TODO 需要实现 | ||||
|         throw new UnsupportedOperationException(); | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -22,7 +22,6 @@ public enum PayChannelEnum { | ||||
|     WX_APP("wx_app", "微信 App 支付", WXPayClientConfig.class), | ||||
|     WX_NATIVE("wx_native", "微信 native 支付", WXPayClientConfig.class), | ||||
|  | ||||
|  | ||||
|     ALIPAY_PC("alipay_pc", "支付宝 PC 网站支付", AlipayPayClientConfig.class), | ||||
|     ALIPAY_WAP("alipay_wap", "支付宝 Wap 网站支付", AlipayPayClientConfig.class), | ||||
|     ALIPAY_APP("alipay_app", "支付宝App 支付", AlipayPayClientConfig.class), | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 YunaiV
					YunaiV