Commit bca6fb4698d55ddc7f26a7cc076f85b3f5aee370
Merge remote-tracking branch 'origin/feature/mall_product' into feature/mall_product
Showing
7 changed files
with
89 additions
and
84 deletions
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/PayClientFactory.java
| 1 | 1 | package cn.iocoder.yudao.framework.pay.core.client; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.framework.pay.core.client.impl.AbstractPayClient; | |
| 3 | +import cn.iocoder.yudao.framework.pay.core.enums.channel.PayChannelEnum; | |
| 4 | 4 | |
| 5 | 5 | /** |
| 6 | 6 | * 支付客户端的工厂接口 |
| ... | ... | @@ -21,8 +21,17 @@ public interface PayClientFactory { |
| 21 | 21 | * 创建支付客户端 |
| 22 | 22 | * |
| 23 | 23 | * @param channelId 渠道编号 |
| 24 | - * @param client 支付客户端 | |
| 25 | - * @param <Config> 支付配置 | |
| 24 | + * @param channelCode 渠道编码 | |
| 25 | + * @param config 支付配置 | |
| 26 | 26 | */ |
| 27 | - <Config extends PayClientConfig> void addOrUpdatePayClient(Long channelId, AbstractPayClient<Config> client); | |
| 27 | + <Config extends PayClientConfig> void createOrUpdatePayClient(Long channelId, String channelCode, | |
| 28 | + Config config); | |
| 29 | + | |
| 30 | + /** | |
| 31 | + * 注册支付客户端 Class, 用于模块中实现的 PayClient | |
| 32 | + * | |
| 33 | + * @param payChannelEnum 支付渠道的编码的枚举 | |
| 34 | + * @param payClientClass 支付客户端 class | |
| 35 | + */ | |
| 36 | + void registerPayClientClass(PayChannelEnum payChannelEnum, Class<?> payClientClass); | |
| 28 | 37 | } | ... | ... |
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/AbstractPayClient.java
| ... | ... | @@ -9,7 +9,6 @@ import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDT |
| 9 | 9 | import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundRespDTO; |
| 10 | 10 | import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundUnifiedReqDTO; |
| 11 | 11 | import cn.iocoder.yudao.framework.pay.core.client.exception.PayException; |
| 12 | -import lombok.Getter; | |
| 13 | 12 | import lombok.extern.slf4j.Slf4j; |
| 14 | 13 | |
| 15 | 14 | import java.util.Map; |
| ... | ... | @@ -36,7 +35,6 @@ public abstract class AbstractPayClient<Config extends PayClientConfig> implemen |
| 36 | 35 | /** |
| 37 | 36 | * 支付配置 |
| 38 | 37 | */ |
| 39 | - @Getter | |
| 40 | 38 | protected Config config; |
| 41 | 39 | |
| 42 | 40 | public AbstractPayClient(Long channelId, String channelCode, Config config) { | ... | ... |
yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/PayClientFactoryImpl.java
| 1 | 1 | package cn.iocoder.yudao.framework.pay.core.client.impl; |
| 2 | 2 | |
| 3 | +import cn.hutool.core.lang.Assert; | |
| 4 | +import cn.hutool.core.util.ReflectUtil; | |
| 3 | 5 | import cn.iocoder.yudao.framework.pay.core.client.PayClient; |
| 4 | 6 | import cn.iocoder.yudao.framework.pay.core.client.PayClientConfig; |
| 5 | 7 | import cn.iocoder.yudao.framework.pay.core.client.PayClientFactory; |
| 8 | +import cn.iocoder.yudao.framework.pay.core.client.impl.alipay.*; | |
| 9 | +import cn.iocoder.yudao.framework.pay.core.client.impl.mock.MockPayClient; | |
| 10 | +import cn.iocoder.yudao.framework.pay.core.client.impl.weixin.*; | |
| 11 | +import cn.iocoder.yudao.framework.pay.core.enums.channel.PayChannelEnum; | |
| 6 | 12 | import lombok.extern.slf4j.Slf4j; |
| 7 | 13 | |
| 14 | +import java.util.Map; | |
| 8 | 15 | import java.util.concurrent.ConcurrentHashMap; |
| 9 | 16 | import java.util.concurrent.ConcurrentMap; |
| 10 | 17 | |
| 18 | +import static cn.iocoder.yudao.framework.pay.core.enums.channel.PayChannelEnum.*; | |
| 19 | + | |
| 11 | 20 | /** |
| 12 | 21 | * 支付客户端的工厂实现类 |
| 13 | 22 | * |
| ... | ... | @@ -22,6 +31,29 @@ public class PayClientFactoryImpl implements PayClientFactory { |
| 22 | 31 | */ |
| 23 | 32 | private final ConcurrentMap<Long, AbstractPayClient<?>> clients = new ConcurrentHashMap<>(); |
| 24 | 33 | |
| 34 | + /** | |
| 35 | + * 支付客户端 Class Map | |
| 36 | + * key: 支付渠道的编码的枚举 | |
| 37 | + */ | |
| 38 | + private final Map<PayChannelEnum, Class<?>>clientClass = new ConcurrentHashMap<>(16); | |
| 39 | + | |
| 40 | + public PayClientFactoryImpl() { | |
| 41 | + // 微信支付客户端 | |
| 42 | + clientClass.put(WX_PUB, WxPubPayClient.class); | |
| 43 | + clientClass.put(WX_LITE, WxLitePayClient.class); | |
| 44 | + clientClass.put(WX_APP, WxAppPayClient.class); | |
| 45 | + clientClass.put(WX_BAR, WxBarPayClient.class); | |
| 46 | + clientClass.put(WX_NATIVE, WxNativePayClient.class); | |
| 47 | + // 支付包支付客户端 | |
| 48 | + clientClass.put(ALIPAY_WAP, AlipayWapPayClient.class); | |
| 49 | + clientClass.put(ALIPAY_QR, AlipayQrPayClient.class); | |
| 50 | + clientClass.put(ALIPAY_APP, AlipayAppPayClient.class); | |
| 51 | + clientClass.put(ALIPAY_PC, AlipayPcPayClient.class); | |
| 52 | + clientClass.put(ALIPAY_BAR, AlipayBarPayClient.class); | |
| 53 | + // Mock 支付客户端 | |
| 54 | + clientClass.put(MOCK, MockPayClient.class); | |
| 55 | + } | |
| 56 | + | |
| 25 | 57 | @Override |
| 26 | 58 | public PayClient getPayClient(Long channelId) { |
| 27 | 59 | AbstractPayClient<?> client = clients.get(channelId); |
| ... | ... | @@ -33,12 +65,31 @@ public class PayClientFactoryImpl implements PayClientFactory { |
| 33 | 65 | |
| 34 | 66 | @Override |
| 35 | 67 | @SuppressWarnings("unchecked") |
| 36 | - public <Config extends PayClientConfig> void addOrUpdatePayClient(Long channelId, AbstractPayClient<Config> client) { | |
| 37 | - AbstractPayClient<Config> prePayClient = (AbstractPayClient<Config>) clients.putIfAbsent(channelId, client); | |
| 38 | - if (prePayClient == null) { | |
| 68 | + public <Config extends PayClientConfig> void createOrUpdatePayClient(Long channelId, String channelCode, | |
| 69 | + Config config) { | |
| 70 | + AbstractPayClient<Config> client = (AbstractPayClient<Config>) clients.get(channelId); | |
| 71 | + if (client == null) { | |
| 72 | + client = this.createPayClient(channelId, channelCode, config); | |
| 39 | 73 | client.init(); |
| 74 | + clients.put(client.getId(), client); | |
| 40 | 75 | } else { |
| 41 | - prePayClient.refresh(client.getConfig()); | |
| 76 | + client.refresh(config); | |
| 42 | 77 | } |
| 43 | 78 | } |
| 79 | + | |
| 80 | + @Override | |
| 81 | + public void registerPayClientClass(PayChannelEnum payChannelEnum, Class<?> payClientClass) { | |
| 82 | + clientClass.put(payChannelEnum, payClientClass); | |
| 83 | + } | |
| 84 | + | |
| 85 | + @SuppressWarnings("unchecked") | |
| 86 | + private <Config extends PayClientConfig> AbstractPayClient<Config> createPayClient(Long channelId, String channelCode, | |
| 87 | + Config config) { | |
| 88 | + PayChannelEnum channelEnum = PayChannelEnum.getByCode(channelCode); | |
| 89 | + Assert.notNull(channelEnum, String.format("支付渠道(%s) 为空", channelCode)); | |
| 90 | + Class<?> payClientClass = clientClass.get(channelEnum); | |
| 91 | + Assert.notNull(payClientClass, String.format("支付渠道(%s) Class 为空", channelCode)); | |
| 92 | + return (AbstractPayClient<Config>) ReflectUtil.newInstance(payClientClass, channelId, config); | |
| 93 | + } | |
| 94 | + | |
| 44 | 95 | } | ... | ... |
yudao-framework/yudao-spring-boot-starter-biz-pay/src/test/java/cn/iocoder/yudao/framework/pay/core/client/impl/PayClientFactoryImplIntegrationTest.java
| ... | ... | @@ -9,6 +9,7 @@ import cn.iocoder.yudao.framework.pay.core.client.impl.alipay.AlipayQrPayClient; |
| 9 | 9 | import cn.iocoder.yudao.framework.pay.core.client.impl.alipay.AlipayWapPayClient; |
| 10 | 10 | import cn.iocoder.yudao.framework.pay.core.client.impl.weixin.WxPayClientConfig; |
| 11 | 11 | import cn.iocoder.yudao.framework.pay.core.client.impl.weixin.WxPubPayClient; |
| 12 | +import cn.iocoder.yudao.framework.pay.core.enums.channel.PayChannelEnum; | |
| 12 | 13 | import org.junit.jupiter.api.Disabled; |
| 13 | 14 | import org.junit.jupiter.api.Test; |
| 14 | 15 | |
| ... | ... | @@ -40,8 +41,7 @@ public class PayClientFactoryImplIntegrationTest { |
| 40 | 41 | config.setMchKey("0alL64UDQdlCwiKZ73ib7ypaIjMns06p"); |
| 41 | 42 | // 创建客户端 |
| 42 | 43 | Long channelId = RandomUtil.randomLong(); |
| 43 | - | |
| 44 | - payClientFactory.addOrUpdatePayClient(channelId, new WxPubPayClient(channelId, config)); | |
| 44 | + payClientFactory.createOrUpdatePayClient(channelId, PayChannelEnum.WX_PUB.getCode(), config); | |
| 45 | 45 | PayClient client = payClientFactory.getPayClient(channelId); |
| 46 | 46 | // 发起支付 |
| 47 | 47 | PayOrderUnifiedReqDTO reqDTO = buildPayOrderUnifiedReqDTO(); |
| ... | ... | @@ -64,7 +64,7 @@ public class PayClientFactoryImplIntegrationTest { |
| 64 | 64 | config.setApiV3Key("joerVi8y5DJ3o4ttA0o1uH47Xz1u2Ase"); |
| 65 | 65 | // 创建客户端 |
| 66 | 66 | Long channelId = RandomUtil.randomLong(); |
| 67 | - payClientFactory.addOrUpdatePayClient(channelId, new WxPubPayClient(channelId, config)); | |
| 67 | + payClientFactory.createOrUpdatePayClient(channelId, PayChannelEnum.WX_PUB.getCode(), config); | |
| 68 | 68 | PayClient client = payClientFactory.getPayClient(channelId); |
| 69 | 69 | // 发起支付 |
| 70 | 70 | PayOrderUnifiedReqDTO reqDTO = buildPayOrderUnifiedReqDTO(); |
| ... | ... | @@ -87,7 +87,7 @@ public class PayClientFactoryImplIntegrationTest { |
| 87 | 87 | config.setAlipayPublicKey("MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnq90KnF4dTnlzzmxpujbI05OYqi5WxAS6cL0gnZFv2gK51HExF8v/BaP7P979PhFMgWTqmOOI+Dtno5s+yD09XTY1WkshbLk6i4g2Xlr8fyW9ODnkU88RI2w9UdPhQU4cPPwBNlrsYhKkVK2OxwM3kFqjoBBY0CZoZCsSQ3LDH5WeZqPArlsS6xa2zqJBuuoKjMrdpELl3eXSjP8K54eDJCbeetCZNKWLL3DPahTPB7LZikfYmslb0QUvCgGapD0xkS7eVq70NaL1G57MWABs4tbfWgxike4Daj3EfUrzIVspQxj7w8HEj9WozJPgL88kSJSits0pqD3n5r8HSuseQIDAQAB"); |
| 88 | 88 | // 创建客户端 |
| 89 | 89 | Long channelId = RandomUtil.randomLong(); |
| 90 | - payClientFactory.addOrUpdatePayClient(channelId, new AlipayQrPayClient(channelId, config)); | |
| 90 | + payClientFactory.createOrUpdatePayClient(channelId, PayChannelEnum.ALIPAY_QR.getCode(), config); | |
| 91 | 91 | PayClient client = payClientFactory.getPayClient(channelId); |
| 92 | 92 | // 发起支付 |
| 93 | 93 | PayOrderUnifiedReqDTO reqDTO = buildPayOrderUnifiedReqDTO(); |
| ... | ... | @@ -111,7 +111,7 @@ public class PayClientFactoryImplIntegrationTest { |
| 111 | 111 | config.setAlipayPublicKey("MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnq90KnF4dTnlzzmxpujbI05OYqi5WxAS6cL0gnZFv2gK51HExF8v/BaP7P979PhFMgWTqmOOI+Dtno5s+yD09XTY1WkshbLk6i4g2Xlr8fyW9ODnkU88RI2w9UdPhQU4cPPwBNlrsYhKkVK2OxwM3kFqjoBBY0CZoZCsSQ3LDH5WeZqPArlsS6xa2zqJBuuoKjMrdpELl3eXSjP8K54eDJCbeetCZNKWLL3DPahTPB7LZikfYmslb0QUvCgGapD0xkS7eVq70NaL1G57MWABs4tbfWgxike4Daj3EfUrzIVspQxj7w8HEj9WozJPgL88kSJSits0pqD3n5r8HSuseQIDAQAB"); |
| 112 | 112 | // 创建客户端 |
| 113 | 113 | Long channelId = RandomUtil.randomLong(); |
| 114 | - payClientFactory.addOrUpdatePayClient(channelId, new AlipayWapPayClient(channelId, config)); | |
| 114 | + payClientFactory.createOrUpdatePayClient(channelId, PayChannelEnum.ALIPAY_WAP.getCode(), config); | |
| 115 | 115 | PayClient client = payClientFactory.getPayClient(channelId); |
| 116 | 116 | // 发起支付 |
| 117 | 117 | PayOrderUnifiedReqDTO reqDTO = buildPayOrderUnifiedReqDTO(); | ... | ... |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/framework/pay/wallet/WalletPayClient.java
| 1 | 1 | package cn.iocoder.yudao.module.pay.framework.pay.wallet; |
| 2 | 2 | |
| 3 | +import cn.hutool.extra.spring.SpringUtil; | |
| 3 | 4 | import cn.iocoder.yudao.framework.common.exception.ServiceException; |
| 4 | 5 | import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderRespDTO; |
| 5 | 6 | import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDTO; |
| ... | ... | @@ -7,6 +8,7 @@ import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundRespDTO; |
| 7 | 8 | import cn.iocoder.yudao.framework.pay.core.client.dto.refund.PayRefundUnifiedReqDTO; |
| 8 | 9 | import cn.iocoder.yudao.framework.pay.core.client.impl.AbstractPayClient; |
| 9 | 10 | import cn.iocoder.yudao.framework.pay.core.client.impl.NonePayClientConfig; |
| 11 | +import cn.iocoder.yudao.framework.pay.core.enums.channel.PayChannelEnum; | |
| 10 | 12 | import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO; |
| 11 | 13 | import cn.iocoder.yudao.module.pay.service.wallet.PayWalletService; |
| 12 | 14 | import lombok.extern.slf4j.Slf4j; |
| ... | ... | @@ -23,30 +25,26 @@ import static cn.iocoder.yudao.framework.common.exception.enums.GlobalErrorCodeC |
| 23 | 25 | @Slf4j |
| 24 | 26 | public class WalletPayClient extends AbstractPayClient<NonePayClientConfig> { |
| 25 | 27 | |
| 26 | - private PayWalletService payWalletService; | |
| 28 | + private PayWalletService client; | |
| 27 | 29 | |
| 28 | - public WalletPayClient(Long channelId, String channelCode, NonePayClientConfig config) { | |
| 29 | - super(channelId, channelCode, config); | |
| 30 | - } | |
| 31 | - | |
| 32 | - public WalletPayClient(Long channelId, String channelCode, NonePayClientConfig config, | |
| 33 | - PayWalletService payWalletService) { | |
| 34 | - this(channelId, channelCode, config); | |
| 35 | - this.payWalletService = payWalletService; | |
| 30 | + public WalletPayClient(Long channelId, NonePayClientConfig config) { | |
| 31 | + super(channelId, PayChannelEnum.WALLET.getCode(), config); | |
| 36 | 32 | } |
| 37 | 33 | |
| 38 | 34 | @Override |
| 39 | 35 | protected void doInit() { |
| 40 | - // 钱包支付,无需初始化 | |
| 36 | + if (client == null) { | |
| 37 | + client = SpringUtil.getBean(PayWalletService.class); | |
| 38 | + } | |
| 41 | 39 | } |
| 42 | 40 | |
| 43 | 41 | @Override |
| 44 | 42 | protected PayOrderRespDTO doUnifiedOrder(PayOrderUnifiedReqDTO reqDTO) { |
| 45 | 43 | try { |
| 46 | - PayWalletTransactionDO transaction = payWalletService.pay(reqDTO.getOutTradeNo(), reqDTO.getPrice()); | |
| 44 | + PayWalletTransactionDO transaction = client.pay(reqDTO.getOutTradeNo(), reqDTO.getPrice()); | |
| 47 | 45 | return PayOrderRespDTO.successOf(transaction.getNo(), transaction.getCreator(), |
| 48 | 46 | transaction.getTransactionTime(), |
| 49 | - reqDTO.getOutTradeNo(), "WALLET_PAY_SUCCESS"); // TODO @jason:transaction 作为 traData 好了; | |
| 47 | + reqDTO.getOutTradeNo(), transaction); | |
| 50 | 48 | } catch (Throwable ex) { |
| 51 | 49 | log.error("[doUnifiedOrder] 失败", ex); |
| 52 | 50 | Integer errorCode = INTERNAL_SERVER_ERROR.getCode(); |
| ... | ... | @@ -74,10 +72,10 @@ public class WalletPayClient extends AbstractPayClient<NonePayClientConfig> { |
| 74 | 72 | @Override |
| 75 | 73 | protected PayRefundRespDTO doUnifiedRefund(PayRefundUnifiedReqDTO reqDTO) { |
| 76 | 74 | try { |
| 77 | - PayWalletTransactionDO payWalletTransaction = payWalletService.refund(reqDTO.getOutRefundNo(), | |
| 75 | + PayWalletTransactionDO payWalletTransaction = client.refund(reqDTO.getOutRefundNo(), | |
| 78 | 76 | reqDTO.getRefundPrice(), reqDTO.getReason()); |
| 79 | 77 | return PayRefundRespDTO.successOf(payWalletTransaction.getNo(), payWalletTransaction.getTransactionTime(), |
| 80 | - reqDTO.getOutRefundNo(), "WALLET_REFUND_SUCCESS"); | |
| 78 | + reqDTO.getOutRefundNo(), payWalletTransaction); | |
| 81 | 79 | } catch (Throwable ex) { |
| 82 | 80 | log.error("[doUnifiedRefund] 失败", ex); |
| 83 | 81 | Integer errorCode = INTERNAL_SERVER_ERROR.getCode(); | ... | ... |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/channel/PayChannelServiceImpl.java
| ... | ... | @@ -8,12 +8,6 @@ import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| 8 | 8 | import cn.iocoder.yudao.framework.common.util.json.JsonUtils; |
| 9 | 9 | import cn.iocoder.yudao.framework.pay.core.client.PayClientConfig; |
| 10 | 10 | import cn.iocoder.yudao.framework.pay.core.client.PayClientFactory; |
| 11 | -import cn.iocoder.yudao.framework.pay.core.client.impl.AbstractPayClient; | |
| 12 | -import cn.iocoder.yudao.framework.pay.core.client.impl.NonePayClientConfig; | |
| 13 | -import cn.iocoder.yudao.framework.pay.core.client.impl.alipay.*; | |
| 14 | -import cn.iocoder.yudao.framework.pay.core.client.impl.mock.MockPayClient; | |
| 15 | -import cn.iocoder.yudao.framework.pay.core.client.impl.mock.MockPayClientConfig; | |
| 16 | -import cn.iocoder.yudao.framework.pay.core.client.impl.weixin.*; | |
| 17 | 11 | import cn.iocoder.yudao.framework.pay.core.enums.channel.PayChannelEnum; |
| 18 | 12 | import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils; |
| 19 | 13 | import cn.iocoder.yudao.module.pay.controller.admin.channel.vo.PayChannelCreateReqVO; |
| ... | ... | @@ -22,7 +16,6 @@ import cn.iocoder.yudao.module.pay.convert.channel.PayChannelConvert; |
| 22 | 16 | import cn.iocoder.yudao.module.pay.dal.dataobject.channel.PayChannelDO; |
| 23 | 17 | import cn.iocoder.yudao.module.pay.dal.mysql.channel.PayChannelMapper; |
| 24 | 18 | import cn.iocoder.yudao.module.pay.framework.pay.wallet.WalletPayClient; |
| 25 | -import cn.iocoder.yudao.module.pay.service.wallet.PayWalletService; | |
| 26 | 19 | import lombok.Getter; |
| 27 | 20 | import lombok.Setter; |
| 28 | 21 | import lombok.extern.slf4j.Slf4j; |
| ... | ... | @@ -64,14 +57,14 @@ public class PayChannelServiceImpl implements PayChannelService { |
| 64 | 57 | |
| 65 | 58 | @Resource |
| 66 | 59 | private Validator validator; |
| 67 | - @Resource | |
| 68 | - private PayWalletService payWalletService; | |
| 69 | 60 | |
| 70 | 61 | /** |
| 71 | 62 | * 初始化 {@link #payClientFactory} 缓存 |
| 72 | 63 | */ |
| 73 | 64 | @PostConstruct |
| 74 | 65 | public void initLocalCache() { |
| 66 | + // 注册钱包支付 Class | |
| 67 | + payClientFactory.registerPayClientClass(PayChannelEnum.WALLET, WalletPayClient.class); | |
| 75 | 68 | // 注意:忽略自动多租户,因为要全局初始化缓存 |
| 76 | 69 | TenantUtils.executeIgnore(() -> { |
| 77 | 70 | // 第一步:查询数据 |
| ... | ... | @@ -86,54 +79,11 @@ public class PayChannelServiceImpl implements PayChannelService { |
| 86 | 79 | } |
| 87 | 80 | log.info("[initLocalCache][缓存支付渠道,数量为:{}]", channels.size()); |
| 88 | 81 | // 第二步:构建缓存:创建或更新支付 Client |
| 89 | - channels.forEach(payChannel ->{ | |
| 90 | - AbstractPayClient<PayClientConfig> payClient = createPayClient(payChannel.getId(), payChannel.getCode(), payChannel.getConfig()); | |
| 91 | - payClientFactory.addOrUpdatePayClient(payChannel.getId(), payClient); | |
| 92 | - | |
| 93 | - }); | |
| 82 | + channels.forEach(payChannel -> payClientFactory.createOrUpdatePayClient(payChannel.getId(), | |
| 83 | + payChannel.getCode(), payChannel.getConfig())); | |
| 94 | 84 | this.channelCache = channels; |
| 95 | 85 | }); |
| 96 | 86 | } |
| 97 | - @SuppressWarnings("unchecked") | |
| 98 | - private <Config extends PayClientConfig> AbstractPayClient<Config> createPayClient( | |
| 99 | - Long channelId, String channelCode, Config config) { | |
| 100 | - PayChannelEnum channelEnum = PayChannelEnum.getByCode(channelCode); | |
| 101 | - Assert.notNull(channelEnum, String.format("支付渠道(%s) 为空", channelEnum)); | |
| 102 | - // 创建客户端 | |
| 103 | - switch (channelEnum) { | |
| 104 | - // 微信支付 | |
| 105 | - case WX_PUB: | |
| 106 | - return (AbstractPayClient<Config>) new WxPubPayClient(channelId, (WxPayClientConfig) config); | |
| 107 | - case WX_LITE: | |
| 108 | - return (AbstractPayClient<Config>) new WxLitePayClient(channelId, (WxPayClientConfig) config); | |
| 109 | - case WX_APP: | |
| 110 | - return (AbstractPayClient<Config>) new WxAppPayClient(channelId, (WxPayClientConfig) config); | |
| 111 | - case WX_BAR: | |
| 112 | - return (AbstractPayClient<Config>) new WxBarPayClient(channelId, (WxPayClientConfig) config); | |
| 113 | - case WX_NATIVE: | |
| 114 | - return (AbstractPayClient<Config>) new WxNativePayClient(channelId, (WxPayClientConfig) config); | |
| 115 | - // 支付宝支付 | |
| 116 | - case ALIPAY_WAP: | |
| 117 | - return (AbstractPayClient<Config>) new AlipayWapPayClient(channelId, (AlipayPayClientConfig) config); | |
| 118 | - case ALIPAY_QR: | |
| 119 | - return (AbstractPayClient<Config>) new AlipayQrPayClient(channelId, (AlipayPayClientConfig) config); | |
| 120 | - case ALIPAY_APP: | |
| 121 | - return (AbstractPayClient<Config>) new AlipayAppPayClient(channelId, (AlipayPayClientConfig) config); | |
| 122 | - case ALIPAY_PC: | |
| 123 | - return (AbstractPayClient<Config>) new AlipayPcPayClient(channelId, (AlipayPayClientConfig) config); | |
| 124 | - case ALIPAY_BAR: | |
| 125 | - return (AbstractPayClient<Config>) new AlipayBarPayClient(channelId, (AlipayPayClientConfig) config); | |
| 126 | - // 其它支付 | |
| 127 | - case MOCK: | |
| 128 | - return (AbstractPayClient<Config>) new MockPayClient(channelId, (MockPayClientConfig) config); | |
| 129 | - case WALLET: | |
| 130 | - return (AbstractPayClient<Config>) new WalletPayClient( | |
| 131 | - channelId, channelCode, (NonePayClientConfig) config, payWalletService); | |
| 132 | - } | |
| 133 | - // 创建失败,错误日志 + 抛出异常 | |
| 134 | - log.error("[createPayClient][配置({}) 找不到合适的客户端实现]", config); | |
| 135 | - throw new IllegalArgumentException(String.format("配置(%s) 找不到合适的客户端实现", config)); | |
| 136 | - } | |
| 137 | 87 | |
| 138 | 88 | /** |
| 139 | 89 | * 通过定时任务轮询,刷新缓存 | ... | ... |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java
| ... | ... | @@ -45,7 +45,6 @@ public class PayWalletServiceImpl implements PayWalletService { |
| 45 | 45 | private PayWalletMapper payWalletMapper; |
| 46 | 46 | @Resource |
| 47 | 47 | private PayNoRedisDAO noRedisDAO; |
| 48 | - | |
| 49 | 48 | @Resource |
| 50 | 49 | private PayWalletTransactionService payWalletTransactionService; |
| 51 | 50 | @Resource | ... | ... |