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