fix:完善订单支付逻辑动态配置微信商户支付配置
This commit is contained in:
+12
-45
@@ -16,6 +16,7 @@ import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
|
||||
import com.wechat.pay.java.service.payments.jsapi.model.SettleInfo;
|
||||
import com.wechat.pay.java.service.profitsharing.ProfitsharingService;
|
||||
import com.wechat.pay.java.service.refund.RefundService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
|
||||
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
|
||||
@@ -24,11 +25,13 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
@Slf4j
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(WechatProperties.class)
|
||||
public class WechatAutoConfiguration {
|
||||
@@ -37,6 +40,7 @@ public class WechatAutoConfiguration {
|
||||
@ConditionalOnMissingBean
|
||||
@ConditionalOnBean(WechatConfigService.class)
|
||||
public WxMpService wxMpService(WechatConfigService configService) {
|
||||
log.info("WxMpService(公众号相关)被加载,tenantId:{}", getCurrentTenantId());
|
||||
return new WxMpServiceImpl() {
|
||||
@Override
|
||||
public WxMpDefaultConfigImpl getWxMpConfigStorage() {
|
||||
@@ -62,6 +66,8 @@ public class WechatAutoConfiguration {
|
||||
@ConditionalOnMissingBean
|
||||
@ConditionalOnBean(WechatConfigService.class)
|
||||
public WxMaService wxMaService(WechatConfigService configService) {
|
||||
log.info("WxMaService(小程序通知)被加载,tenantId:{}", getCurrentTenantId());
|
||||
// 小程序通知Service配置,type=MINI
|
||||
return new WxMaServiceImpl() {
|
||||
@Override
|
||||
public WxMaDefaultConfigImpl getWxMaConfig() {
|
||||
@@ -74,58 +80,18 @@ public class WechatAutoConfiguration {
|
||||
};
|
||||
}
|
||||
|
||||
/*@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public WxPayService wxPayService(WechatConfigService configService) {
|
||||
return new WxPayServiceImpl() {
|
||||
@Override
|
||||
public WxPayConfig getConfig() {
|
||||
WechatConfig config = configService.getConfig("PAY", getCurrentMerchantId());
|
||||
WxPayConfig payConfig = new WxPayConfig();
|
||||
payConfig.setAppId(config.getAppId());
|
||||
payConfig.setMchId(config.getMerchantId());
|
||||
payConfig.setMchKey(config.getMchKey());
|
||||
payConfig.setKeyPath(config.getPrivateKeyPath());
|
||||
payConfig.setNotifyUrl(config.getNotifyUrl());
|
||||
payConfig.setApiV3Key(config.getApiV3Key());
|
||||
payConfig.setPrivateKeyPath(config.getPrivateKeyPath());
|
||||
payConfig.setPrivateCertPath(config.getPrivateKeyPath());
|
||||
payConfig.setCertSerialNo(config.getMchSerialNo());
|
||||
return payConfig;
|
||||
}
|
||||
};
|
||||
}*/
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
@ConditionalOnBean(WechatConfigService.class)
|
||||
public Config wxPayConfig(WechatConfigService configService, PrivateKeyService privateKeyService) {
|
||||
WechatConfig config = configService.getConfig("PAY", getCurrentTenantId());
|
||||
String privateKey = privateKeyService.getPrivateKey(getCurrentTenantId(), "PAY");
|
||||
return new RSAAutoCertificateConfig.Builder()
|
||||
.merchantId(config.getMerchantId())
|
||||
.privateKey(privateKey)
|
||||
.merchantSerialNumber(config.getMchSerialNo())
|
||||
.apiV3Key(config.getApiV3Key())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public JsapiServiceExtension jsapiServiceExtension(Config config) {
|
||||
return new JsapiServiceExtension.Builder().config(config).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public RefundService refundService(Config config) {
|
||||
return new RefundService.Builder().config(config).build();
|
||||
public WxPayConfigFactory wxPayConfigFactory(
|
||||
WechatConfigService configService,
|
||||
PrivateKeyService privateKeyService) {
|
||||
return new WxPayConfigFactory(configService, privateKeyService);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
@ConditionalOnBean(WechatConfigService.class)
|
||||
public NotificationConfig notificationConfig(WechatConfigService configService, PrivateKeyService privateKeyService) {
|
||||
log.info("NotificationConfig被加载,tenantId:{}", getCurrentTenantId());
|
||||
WechatConfig config = configService.getConfig("PAY", getCurrentTenantId());
|
||||
String privateKey = privateKeyService.getPrivateKey(getCurrentTenantId(), "PAY");
|
||||
return new RSAAutoCertificateConfig.Builder()
|
||||
@@ -162,6 +128,7 @@ public class WechatAutoConfiguration {
|
||||
@ConditionalOnMissingBean
|
||||
@ConditionalOnBean(WechatConfigService.class)
|
||||
public Executor profitSharingExecutor(WechatConfigService configService) {
|
||||
log.info("profitSharingExecutor被加载,tenantId:{}", getCurrentTenantId());
|
||||
WechatConfig config = configService.getConfig("PAY", getCurrentTenantId());
|
||||
if (!config.getAsyncEnabled()) {
|
||||
return null;
|
||||
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
package com.zlt.wechat.config;
|
||||
|
||||
import com.central.wechat.wechat.entity.WechatConfig;
|
||||
import com.central.wechat.wechat.feign.PrivateKeyService;
|
||||
import com.central.wechat.wechat.feign.WechatConfigService;
|
||||
import com.wechat.pay.java.core.Config;
|
||||
import com.wechat.pay.java.core.RSAAutoCertificateConfig;
|
||||
import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class WxPayConfigFactory {
|
||||
private final WechatConfigService configService;
|
||||
private final PrivateKeyService privateKeyService;
|
||||
|
||||
public WxPayConfigFactory(WechatConfigService configService, PrivateKeyService privateKeyService) {
|
||||
this.configService = configService;
|
||||
this.privateKeyService = privateKeyService;
|
||||
}
|
||||
|
||||
public Config createConfig(String tenantId) {
|
||||
log.info("创建微信支付配置,tenantId:{}", tenantId);
|
||||
WechatConfig config = configService.getConfig("PAY", tenantId);
|
||||
String privateKey = privateKeyService.getPrivateKey(tenantId, "PAY");
|
||||
return new RSAAutoCertificateConfig.Builder()
|
||||
.merchantId(config.getMerchantId())
|
||||
.privateKey(privateKey)
|
||||
.merchantSerialNumber(config.getMchSerialNo())
|
||||
.apiV3Key(config.getApiV3Key())
|
||||
.build();
|
||||
}
|
||||
|
||||
public JsapiServiceExtension createJsapiService(String tenantId) {
|
||||
Config config = createConfig(tenantId);
|
||||
return new JsapiServiceExtension.Builder().config(config).build();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user