Commit cea1589e799258d5dc2f6b5e9c08f1c8e49136bc
1 parent
f1424aa6
code review 支付渠道的逻辑
Showing
4 changed files
with
9 additions
and
16 deletions
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/controller/channel/vo/PayChannelCreateReqVO.java
| @@ -14,10 +14,8 @@ import javax.validation.constraints.NotBlank; | @@ -14,10 +14,8 @@ import javax.validation.constraints.NotBlank; | ||
| 14 | @ToString(callSuper = true) | 14 | @ToString(callSuper = true) |
| 15 | public class PayChannelCreateReqVO extends PayChannelBaseVO { | 15 | public class PayChannelCreateReqVO extends PayChannelBaseVO { |
| 16 | 16 | ||
| 17 | - | ||
| 18 | - @ApiModelProperty(value = "通道配置的json字符串") | 17 | + @ApiModelProperty(value = "通道配置的 json 字符串") |
| 19 | @NotBlank(message = "通道配置不能为空") | 18 | @NotBlank(message = "通道配置不能为空") |
| 20 | private String config; | 19 | private String config; |
| 21 | 20 | ||
| 22 | - | ||
| 23 | } | 21 | } |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/pay/service/channel/impl/PayChannelServiceImpl.java
| @@ -11,11 +11,8 @@ import cn.iocoder.yudao.adminserver.modules.pay.service.channel.PayChannelServic | @@ -11,11 +11,8 @@ import cn.iocoder.yudao.adminserver.modules.pay.service.channel.PayChannelServic | ||
| 11 | import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.merchant.PayChannelDO; | 11 | import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.merchant.PayChannelDO; |
| 12 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 12 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 13 | import cn.iocoder.yudao.framework.pay.core.client.PayClientConfig; | 13 | import cn.iocoder.yudao.framework.pay.core.client.PayClientConfig; |
| 14 | -import cn.iocoder.yudao.framework.pay.core.client.impl.wx.WXPayClientConfig; | ||
| 15 | import cn.iocoder.yudao.framework.pay.core.enums.PayChannelEnum; | 14 | import cn.iocoder.yudao.framework.pay.core.enums.PayChannelEnum; |
| 16 | import lombok.extern.slf4j.Slf4j; | 15 | import lombok.extern.slf4j.Slf4j; |
| 17 | -import org.springframework.beans.factory.annotation.Autowired; | ||
| 18 | -import org.springframework.beans.factory.annotation.Qualifier; | ||
| 19 | import org.springframework.stereotype.Service; | 16 | import org.springframework.stereotype.Service; |
| 20 | import org.springframework.util.Assert; | 17 | import org.springframework.util.Assert; |
| 21 | import org.springframework.validation.annotation.Validated; | 18 | import org.springframework.validation.annotation.Validated; |
| @@ -25,7 +22,8 @@ import javax.validation.Validator; | @@ -25,7 +22,8 @@ import javax.validation.Validator; | ||
| 25 | import java.util.Collection; | 22 | import java.util.Collection; |
| 26 | import java.util.List; | 23 | import java.util.List; |
| 27 | 24 | ||
| 28 | -import static cn.iocoder.yudao.coreservice.modules.pay.enums.PayErrorCodeCoreConstants.*; | 25 | +import static cn.iocoder.yudao.coreservice.modules.pay.enums.PayErrorCodeCoreConstants.CHANNEL_EXIST_SAME_CHANNEL_ERROR; |
| 26 | +import static cn.iocoder.yudao.coreservice.modules.pay.enums.PayErrorCodeCoreConstants.CHANNEL_NOT_EXISTS; | ||
| 29 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 27 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 30 | 28 | ||
| 31 | /** | 29 | /** |
| @@ -48,6 +46,7 @@ public class PayChannelServiceImpl implements PayChannelService { | @@ -48,6 +46,7 @@ public class PayChannelServiceImpl implements PayChannelService { | ||
| 48 | public Long createChannel(PayChannelCreateReqVO reqVO) { | 46 | public Long createChannel(PayChannelCreateReqVO reqVO) { |
| 49 | // 断言是否有重复的 | 47 | // 断言是否有重复的 |
| 50 | PayChannelDO channelDO = this.getChannelByConditions(reqVO.getMerchantId(), reqVO.getAppId(), reqVO.getCode()); | 48 | PayChannelDO channelDO = this.getChannelByConditions(reqVO.getMerchantId(), reqVO.getAppId(), reqVO.getCode()); |
| 49 | + // TODO @aquan:这里会抛出系统异常,不会抛出 ServiceException | ||
| 51 | Assert.isNull(channelDO, CHANNEL_EXIST_SAME_CHANNEL_ERROR.getMsg()); | 50 | Assert.isNull(channelDO, CHANNEL_EXIST_SAME_CHANNEL_ERROR.getMsg()); |
| 52 | 51 | ||
| 53 | // 新增渠道 | 52 | // 新增渠道 |
| @@ -154,4 +153,5 @@ public class PayChannelServiceImpl implements PayChannelService { | @@ -154,4 +153,5 @@ public class PayChannelServiceImpl implements PayChannelService { | ||
| 154 | config.verifyParam(validator); | 153 | config.verifyParam(validator); |
| 155 | channel.setConfig(config); | 154 | channel.setConfig(config); |
| 156 | } | 155 | } |
| 156 | + | ||
| 157 | } | 157 | } |
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/wx/WXPayClientConfig.java
| 1 | package cn.iocoder.yudao.framework.pay.core.client.impl.wx; | 1 | package cn.iocoder.yudao.framework.pay.core.client.impl.wx; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.io.IoUtil; | 3 | import cn.hutool.core.io.IoUtil; |
| 4 | -import cn.hutool.json.JSONObject; | ||
| 5 | -import cn.hutool.json.JSONUtil; | ||
| 6 | import cn.iocoder.yudao.framework.pay.core.client.PayClientConfig; | 4 | import cn.iocoder.yudao.framework.pay.core.client.PayClientConfig; |
| 7 | -import com.alibaba.fastjson.JSON; | ||
| 8 | import lombok.Data; | 5 | import lombok.Data; |
| 9 | -import org.springframework.beans.factory.annotation.Autowired; | ||
| 10 | import org.springframework.util.Assert; | 6 | import org.springframework.util.Assert; |
| 11 | 7 | ||
| 12 | -import javax.annotation.Resource; | ||
| 13 | import javax.validation.ConstraintViolation; | 8 | import javax.validation.ConstraintViolation; |
| 14 | import javax.validation.Validator; | 9 | import javax.validation.Validator; |
| 15 | -import javax.validation.constraints.AssertTrue; | ||
| 16 | import javax.validation.constraints.NotBlank; | 10 | import javax.validation.constraints.NotBlank; |
| 17 | import java.io.FileInputStream; | 11 | import java.io.FileInputStream; |
| 18 | import java.io.FileNotFoundException; | 12 | import java.io.FileNotFoundException; |
| @@ -95,7 +89,6 @@ public class WXPayClientConfig implements PayClientConfig { | @@ -95,7 +89,6 @@ public class WXPayClientConfig implements PayClientConfig { | ||
| 95 | @NotBlank(message = "apiV3 秘钥值 不能为空", groups = V3.class) | 89 | @NotBlank(message = "apiV3 秘钥值 不能为空", groups = V3.class) |
| 96 | private String apiV3Key; | 90 | private String apiV3Key; |
| 97 | 91 | ||
| 98 | - | ||
| 99 | /** | 92 | /** |
| 100 | * 分组校验 v2版本 | 93 | * 分组校验 v2版本 |
| 101 | */ | 94 | */ |
| @@ -108,6 +101,7 @@ public class WXPayClientConfig implements PayClientConfig { | @@ -108,6 +101,7 @@ public class WXPayClientConfig implements PayClientConfig { | ||
| 108 | public interface V3 { | 101 | public interface V3 { |
| 109 | } | 102 | } |
| 110 | 103 | ||
| 104 | + // TODO @aquan:1)已经有注释,不用重复注释;2)方法名改成 validate,比较适合 validator;3)断言是否有异常,可以封一个 ConstraintViolationException 异常 | ||
| 111 | /** | 105 | /** |
| 112 | * 验证配置参数是否正确 | 106 | * 验证配置参数是否正确 |
| 113 | * @param validator 校验对象 | 107 | * @param validator 校验对象 |
| @@ -129,5 +123,4 @@ public class WXPayClientConfig implements PayClientConfig { | @@ -129,5 +123,4 @@ public class WXPayClientConfig implements PayClientConfig { | ||
| 129 | System.out.println(IoUtil.readUtf8(new FileInputStream(path))); | 123 | System.out.println(IoUtil.readUtf8(new FileInputStream(path))); |
| 130 | } | 124 | } |
| 131 | 125 | ||
| 132 | - | ||
| 133 | } | 126 | } |
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/enums/PayChannelEnum.java
| @@ -51,12 +51,14 @@ public enum PayChannelEnum { | @@ -51,12 +51,14 @@ public enum PayChannelEnum { | ||
| 51 | return ArrayUtil.firstMatch(o -> o.getCode().equals(code), values()); | 51 | return ArrayUtil.firstMatch(o -> o.getCode().equals(code), values()); |
| 52 | } | 52 | } |
| 53 | 53 | ||
| 54 | + // TODO @aquan:加一个 configClass 字段,不用 switch 的方式哈。不然新增一个支付方式,需要改的方法有点多 | ||
| 54 | /** | 55 | /** |
| 55 | * 根据编码得到支付类 | 56 | * 根据编码得到支付类 |
| 57 | + * | ||
| 56 | * @param code 编码 | 58 | * @param code 编码 |
| 57 | * @return 支付配置类 | 59 | * @return 支付配置类 |
| 58 | */ | 60 | */ |
| 59 | - public static Class<? extends PayClientConfig> findByCodeGetClass(String code){ | 61 | + public static Class<? extends PayClientConfig> findByCodeGetClass(String code) { |
| 60 | switch (PayChannelEnum.getByCode(code)){ | 62 | switch (PayChannelEnum.getByCode(code)){ |
| 61 | case WX_PUB: | 63 | case WX_PUB: |
| 62 | case WX_LITE: | 64 | case WX_LITE: |