fix:支付和通知相关模块代码恢复

This commit is contained in:
2025-06-03 12:10:26 +08:00
parent ce896c158f
commit ee840a2df1
5 changed files with 315 additions and 311 deletions
@@ -2,12 +2,9 @@ package com.central.order;
import com.central.common.lb.annotation.EnableFeignInterceptor; import com.central.common.lb.annotation.EnableFeignInterceptor;
import com.central.search.annotation.EnableSearchClient; import com.central.search.annotation.EnableSearchClient;
import com.zlt.wechat.config.WechatAutoConfiguration;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Import;
import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.transaction.annotation.EnableTransactionManagement;
/** /**
@@ -18,8 +15,6 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
@EnableTransactionManagement @EnableTransactionManagement
@EnableFeignInterceptor @EnableFeignInterceptor
@SpringBootApplication @SpringBootApplication
@EnableFeignClients(basePackages = {"com.central"})
@Import(WechatAutoConfiguration.class)
public class OrderCenterApp { public class OrderCenterApp {
public static void main(String[] args) { public static void main(String[] args) {
SpringApplication.run(OrderCenterApp.class, args); SpringApplication.run(OrderCenterApp.class, args);
@@ -1,98 +1,98 @@
package com.central.order.service; //package com.central.order.service;
//
import com.central.common.context.LoginUserContextHolder; //import com.central.common.context.LoginUserContextHolder;
import com.central.common.exception.BusinessException; //import com.central.common.exception.BusinessException;
import com.central.common.model.SysUser; //import com.central.common.model.SysUser;
import com.central.order.feign.UserCenterService; //import com.central.order.feign.UserCenterService;
import com.central.order.model.Order; //import com.central.order.model.Order;
import com.central.order.model.QrCode; //import com.central.order.model.QrCode;
import com.central.wechat.wechat.entity.WechatConfig; //import com.central.wechat.wechat.entity.WechatConfig;
import com.central.wechat.wechat.feign.WechatConfigService; //import com.central.wechat.wechat.feign.WechatConfigService;
import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension; //import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
import com.wechat.pay.java.service.payments.jsapi.model.*; //import com.wechat.pay.java.service.payments.jsapi.model.*;
import com.zlt.wechat.config.WxPayConfigFactory; //import com.zlt.wechat.config.WxPayConfigFactory;
import lombok.extern.slf4j.Slf4j; //import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; //import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; //import org.springframework.stereotype.Service;
//
@Slf4j //@Slf4j
@Service //@Service
public class PaymentService { //public class PaymentService {
@Autowired // @Autowired
private WxPayConfigFactory wxPayConfigFactory; // private WxPayConfigFactory wxPayConfigFactory;
@Autowired // @Autowired
private UserCenterService userCenterService; // private UserCenterService userCenterService;
@Autowired // @Autowired
private IOrderService orderService; // private IOrderService orderService;
@Autowired // @Autowired
private IQrCodeService qrCodeService; // private IQrCodeService qrCodeService;
@Autowired // @Autowired
private IProfitSharingService profitSharingService; // private IProfitSharingService profitSharingService;
@Autowired // @Autowired
private WechatConfigService configService; // private WechatConfigService configService;
//
//
//
public PrepayWithRequestPaymentResponse createPayment(Long orderId) { // public PrepayWithRequestPaymentResponse createPayment(Long orderId) {
// 1. 获取用户和订单信息 // // 1. 获取用户和订单信息
SysUser user = userCenterService.findUserById(LoginUserContextHolder.getUser().getId()); // SysUser user = userCenterService.findUserById(LoginUserContextHolder.getUser().getId());
Order order = orderService.getById(orderId); // Order order = orderService.getById(orderId);
if (order == null) { // if (order == null) {
throw new BusinessException("订单数据不存在"); // throw new BusinessException("订单数据不存在");
} // }
//
// 2. 获取二维码信息 // // 2. 获取二维码信息
QrCode qrCode = qrCodeService.getByCodeId(order.getCodeId()); // QrCode qrCode = qrCodeService.getByCodeId(order.getCodeId());
if (qrCode == null) { // if (qrCode == null) {
throw new BusinessException("二维码不存在"); // throw new BusinessException("二维码不存在");
} // }
//
// 3. 创建支付请求 // // 3. 创建支付请求
PrepayRequest request = new PrepayRequest(); // PrepayRequest request = new PrepayRequest();
//
// 设置基本支付信息 // // 设置基本支付信息
Amount amount = new Amount(); // Amount amount = new Amount();
amount.setTotal(Integer.parseInt(order.getOrderAmount())); // amount.setTotal(Integer.parseInt(order.getOrderAmount()));
request.setAmount(amount); // request.setAmount(amount);
//
// 从二维码配置中获取支付配置 // // 从二维码配置中获取支付配置
WechatConfig payConfig = configService.getConfig("PAY", qrCode.getTenantId()); // WechatConfig payConfig = configService.getConfig("PAY", qrCode.getTenantId());
request.setAppid(payConfig.getAppId()); // request.setAppid(payConfig.getAppId());
request.setMchid(payConfig.getMerchantId()); // request.setMchid(payConfig.getMerchantId());
request.setDescription(order.getOrderNo()); // request.setDescription(order.getOrderNo());
request.setNotifyUrl(payConfig.getNotifyUrl()); // request.setNotifyUrl(payConfig.getNotifyUrl());
request.setOutTradeNo(order.getOrderNo()); // request.setOutTradeNo(order.getOrderNo());
//
// 设置支付者信息 // // 设置支付者信息
Payer payer = new Payer(); // Payer payer = new Payer();
payer.setOpenid(user.getOpenId()); // payer.setOpenid(user.getOpenId());
request.setPayer(payer); // request.setPayer(payer);
//
// 设置分账信息 // // 设置分账信息
SettleInfo settleInfo = new SettleInfo(); // SettleInfo settleInfo = new SettleInfo();
if (isEnableProfit(qrCode)) { // if (isEnableProfit(qrCode)) {
settleInfo.setProfitSharing(true); // settleInfo.setProfitSharing(true);
request.setSettleInfo(settleInfo); // request.setSettleInfo(settleInfo);
// 创建分账记录 // // 创建分账记录
profitSharingService.createProfitSharing(order, qrCode); // profitSharingService.createProfitSharing(order, qrCode);
} else { // } else {
settleInfo.setProfitSharing(false); // settleInfo.setProfitSharing(false);
request.setSettleInfo(settleInfo); // request.setSettleInfo(settleInfo);
} // }
//
// 4. 创建对应租户的支付服务 // // 4. 创建对应租户的支付服务
JsapiServiceExtension jsapiService = wxPayConfigFactory.createJsapiService(qrCode.getTenantId()); // JsapiServiceExtension jsapiService = wxPayConfigFactory.createJsapiService(qrCode.getTenantId());
//
// 5. 调用支付接口 // // 5. 调用支付接口
return jsapiService.prepayWithRequestPayment(request); // return jsapiService.prepayWithRequestPayment(request);
} // }
//
private boolean isEnableProfit(QrCode qrCode) { // private boolean isEnableProfit(QrCode qrCode) {
return qrCode != null && // return qrCode != null &&
Integer.valueOf(1).equals(qrCode.getEnableProfit()) && // Integer.valueOf(1).equals(qrCode.getEnableProfit()) &&
qrCode.getPayeeStatus() != null && // qrCode.getPayeeStatus() != null &&
qrCode.getPayeeStatus() == 1 && // qrCode.getPayeeStatus() == 1 &&
qrCode.getPayeeAccount() != null && // qrCode.getPayeeAccount() != null &&
qrCode.getProfitRate() != null; // qrCode.getProfitRate() != null;
} // }
} //}
@@ -117,3 +117,12 @@ wx:
video-complete: TEMPLATE_ID_2 # 视频完成通知模板ID video-complete: TEMPLATE_ID_2 # 视频完成通知模板ID
video-failure: TEMPLATE_ID_3 # 视频失败通知模板ID video-failure: TEMPLATE_ID_3 # 视频失败通知模板ID
mini:
app-id: ${zlt.wxpay.appId}
secret: ${zlt.security.tencent.app-secret}
template:
pay-success: nSy7NGq1443YCfhgR81fgkeOVv9cSM5Ysp3nMoQYVpc
service-process: rgQCI3fMKPpgO-9nO3TzP-omohraGxX2suVioq7hQhk
activity-start: lgwkRnbdDc3mEwk3RMob43LpLHnLfglZtTkbFRPsPCA
order-complete: ZeIlAA6ImQLxBiLmo-53lM7wkL4KnuKKTGKWBZwYAdM
video-edit-complete: IXpL-Voztm3GM-zFj3sxA39qy8oRtAcxTiT7_Qsyz9Q
@@ -1,166 +1,166 @@
package com.zlt.wechat.config; //package com.zlt.wechat.config;
//
import cn.binarywang.wx.miniapp.api.WxMaService; //import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl; //import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl; //import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
import com.central.common.context.TenantContextHolder; //import com.central.common.context.TenantContextHolder;
import com.central.wechat.wechat.config.WechatProperties; //import com.central.wechat.wechat.config.WechatProperties;
import com.central.wechat.wechat.entity.WechatConfig; //import com.central.wechat.wechat.entity.WechatConfig;
import com.central.wechat.wechat.feign.PrivateKeyService; //import com.central.wechat.wechat.feign.PrivateKeyService;
import com.central.wechat.wechat.feign.WechatConfigService; //import com.central.wechat.wechat.feign.WechatConfigService;
import com.wechat.pay.java.core.Config; //import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.RSAAutoCertificateConfig; //import com.wechat.pay.java.core.RSAAutoCertificateConfig;
import com.wechat.pay.java.core.notification.NotificationConfig; //import com.wechat.pay.java.core.notification.NotificationConfig;
import com.wechat.pay.java.core.notification.NotificationParser; //import com.wechat.pay.java.core.notification.NotificationParser;
import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension; //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.payments.jsapi.model.SettleInfo;
import com.wechat.pay.java.service.profitsharing.ProfitsharingService; //import com.wechat.pay.java.service.profitsharing.ProfitsharingService;
import lombok.extern.slf4j.Slf4j; //import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.mp.api.WxMpService; //import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl; //import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl; //import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; //import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; //import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties; //import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean; //import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; //import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; //import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
//
import java.util.concurrent.Executor; //import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor; //import java.util.concurrent.ThreadPoolExecutor;
//
@Slf4j //@Slf4j
@Configuration //@Configuration
@EnableConfigurationProperties(WechatProperties.class) //@EnableConfigurationProperties(WechatProperties.class)
public class WechatAutoConfiguration { //public class WechatAutoConfiguration {
//
@Bean // @Bean
@ConditionalOnMissingBean // @ConditionalOnMissingBean
@ConditionalOnBean(WechatConfigService.class) // @ConditionalOnBean(WechatConfigService.class)
public WxMpService wxMpService(WechatConfigService configService) { // public WxMpService wxMpService(WechatConfigService configService) {
log.info("WxMpService(公众号相关)被加载,tenantId:{}", getCurrentTenantId()); // log.info("WxMpService(公众号相关)被加载,tenantId:{}", getCurrentTenantId());
return new WxMpServiceImpl() { // return new WxMpServiceImpl() {
@Override // @Override
public WxMpDefaultConfigImpl getWxMpConfigStorage() { // public WxMpDefaultConfigImpl getWxMpConfigStorage() {
WechatConfig config = configService.getConfig("MP", getCurrentTenantId()); // WechatConfig config = configService.getConfig("MP", getCurrentTenantId());
WxMpDefaultConfigImpl wxConfig = new WxMpDefaultConfigImpl(); // WxMpDefaultConfigImpl wxConfig = new WxMpDefaultConfigImpl();
wxConfig.setAppId(config.getAppId()); // wxConfig.setAppId(config.getAppId());
wxConfig.setSecret(config.getAppSecret()); // wxConfig.setSecret(config.getAppSecret());
wxConfig.setToken(config.getToken()); // wxConfig.setToken(config.getToken());
wxConfig.setAesKey(config.getAesKey()); // wxConfig.setAesKey(config.getAesKey());
return wxConfig; // return wxConfig;
} // }
}; // };
} // }
//
/** // /**
* 这个配置类在启动时可能会遇到问题,因为: // * 这个配置类在启动时可能会遇到问题,因为:
* WechatAutoConfiguration是一个自动配置类 // * WechatAutoConfiguration是一个自动配置类
* 它依赖于WechatConfigService这个Feign客户端 // * 它依赖于WechatConfigService这个Feign客户端
* 如果Feign客户端还没有被创建,就会导致注入失败 // * 如果Feign客户端还没有被创建,就会导致注入失败
* 因此使用@ConditionalOnBean注解确保配置类只在Feign客户端可用时才创建相关Bean // * 因此使用@ConditionalOnBean注解确保配置类只在Feign客户端可用时才创建相关Bean
*/ // */
@Bean // @Bean
@ConditionalOnMissingBean // @ConditionalOnMissingBean
@ConditionalOnBean(WechatConfigService.class) // @ConditionalOnBean(WechatConfigService.class)
public WxMaService wxMaService(WechatConfigService configService) { // public WxMaService wxMaService(WechatConfigService configService) {
log.info("WxMaService(小程序通知)被加载,tenantId:{}", getCurrentTenantId()); // log.info("WxMaService(小程序通知)被加载,tenantId:{}", getCurrentTenantId());
// 小程序通知Service配置,type=MINI // // 小程序通知Service配置,type=MINI
return new WxMaServiceImpl() { // return new WxMaServiceImpl() {
@Override // @Override
public WxMaDefaultConfigImpl getWxMaConfig() { // public WxMaDefaultConfigImpl getWxMaConfig() {
WechatConfig config = configService.getConfig("MINI", getCurrentTenantId()); // WechatConfig config = configService.getConfig("MINI", getCurrentTenantId());
WxMaDefaultConfigImpl wxConfig = new WxMaDefaultConfigImpl(); // WxMaDefaultConfigImpl wxConfig = new WxMaDefaultConfigImpl();
wxConfig.setAppid(config.getAppId()); // wxConfig.setAppid(config.getAppId());
wxConfig.setSecret(config.getAppSecret()); // wxConfig.setSecret(config.getAppSecret());
return wxConfig; // return wxConfig;
} // }
}; // };
} // }
//
@Bean // @Bean
@ConditionalOnBean({WechatConfigService.class, PrivateKeyService.class}) // @ConditionalOnBean({WechatConfigService.class, PrivateKeyService.class})
public WxPayConfigFactory wxPayConfigFactory( // public WxPayConfigFactory wxPayConfigFactory(
WechatConfigService configService, // WechatConfigService configService,
PrivateKeyService privateKeyService) { // PrivateKeyService privateKeyService) {
log.info("WxPayConfigFactory被加载,tenantId:{}", getCurrentTenantId()); // log.info("WxPayConfigFactory被加载,tenantId:{}", getCurrentTenantId());
return new WxPayConfigFactory(configService, privateKeyService); // return new WxPayConfigFactory(configService, privateKeyService);
} // }
//
@Bean // @Bean
@ConditionalOnBean(WxPayConfigFactory.class) // @ConditionalOnBean(WxPayConfigFactory.class)
public Config wxPayConfig(WxPayConfigFactory factory) { // public Config wxPayConfig(WxPayConfigFactory factory) {
return factory.createConfig(getCurrentTenantId()); // return factory.createConfig(getCurrentTenantId());
} // }
//
@Bean // @Bean
@ConditionalOnBean(WxPayConfigFactory.class) // @ConditionalOnBean(WxPayConfigFactory.class)
public JsapiServiceExtension jsapiService(WxPayConfigFactory factory) { // public JsapiServiceExtension jsapiService(WxPayConfigFactory factory) {
return factory.createJsapiService(getCurrentTenantId()); // return factory.createJsapiService(getCurrentTenantId());
} // }
//
@Bean // @Bean
@ConditionalOnMissingBean // @ConditionalOnMissingBean
@ConditionalOnBean(WechatConfigService.class) // @ConditionalOnBean(WechatConfigService.class)
public NotificationConfig notificationConfig(WechatConfigService configService, PrivateKeyService privateKeyService) { // public NotificationConfig notificationConfig(WechatConfigService configService, PrivateKeyService privateKeyService) {
log.info("NotificationConfig被加载,tenantId:{}", getCurrentTenantId()); // log.info("NotificationConfig被加载,tenantId:{}", getCurrentTenantId());
WechatConfig config = configService.getConfig("PAY", getCurrentTenantId()); // WechatConfig config = configService.getConfig("PAY", getCurrentTenantId());
String privateKey = privateKeyService.getPrivateKey(getCurrentTenantId(), "PAY"); // String privateKey = privateKeyService.getPrivateKey(getCurrentTenantId(), "PAY");
return new RSAAutoCertificateConfig.Builder() // return new RSAAutoCertificateConfig.Builder()
.merchantId(config.getMerchantId()) // .merchantId(config.getMerchantId())
.privateKey(privateKey) // .privateKey(privateKey)
.merchantSerialNumber(config.getMchSerialNo()) // .merchantSerialNumber(config.getMchSerialNo())
.apiV3Key(config.getApiV3Key()) // .apiV3Key(config.getApiV3Key())
.build(); // .build();
} // }
//
@Bean // @Bean
@ConditionalOnMissingBean // @ConditionalOnMissingBean
public NotificationParser notificationParser(NotificationConfig config) { // public NotificationParser notificationParser(NotificationConfig config) {
return new NotificationParser(config); // return new NotificationParser(config);
} // }
//
@Bean // @Bean
@ConditionalOnMissingBean // @ConditionalOnMissingBean
public ProfitsharingService profitsharingService(Config config) { // public ProfitsharingService profitsharingService(Config config) {
return new ProfitsharingService.Builder().config(config).build(); // return new ProfitsharingService.Builder().config(config).build();
} // }
//
@Bean // @Bean
@ConditionalOnMissingBean // @ConditionalOnMissingBean
@ConditionalOnBean(WechatConfigService.class) // @ConditionalOnBean(WechatConfigService.class)
public SettleInfo settleInfo(WechatConfigService configService) { // public SettleInfo settleInfo(WechatConfigService configService) {
WechatConfig config = configService.getConfig("PAY", getCurrentTenantId()); // WechatConfig config = configService.getConfig("PAY", getCurrentTenantId());
SettleInfo settleInfo = new SettleInfo(); // SettleInfo settleInfo = new SettleInfo();
settleInfo.setProfitSharing(config.getProfitSharingEnabled()); // settleInfo.setProfitSharing(config.getProfitSharingEnabled());
return settleInfo; // return settleInfo;
} // }
//
@Bean // @Bean
@ConditionalOnMissingBean // @ConditionalOnMissingBean
@ConditionalOnBean(WechatConfigService.class) // @ConditionalOnBean(WechatConfigService.class)
public Executor profitSharingExecutor(WechatConfigService configService) { // public Executor profitSharingExecutor(WechatConfigService configService) {
log.info("profitSharingExecutor被加载,tenantId:{}", getCurrentTenantId()); // log.info("profitSharingExecutor被加载,tenantId:{}", getCurrentTenantId());
WechatConfig config = configService.getConfig("PAY", getCurrentTenantId()); // WechatConfig config = configService.getConfig("PAY", getCurrentTenantId());
if (!config.getAsyncEnabled()) { // if (!config.getAsyncEnabled()) {
return null; // return null;
} // }
//
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); // ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(config.getAsyncPoolSize()); // executor.setCorePoolSize(config.getAsyncPoolSize());
executor.setMaxPoolSize(config.getAsyncPoolSize()); // executor.setMaxPoolSize(config.getAsyncPoolSize());
executor.setQueueCapacity(100); // executor.setQueueCapacity(100);
executor.setThreadNamePrefix("profit-sharing-"); // executor.setThreadNamePrefix("profit-sharing-");
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); // executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
executor.initialize(); // executor.initialize();
return executor; // return executor;
} // }
/** // /**
* 获取当前商户ID // * 获取当前商户ID
* 这里需要根据实际业务场景实现,可以从ThreadLocal、请求上下文等获取 // * 这里需要根据实际业务场景实现,可以从ThreadLocal、请求上下文等获取
*/ // */
private String getCurrentTenantId() { // private String getCurrentTenantId() {
// 获取当前租户的逻辑 // // 获取当前租户的逻辑
return TenantContextHolder.getTenant(); // return TenantContextHolder.getTenant();
} // }
} //}
@@ -1,42 +1,42 @@
package com.zlt.wechat.config; //package com.zlt.wechat.config;
//
import com.central.wechat.wechat.entity.WechatConfig; //import com.central.wechat.wechat.entity.WechatConfig;
import com.central.wechat.wechat.feign.PrivateKeyService; //import com.central.wechat.wechat.feign.PrivateKeyService;
import com.central.wechat.wechat.feign.WechatConfigService; //import com.central.wechat.wechat.feign.WechatConfigService;
import com.wechat.pay.java.core.Config; //import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.RSAAutoCertificateConfig; //import com.wechat.pay.java.core.RSAAutoCertificateConfig;
import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension; //import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
import lombok.extern.slf4j.Slf4j; //import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean; //import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; //import org.springframework.stereotype.Component;
//
@Slf4j //@Slf4j
@Configuration //@Component
public class WxPayConfigFactory { //public class WxPayConfigFactory {
private final WechatConfigService configService; // private final WechatConfigService configService;
private final PrivateKeyService privateKeyService; // private final PrivateKeyService privateKeyService;
//
public WxPayConfigFactory(WechatConfigService configService, PrivateKeyService privateKeyService) { // public WxPayConfigFactory(WechatConfigService configService, PrivateKeyService privateKeyService) {
this.configService = configService; // this.configService = configService;
this.privateKeyService = privateKeyService; // this.privateKeyService = privateKeyService;
} // }
//
@Bean // @Bean
public Config createConfig(String tenantId) { // public Config createConfig(String tenantId) {
log.info("创建微信支付配置,tenantId:{}", tenantId); // log.info("创建微信支付配置,tenantId:{}", tenantId);
WechatConfig config = configService.getConfig("PAY", tenantId); // WechatConfig config = configService.getConfig("PAY", tenantId);
String privateKey = privateKeyService.getPrivateKey(tenantId, "PAY"); // String privateKey = privateKeyService.getPrivateKey(tenantId, "PAY");
return new RSAAutoCertificateConfig.Builder() // return new RSAAutoCertificateConfig.Builder()
.merchantId(config.getMerchantId()) // .merchantId(config.getMerchantId())
.privateKey(privateKey) // .privateKey(privateKey)
.merchantSerialNumber(config.getMchSerialNo()) // .merchantSerialNumber(config.getMchSerialNo())
.apiV3Key(config.getApiV3Key()) // .apiV3Key(config.getApiV3Key())
.build(); // .build();
} // }
//
@Bean // @Bean
public JsapiServiceExtension createJsapiService(String tenantId) { // public JsapiServiceExtension createJsapiService(String tenantId) {
Config config = createConfig(tenantId); // Config config = createConfig(tenantId);
return new JsapiServiceExtension.Builder().config(config).build(); // return new JsapiServiceExtension.Builder().config(config).build();
} // }
} //}