mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-12-21 11:00:00 +08:00
🆕 #3360 【小程序】增加支持多小程序账号的spring-boot-starter组件
This commit is contained in:
@@ -61,7 +61,7 @@
|
||||
4. 使用样例
|
||||
|
||||
```java
|
||||
import com.binarywang.spring.starter.wxjava.mp.service.WxMpMultiServices;
|
||||
import com.binarywang.spring.starter.wxjava.mp.service.WxMaMultiServices;
|
||||
import me.chanjar.weixin.mp.api.WxMpService;
|
||||
import me.chanjar.weixin.mp.api.WxMpUserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
@@ -31,8 +31,8 @@ import java.util.stream.Collectors;
|
||||
@Slf4j
|
||||
public abstract class AbstractWxMpConfiguration {
|
||||
|
||||
protected WxMpMultiServices wxMpMultiServices(WxMpMultiProperties wxCpMultiProperties) {
|
||||
Map<String, WxMpSingleProperties> appsMap = wxCpMultiProperties.getApps();
|
||||
protected WxMpMultiServices wxMpMultiServices(WxMpMultiProperties wxMpMultiProperties) {
|
||||
Map<String, WxMpSingleProperties> appsMap = wxMpMultiProperties.getApps();
|
||||
if (appsMap == null || appsMap.isEmpty()) {
|
||||
log.warn("微信公众号应用参数未配置,通过 WxMpMultiServices#getWxMpService(\"tenantId\")获取实例将返回空");
|
||||
return new WxMpMultiServicesImpl();
|
||||
@@ -59,12 +59,12 @@ public abstract class AbstractWxMpConfiguration {
|
||||
for (Map.Entry<String, WxMpSingleProperties> entry : entries) {
|
||||
String tenantId = entry.getKey();
|
||||
WxMpSingleProperties wxMpSingleProperties = entry.getValue();
|
||||
WxMpDefaultConfigImpl storage = this.wxMpConfigStorage(wxCpMultiProperties);
|
||||
WxMpDefaultConfigImpl storage = this.wxMpConfigStorage(wxMpMultiProperties);
|
||||
this.configApp(storage, wxMpSingleProperties);
|
||||
this.configHttp(storage, wxCpMultiProperties.getConfigStorage());
|
||||
this.configHost(storage, wxCpMultiProperties.getHosts());
|
||||
WxMpService wxCpService = this.wxMpService(storage, wxCpMultiProperties);
|
||||
services.addWxMpService(tenantId, wxCpService);
|
||||
this.configHttp(storage, wxMpMultiProperties.getConfigStorage());
|
||||
this.configHost(storage, wxMpMultiProperties.getHosts());
|
||||
WxMpService wxMpService = this.wxMpService(storage, wxMpMultiProperties);
|
||||
services.addWxMpService(tenantId, wxMpService);
|
||||
}
|
||||
return services;
|
||||
}
|
||||
|
||||
@@ -27,32 +27,32 @@ import redis.clients.jedis.JedisPoolConfig;
|
||||
)
|
||||
@RequiredArgsConstructor
|
||||
public class WxMpInJedisConfiguration extends AbstractWxMpConfiguration {
|
||||
private final WxMpMultiProperties wxCpMultiProperties;
|
||||
private final WxMpMultiProperties wxMpMultiProperties;
|
||||
private final ApplicationContext applicationContext;
|
||||
|
||||
@Bean
|
||||
public WxMpMultiServices wxMpMultiServices() {
|
||||
return this.wxMpMultiServices(wxCpMultiProperties);
|
||||
return this.wxMpMultiServices(wxMpMultiProperties);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected WxMpDefaultConfigImpl wxMpConfigStorage(WxMpMultiProperties wxCpMultiProperties) {
|
||||
return this.configRedis(wxCpMultiProperties);
|
||||
protected WxMpDefaultConfigImpl wxMpConfigStorage(WxMpMultiProperties wxMpMultiProperties) {
|
||||
return this.configRedis(wxMpMultiProperties);
|
||||
}
|
||||
|
||||
private WxMpDefaultConfigImpl configRedis(WxMpMultiProperties wxCpMultiProperties) {
|
||||
WxMpMultiRedisProperties wxCpMultiRedisProperties = wxCpMultiProperties.getConfigStorage().getRedis();
|
||||
private WxMpDefaultConfigImpl configRedis(WxMpMultiProperties wxMpMultiProperties) {
|
||||
WxMpMultiRedisProperties wxMpMultiRedisProperties = wxMpMultiProperties.getConfigStorage().getRedis();
|
||||
JedisPool jedisPool;
|
||||
if (wxCpMultiRedisProperties != null && StringUtils.isNotEmpty(wxCpMultiRedisProperties.getHost())) {
|
||||
jedisPool = getJedisPool(wxCpMultiProperties);
|
||||
if (wxMpMultiRedisProperties != null && StringUtils.isNotEmpty(wxMpMultiRedisProperties.getHost())) {
|
||||
jedisPool = getJedisPool(wxMpMultiProperties);
|
||||
} else {
|
||||
jedisPool = applicationContext.getBean(JedisPool.class);
|
||||
}
|
||||
return new WxMpRedisConfigImpl(new JedisWxRedisOps(jedisPool), wxCpMultiProperties.getConfigStorage().getKeyPrefix());
|
||||
return new WxMpRedisConfigImpl(new JedisWxRedisOps(jedisPool), wxMpMultiProperties.getConfigStorage().getKeyPrefix());
|
||||
}
|
||||
|
||||
private JedisPool getJedisPool(WxMpMultiProperties wxCpMultiProperties) {
|
||||
WxMpMultiProperties.ConfigStorage storage = wxCpMultiProperties.getConfigStorage();
|
||||
private JedisPool getJedisPool(WxMpMultiProperties wxMpMultiProperties) {
|
||||
WxMpMultiProperties.ConfigStorage storage = wxMpMultiProperties.getConfigStorage();
|
||||
WxMpMultiRedisProperties redis = storage.getRedis();
|
||||
|
||||
JedisPoolConfig config = new JedisPoolConfig();
|
||||
|
||||
@@ -21,15 +21,15 @@ import org.springframework.context.annotation.Configuration;
|
||||
)
|
||||
@RequiredArgsConstructor
|
||||
public class WxMpInMemoryConfiguration extends AbstractWxMpConfiguration {
|
||||
private final WxMpMultiProperties wxCpMultiProperties;
|
||||
private final WxMpMultiProperties wxMpMultiProperties;
|
||||
|
||||
@Bean
|
||||
public WxMpMultiServices wxCpMultiServices() {
|
||||
return this.wxMpMultiServices(wxCpMultiProperties);
|
||||
public WxMpMultiServices wxMpMultiServices() {
|
||||
return this.wxMpMultiServices(wxMpMultiProperties);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected WxMpDefaultConfigImpl wxMpConfigStorage(WxMpMultiProperties wxCpMultiProperties) {
|
||||
protected WxMpDefaultConfigImpl wxMpConfigStorage(WxMpMultiProperties wxMpMultiProperties) {
|
||||
return this.configInMemory();
|
||||
}
|
||||
|
||||
|
||||
@@ -28,32 +28,32 @@ import org.springframework.context.annotation.Configuration;
|
||||
)
|
||||
@RequiredArgsConstructor
|
||||
public class WxMpInRedissonConfiguration extends AbstractWxMpConfiguration {
|
||||
private final WxMpMultiProperties wxCpMultiProperties;
|
||||
private final WxMpMultiProperties wxMpMultiProperties;
|
||||
private final ApplicationContext applicationContext;
|
||||
|
||||
@Bean
|
||||
public WxMpMultiServices wxMpMultiServices() {
|
||||
return this.wxMpMultiServices(wxCpMultiProperties);
|
||||
return this.wxMpMultiServices(wxMpMultiProperties);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected WxMpDefaultConfigImpl wxMpConfigStorage(WxMpMultiProperties wxCpMultiProperties) {
|
||||
return this.configRedisson(wxCpMultiProperties);
|
||||
protected WxMpDefaultConfigImpl wxMpConfigStorage(WxMpMultiProperties wxMpMultiProperties) {
|
||||
return this.configRedisson(wxMpMultiProperties);
|
||||
}
|
||||
|
||||
private WxMpDefaultConfigImpl configRedisson(WxMpMultiProperties wxCpMultiProperties) {
|
||||
WxMpMultiRedisProperties redisProperties = wxCpMultiProperties.getConfigStorage().getRedis();
|
||||
private WxMpDefaultConfigImpl configRedisson(WxMpMultiProperties wxMpMultiProperties) {
|
||||
WxMpMultiRedisProperties redisProperties = wxMpMultiProperties.getConfigStorage().getRedis();
|
||||
RedissonClient redissonClient;
|
||||
if (redisProperties != null && StringUtils.isNotEmpty(redisProperties.getHost())) {
|
||||
redissonClient = getRedissonClient(wxCpMultiProperties);
|
||||
redissonClient = getRedissonClient(wxMpMultiProperties);
|
||||
} else {
|
||||
redissonClient = applicationContext.getBean(RedissonClient.class);
|
||||
}
|
||||
return new WxMpRedissonConfigImpl(redissonClient, wxCpMultiProperties.getConfigStorage().getKeyPrefix());
|
||||
return new WxMpRedissonConfigImpl(redissonClient, wxMpMultiProperties.getConfigStorage().getKeyPrefix());
|
||||
}
|
||||
|
||||
private RedissonClient getRedissonClient(WxMpMultiProperties wxCpMultiProperties) {
|
||||
WxMpMultiProperties.ConfigStorage storage = wxCpMultiProperties.getConfigStorage();
|
||||
private RedissonClient getRedissonClient(WxMpMultiProperties wxMpMultiProperties) {
|
||||
WxMpMultiProperties.ConfigStorage storage = wxMpMultiProperties.getConfigStorage();
|
||||
WxMpMultiRedisProperties redis = storage.getRedis();
|
||||
|
||||
Config config = new Config();
|
||||
|
||||
Reference in New Issue
Block a user