feat:微信相关功能模块抽离重构,动态获取相关配置已经登录逻辑等的完善
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-commons</artifactId>
|
||||
<version>6.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>zlt-wechat-spring-boot-starter</artifactId>
|
||||
<description>微信Spring Boot启动器</description>
|
||||
|
||||
<dependencies>
|
||||
<!-- 微信核心模块 -->
|
||||
<dependency>
|
||||
<groupId>com.zlt</groupId>
|
||||
<artifactId>zlt-wechat-common-core</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Spring Boot 相关依赖 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-autoconfigure</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
+173
@@ -0,0 +1,173 @@
|
||||
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.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 com.wechat.pay.java.service.refund.RefundService;
|
||||
import com.zlt.wechat.entity.WechatConfig;
|
||||
import com.zlt.wechat.service.WechatConfigService;
|
||||
import com.zlt.wechat.service.PrivateKeyService;
|
||||
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.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;
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(WechatProperties.class)
|
||||
public class WechatAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public WxMpService wxMpService(WechatConfigService configService) {
|
||||
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;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public WxMaService wxMaService(WechatConfigService configService) {
|
||||
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
|
||||
@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
|
||||
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();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public NotificationConfig notificationConfig(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 NotificationParser notificationParser(NotificationConfig config) {
|
||||
return new NotificationParser(config);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public ProfitsharingService profitsharingService(Config config) {
|
||||
return new ProfitsharingService.Builder().config(config).build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public SettleInfo settleInfo(WechatConfigService configService) {
|
||||
WechatConfig config = configService.getConfig("PAY", getCurrentTenantId());
|
||||
SettleInfo settleInfo = new SettleInfo();
|
||||
settleInfo.setProfitSharing(config.getProfitSharingEnabled());
|
||||
return settleInfo;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public Executor profitSharingExecutor(WechatConfigService configService) {
|
||||
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();
|
||||
}
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
com.zlt.wechat.config.WechatAutoConfiguration
|
||||
Reference in New Issue
Block a user