mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-29 18:51:53 +08:00
code review 支付渠道的逻辑
This commit is contained in:
parent
f1424aa61e
commit
cea1589e79
@ -14,10 +14,8 @@ import javax.validation.constraints.NotBlank;
|
|||||||
@ToString(callSuper = true)
|
@ToString(callSuper = true)
|
||||||
public class PayChannelCreateReqVO extends PayChannelBaseVO {
|
public class PayChannelCreateReqVO extends PayChannelBaseVO {
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "通道配置的 json 字符串")
|
||||||
@ApiModelProperty(value = "通道配置的json字符串")
|
|
||||||
@NotBlank(message = "通道配置不能为空")
|
@NotBlank(message = "通道配置不能为空")
|
||||||
private String config;
|
private String config;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -11,11 +11,8 @@ import cn.iocoder.yudao.adminserver.modules.pay.service.channel.PayChannelServic
|
|||||||
import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.merchant.PayChannelDO;
|
import cn.iocoder.yudao.coreservice.modules.pay.dal.dataobject.merchant.PayChannelDO;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.framework.pay.core.client.PayClientConfig;
|
import cn.iocoder.yudao.framework.pay.core.client.PayClientConfig;
|
||||||
import cn.iocoder.yudao.framework.pay.core.client.impl.wx.WXPayClientConfig;
|
|
||||||
import cn.iocoder.yudao.framework.pay.core.enums.PayChannelEnum;
|
import cn.iocoder.yudao.framework.pay.core.enums.PayChannelEnum;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
@ -25,7 +22,8 @@ import javax.validation.Validator;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static cn.iocoder.yudao.coreservice.modules.pay.enums.PayErrorCodeCoreConstants.*;
|
import static cn.iocoder.yudao.coreservice.modules.pay.enums.PayErrorCodeCoreConstants.CHANNEL_EXIST_SAME_CHANNEL_ERROR;
|
||||||
|
import static cn.iocoder.yudao.coreservice.modules.pay.enums.PayErrorCodeCoreConstants.CHANNEL_NOT_EXISTS;
|
||||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -48,6 +46,7 @@ public class PayChannelServiceImpl implements PayChannelService {
|
|||||||
public Long createChannel(PayChannelCreateReqVO reqVO) {
|
public Long createChannel(PayChannelCreateReqVO reqVO) {
|
||||||
// 断言是否有重复的
|
// 断言是否有重复的
|
||||||
PayChannelDO channelDO = this.getChannelByConditions(reqVO.getMerchantId(), reqVO.getAppId(), reqVO.getCode());
|
PayChannelDO channelDO = this.getChannelByConditions(reqVO.getMerchantId(), reqVO.getAppId(), reqVO.getCode());
|
||||||
|
// TODO @aquan:这里会抛出系统异常,不会抛出 ServiceException
|
||||||
Assert.isNull(channelDO, CHANNEL_EXIST_SAME_CHANNEL_ERROR.getMsg());
|
Assert.isNull(channelDO, CHANNEL_EXIST_SAME_CHANNEL_ERROR.getMsg());
|
||||||
|
|
||||||
// 新增渠道
|
// 新增渠道
|
||||||
@ -154,4 +153,5 @@ public class PayChannelServiceImpl implements PayChannelService {
|
|||||||
config.verifyParam(validator);
|
config.verifyParam(validator);
|
||||||
channel.setConfig(config);
|
channel.setConfig(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,18 +1,12 @@
|
|||||||
package cn.iocoder.yudao.framework.pay.core.client.impl.wx;
|
package cn.iocoder.yudao.framework.pay.core.client.impl.wx;
|
||||||
|
|
||||||
import cn.hutool.core.io.IoUtil;
|
import cn.hutool.core.io.IoUtil;
|
||||||
import cn.hutool.json.JSONObject;
|
|
||||||
import cn.hutool.json.JSONUtil;
|
|
||||||
import cn.iocoder.yudao.framework.pay.core.client.PayClientConfig;
|
import cn.iocoder.yudao.framework.pay.core.client.PayClientConfig;
|
||||||
import com.alibaba.fastjson.JSON;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
import javax.validation.ConstraintViolation;
|
import javax.validation.ConstraintViolation;
|
||||||
import javax.validation.Validator;
|
import javax.validation.Validator;
|
||||||
import javax.validation.constraints.AssertTrue;
|
|
||||||
import javax.validation.constraints.NotBlank;
|
import javax.validation.constraints.NotBlank;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
@ -95,7 +89,6 @@ public class WXPayClientConfig implements PayClientConfig {
|
|||||||
@NotBlank(message = "apiV3 秘钥值 不能为空", groups = V3.class)
|
@NotBlank(message = "apiV3 秘钥值 不能为空", groups = V3.class)
|
||||||
private String apiV3Key;
|
private String apiV3Key;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分组校验 v2版本
|
* 分组校验 v2版本
|
||||||
*/
|
*/
|
||||||
@ -108,6 +101,7 @@ public class WXPayClientConfig implements PayClientConfig {
|
|||||||
public interface V3 {
|
public interface V3 {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO @aquan:1)已经有注释,不用重复注释;2)方法名改成 validate,比较适合 validator;3)断言是否有异常,可以封一个 ConstraintViolationException 异常
|
||||||
/**
|
/**
|
||||||
* 验证配置参数是否正确
|
* 验证配置参数是否正确
|
||||||
* @param validator 校验对象
|
* @param validator 校验对象
|
||||||
@ -129,5 +123,4 @@ public class WXPayClientConfig implements PayClientConfig {
|
|||||||
System.out.println(IoUtil.readUtf8(new FileInputStream(path)));
|
System.out.println(IoUtil.readUtf8(new FileInputStream(path)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -51,12 +51,14 @@ public enum PayChannelEnum {
|
|||||||
return ArrayUtil.firstMatch(o -> o.getCode().equals(code), values());
|
return ArrayUtil.firstMatch(o -> o.getCode().equals(code), values());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO @aquan:加一个 configClass 字段,不用 switch 的方式哈。不然新增一个支付方式,需要改的方法有点多
|
||||||
/**
|
/**
|
||||||
* 根据编码得到支付类
|
* 根据编码得到支付类
|
||||||
|
*
|
||||||
* @param code 编码
|
* @param code 编码
|
||||||
* @return 支付配置类
|
* @return 支付配置类
|
||||||
*/
|
*/
|
||||||
public static Class<? extends PayClientConfig> findByCodeGetClass(String code){
|
public static Class<? extends PayClientConfig> findByCodeGetClass(String code) {
|
||||||
switch (PayChannelEnum.getByCode(code)){
|
switch (PayChannelEnum.getByCode(code)){
|
||||||
case WX_PUB:
|
case WX_PUB:
|
||||||
case WX_LITE:
|
case WX_LITE:
|
||||||
|
Loading…
Reference in New Issue
Block a user