fix:支付和通知相关模块代码恢复
This commit is contained in:
+166
-166
@@ -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();
|
||||
// }
|
||||
//}
|
||||
|
||||
+42
-42
@@ -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();
|
||||
// }
|
||||
//}
|
||||
|
||||
Reference in New Issue
Block a user