🆕 添加 solon-plugins 下的两个新模块
This commit is contained in:
@@ -0,0 +1,140 @@
|
||||
package com.binarywang.solon.wxjava.channel.configuration.services;
|
||||
|
||||
import com.binarywang.solon.wxjava.channel.enums.HttpClientType;
|
||||
import com.binarywang.solon.wxjava.channel.properties.WxChannelMultiProperties;
|
||||
import com.binarywang.solon.wxjava.channel.properties.WxChannelSingleProperties;
|
||||
import com.binarywang.solon.wxjava.channel.service.WxChannelMultiServices;
|
||||
import com.binarywang.solon.wxjava.channel.service.WxChannelMultiServicesImpl;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import me.chanjar.weixin.channel.api.WxChannelService;
|
||||
import me.chanjar.weixin.channel.api.impl.WxChannelServiceHttpClientImpl;
|
||||
import me.chanjar.weixin.channel.api.impl.WxChannelServiceImpl;
|
||||
import me.chanjar.weixin.channel.config.WxChannelConfig;
|
||||
import me.chanjar.weixin.channel.config.impl.WxChannelDefaultConfigImpl;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* WxChannelConfigStorage 抽象配置类
|
||||
*
|
||||
* @author <a href="https://github.com/Winnie-by996">Winnie</a> 2024/9/13
|
||||
* @author noear
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public abstract class AbstractWxChannelConfiguration {
|
||||
protected WxChannelMultiServices wxChannelMultiServices(WxChannelMultiProperties wxChannelMultiProperties) {
|
||||
Map<String, WxChannelSingleProperties> appsMap = wxChannelMultiProperties.getApps();
|
||||
if (appsMap == null || appsMap.isEmpty()) {
|
||||
log.warn("微信视频号应用参数未配置,通过 WxChannelMultiServices#getWxChannelService(\"tenantId\")获取实例将返回空");
|
||||
return new WxChannelMultiServicesImpl();
|
||||
}
|
||||
/**
|
||||
* 校验 appId 是否唯一,避免使用 redis 缓存 token、ticket 时错乱。
|
||||
*
|
||||
* 查看 {@link me.chanjar.weixin.channel.config.impl.WxChannelRedisConfigImpl#setAppid(String)}
|
||||
*/
|
||||
Collection<WxChannelSingleProperties> apps = appsMap.values();
|
||||
if (apps.size() > 1) {
|
||||
// 校验 appId 是否唯一
|
||||
boolean multi = apps.stream()
|
||||
// 没有 appId,如果不判断是否为空,这里会报 NPE 异常
|
||||
.collect(Collectors.groupingBy(c -> c.getAppId() == null ? 0 : c.getAppId(), Collectors.counting()))
|
||||
.entrySet().stream().anyMatch(e -> e.getValue() > 1);
|
||||
if (multi) {
|
||||
throw new RuntimeException("请确保微信视频号配置 appId 的唯一性");
|
||||
}
|
||||
}
|
||||
WxChannelMultiServicesImpl services = new WxChannelMultiServicesImpl();
|
||||
|
||||
Set<Map.Entry<String, WxChannelSingleProperties>> entries = appsMap.entrySet();
|
||||
for (Map.Entry<String, WxChannelSingleProperties> entry : entries) {
|
||||
String tenantId = entry.getKey();
|
||||
WxChannelSingleProperties wxChannelSingleProperties = entry.getValue();
|
||||
WxChannelDefaultConfigImpl storage = this.wxChannelConfigStorage(wxChannelMultiProperties);
|
||||
this.configApp(storage, wxChannelSingleProperties);
|
||||
this.configHttp(storage, wxChannelMultiProperties.getConfigStorage());
|
||||
WxChannelService wxChannelService = this.wxChannelService(storage, wxChannelMultiProperties, wxChannelSingleProperties.isUseStableAccessToken());
|
||||
services.addWxChannelService(tenantId, wxChannelService);
|
||||
}
|
||||
return services;
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置 WxChannelDefaultConfigImpl
|
||||
*
|
||||
* @param wxChannelMultiProperties 参数
|
||||
* @return WxChannelDefaultConfigImpl
|
||||
*/
|
||||
protected abstract WxChannelDefaultConfigImpl wxChannelConfigStorage(WxChannelMultiProperties wxChannelMultiProperties);
|
||||
|
||||
public WxChannelService wxChannelService(WxChannelConfig wxChannelConfig, WxChannelMultiProperties wxChannelMultiProperties, boolean useStableAccessToken) {
|
||||
WxChannelMultiProperties.ConfigStorage storage = wxChannelMultiProperties.getConfigStorage();
|
||||
HttpClientType httpClientType = storage.getHttpClientType();
|
||||
WxChannelService wxChannelService;
|
||||
switch (httpClientType) {
|
||||
// case OK_HTTP:
|
||||
// wxChannelService = new WxChannelServiceOkHttpImpl(false, false);
|
||||
// break;
|
||||
case HTTP_CLIENT:
|
||||
wxChannelService = new WxChannelServiceHttpClientImpl(useStableAccessToken, false);
|
||||
break;
|
||||
default:
|
||||
wxChannelService = new WxChannelServiceImpl();
|
||||
break;
|
||||
}
|
||||
|
||||
wxChannelService.setConfig(wxChannelConfig);
|
||||
int maxRetryTimes = storage.getMaxRetryTimes();
|
||||
if (maxRetryTimes < 0) {
|
||||
maxRetryTimes = 0;
|
||||
}
|
||||
int retrySleepMillis = storage.getRetrySleepMillis();
|
||||
if (retrySleepMillis < 0) {
|
||||
retrySleepMillis = 1000;
|
||||
}
|
||||
wxChannelService.setRetrySleepMillis(retrySleepMillis);
|
||||
wxChannelService.setMaxRetryTimes(maxRetryTimes);
|
||||
return wxChannelService;
|
||||
}
|
||||
|
||||
private void configApp(WxChannelDefaultConfigImpl config, WxChannelSingleProperties wxChannelSingleProperties) {
|
||||
String appId = wxChannelSingleProperties.getAppId();
|
||||
String appSecret = wxChannelSingleProperties.getSecret();
|
||||
String token = wxChannelSingleProperties.getToken();
|
||||
String aesKey = wxChannelSingleProperties.getAesKey();
|
||||
|
||||
config.setAppid(appId);
|
||||
config.setSecret(appSecret);
|
||||
if (StringUtils.isNotBlank(token)) {
|
||||
config.setToken(token);
|
||||
}
|
||||
if (StringUtils.isNotBlank(aesKey)) {
|
||||
config.setAesKey(aesKey);
|
||||
}
|
||||
}
|
||||
|
||||
private void configHttp(WxChannelDefaultConfigImpl config, WxChannelMultiProperties.ConfigStorage storage) {
|
||||
String httpProxyHost = storage.getHttpProxyHost();
|
||||
Integer httpProxyPort = storage.getHttpProxyPort();
|
||||
String httpProxyUsername = storage.getHttpProxyUsername();
|
||||
String httpProxyPassword = storage.getHttpProxyPassword();
|
||||
if (StringUtils.isNotBlank(httpProxyHost)) {
|
||||
config.setHttpProxyHost(httpProxyHost);
|
||||
if (httpProxyPort != null) {
|
||||
config.setHttpProxyPort(httpProxyPort);
|
||||
}
|
||||
if (StringUtils.isNotBlank(httpProxyUsername)) {
|
||||
config.setHttpProxyUsername(httpProxyUsername);
|
||||
}
|
||||
if (StringUtils.isNotBlank(httpProxyPassword)) {
|
||||
config.setHttpProxyPassword(httpProxyPassword);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package com.binarywang.solon.wxjava.channel.configuration.services;
|
||||
|
||||
import com.binarywang.solon.wxjava.channel.properties.WxChannelMultiProperties;
|
||||
import com.binarywang.solon.wxjava.channel.properties.WxChannelMultiRedisProperties;
|
||||
import com.binarywang.solon.wxjava.channel.service.WxChannelMultiServices;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import me.chanjar.weixin.channel.config.impl.WxChannelDefaultConfigImpl;
|
||||
import me.chanjar.weixin.channel.config.impl.WxChannelRedisConfigImpl;
|
||||
import me.chanjar.weixin.common.redis.JedisWxRedisOps;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.noear.solon.annotation.Bean;
|
||||
import org.noear.solon.annotation.Condition;
|
||||
import org.noear.solon.annotation.Configuration;
|
||||
import org.noear.solon.core.AppContext;
|
||||
import redis.clients.jedis.JedisPool;
|
||||
import redis.clients.jedis.JedisPoolConfig;
|
||||
|
||||
/**
|
||||
* 自动装配基于 jedis 策略配置
|
||||
*
|
||||
* @author <a href="https://github.com/Winnie-by996">Winnie</a> 2024/9/13
|
||||
* @author noear
|
||||
*/
|
||||
@Configuration
|
||||
@Condition(
|
||||
onProperty = "${"+WxChannelMultiProperties.PREFIX + ".configStorage.type} = jedis",
|
||||
onClass = JedisPool.class
|
||||
)
|
||||
@RequiredArgsConstructor
|
||||
public class WxChannelInJedisConfiguration extends AbstractWxChannelConfiguration {
|
||||
private final WxChannelMultiProperties wxChannelMultiProperties;
|
||||
private final AppContext applicationContext;
|
||||
|
||||
@Bean
|
||||
public WxChannelMultiServices wxChannelMultiServices() {
|
||||
return this.wxChannelMultiServices(wxChannelMultiProperties);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected WxChannelDefaultConfigImpl wxChannelConfigStorage(WxChannelMultiProperties wxChannelMultiProperties) {
|
||||
return this.configRedis(wxChannelMultiProperties);
|
||||
}
|
||||
|
||||
private WxChannelDefaultConfigImpl configRedis(WxChannelMultiProperties wxChannelMultiProperties) {
|
||||
WxChannelMultiRedisProperties wxChannelMultiRedisProperties = wxChannelMultiProperties.getConfigStorage().getRedis();
|
||||
JedisPool jedisPool;
|
||||
if (wxChannelMultiRedisProperties != null && StringUtils.isNotEmpty(wxChannelMultiRedisProperties.getHost())) {
|
||||
jedisPool = getJedisPool(wxChannelMultiProperties);
|
||||
} else {
|
||||
jedisPool = applicationContext.getBean(JedisPool.class);
|
||||
}
|
||||
return new WxChannelRedisConfigImpl(new JedisWxRedisOps(jedisPool), wxChannelMultiProperties.getConfigStorage().getKeyPrefix());
|
||||
}
|
||||
|
||||
private JedisPool getJedisPool(WxChannelMultiProperties wxChannelMultiProperties) {
|
||||
WxChannelMultiProperties.ConfigStorage storage = wxChannelMultiProperties.getConfigStorage();
|
||||
WxChannelMultiRedisProperties redis = storage.getRedis();
|
||||
|
||||
JedisPoolConfig config = new JedisPoolConfig();
|
||||
if (redis.getMaxActive() != null) {
|
||||
config.setMaxTotal(redis.getMaxActive());
|
||||
}
|
||||
if (redis.getMaxIdle() != null) {
|
||||
config.setMaxIdle(redis.getMaxIdle());
|
||||
}
|
||||
if (redis.getMaxWaitMillis() != null) {
|
||||
config.setMaxWaitMillis(redis.getMaxWaitMillis());
|
||||
}
|
||||
if (redis.getMinIdle() != null) {
|
||||
config.setMinIdle(redis.getMinIdle());
|
||||
}
|
||||
config.setTestOnBorrow(true);
|
||||
config.setTestWhileIdle(true);
|
||||
|
||||
return new JedisPool(config, redis.getHost(), redis.getPort(), redis.getTimeout(), redis.getPassword(), redis.getDatabase());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.binarywang.solon.wxjava.channel.configuration.services;
|
||||
|
||||
import com.binarywang.solon.wxjava.channel.properties.WxChannelMultiProperties;
|
||||
import com.binarywang.solon.wxjava.channel.service.WxChannelMultiServices;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import me.chanjar.weixin.channel.config.impl.WxChannelDefaultConfigImpl;
|
||||
import org.noear.solon.annotation.Bean;
|
||||
import org.noear.solon.annotation.Condition;
|
||||
import org.noear.solon.annotation.Configuration;
|
||||
import redis.clients.jedis.JedisPool;
|
||||
|
||||
/**
|
||||
* 自动装配基于内存策略配置
|
||||
*
|
||||
* @author <a href="https://github.com/Winnie-by996">Winnie</a> 2024/9/13
|
||||
* @author noear
|
||||
*/
|
||||
@Configuration
|
||||
@Condition(
|
||||
onProperty = "${"+WxChannelMultiProperties.PREFIX + ".configStorage.type} = memory",
|
||||
onClass = JedisPool.class
|
||||
)
|
||||
@RequiredArgsConstructor
|
||||
public class WxChannelInMemoryConfiguration extends AbstractWxChannelConfiguration {
|
||||
private final WxChannelMultiProperties wxChannelMultiProperties;
|
||||
|
||||
@Bean
|
||||
public WxChannelMultiServices wxChannelMultiServices() {
|
||||
return this.wxChannelMultiServices(wxChannelMultiProperties);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected WxChannelDefaultConfigImpl wxChannelConfigStorage(WxChannelMultiProperties wxChannelMultiProperties) {
|
||||
return this.configInMemory();
|
||||
}
|
||||
|
||||
private WxChannelDefaultConfigImpl configInMemory() {
|
||||
return new WxChannelDefaultConfigImpl();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.binarywang.solon.wxjava.channel.configuration.services;
|
||||
|
||||
import com.binarywang.solon.wxjava.channel.properties.WxChannelMultiProperties;
|
||||
import com.binarywang.solon.wxjava.channel.properties.WxChannelMultiRedisProperties;
|
||||
import com.binarywang.solon.wxjava.channel.service.WxChannelMultiServices;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import me.chanjar.weixin.channel.config.impl.WxChannelDefaultConfigImpl;
|
||||
import me.chanjar.weixin.channel.config.impl.WxChannelRedissonConfigImpl;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.noear.solon.annotation.Bean;
|
||||
import org.noear.solon.annotation.Condition;
|
||||
import org.noear.solon.annotation.Configuration;
|
||||
import org.noear.solon.core.AppContext;
|
||||
import org.redisson.Redisson;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.redisson.config.Config;
|
||||
import org.redisson.config.TransportMode;
|
||||
|
||||
/**
|
||||
* 自动装配基于 redisson 策略配置
|
||||
*
|
||||
* @author <a href="https://github.com/Winnie-by996">Winnie</a> 2024/9/13
|
||||
* @author noear
|
||||
*/
|
||||
@Configuration
|
||||
@Condition(
|
||||
onProperty = "${"+WxChannelMultiProperties.PREFIX + ".configStorage.type} = redisson",
|
||||
onClass = Redisson.class
|
||||
)
|
||||
@RequiredArgsConstructor
|
||||
public class WxChannelInRedissonConfiguration extends AbstractWxChannelConfiguration {
|
||||
private final WxChannelMultiProperties wxChannelMultiProperties;
|
||||
private final AppContext applicationContext;
|
||||
|
||||
@Bean
|
||||
public WxChannelMultiServices wxChannelMultiServices() {
|
||||
return this.wxChannelMultiServices(wxChannelMultiProperties);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected WxChannelDefaultConfigImpl wxChannelConfigStorage(WxChannelMultiProperties wxChannelMultiProperties) {
|
||||
return this.configRedisson(wxChannelMultiProperties);
|
||||
}
|
||||
|
||||
private WxChannelDefaultConfigImpl configRedisson(WxChannelMultiProperties wxChannelMultiProperties) {
|
||||
WxChannelMultiRedisProperties redisProperties = wxChannelMultiProperties.getConfigStorage().getRedis();
|
||||
RedissonClient redissonClient;
|
||||
if (redisProperties != null && StringUtils.isNotEmpty(redisProperties.getHost())) {
|
||||
redissonClient = getRedissonClient(wxChannelMultiProperties);
|
||||
} else {
|
||||
redissonClient = applicationContext.getBean(RedissonClient.class);
|
||||
}
|
||||
return new WxChannelRedissonConfigImpl(redissonClient, wxChannelMultiProperties.getConfigStorage().getKeyPrefix());
|
||||
}
|
||||
|
||||
private RedissonClient getRedissonClient(WxChannelMultiProperties wxChannelMultiProperties) {
|
||||
WxChannelMultiProperties.ConfigStorage storage = wxChannelMultiProperties.getConfigStorage();
|
||||
WxChannelMultiRedisProperties redis = storage.getRedis();
|
||||
|
||||
Config config = new Config();
|
||||
config.useSingleServer().setAddress("redis://" + redis.getHost() + ":" + redis.getPort()).setDatabase(redis.getDatabase()).setPassword(redis.getPassword());
|
||||
config.setTransportMode(TransportMode.NIO);
|
||||
return Redisson.create(config);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.binarywang.solon.wxjava.channel.enums;
|
||||
|
||||
/**
|
||||
* httpclient类型
|
||||
*
|
||||
* @author <a href="https://github.com/Winnie-by996">Winnie</a>
|
||||
* @date 2024/9/13
|
||||
*/
|
||||
public enum HttpClientType {
|
||||
/**
|
||||
* HttpClient
|
||||
*/
|
||||
HTTP_CLIENT,
|
||||
// WxChannelServiceOkHttpImpl 实现经测试无法正常完成业务固暂不支持OK_HTTP方式
|
||||
// /**
|
||||
// * OkHttp.
|
||||
// */
|
||||
// OK_HTTP,
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.binarywang.solon.wxjava.channel.enums;
|
||||
|
||||
/**
|
||||
* storage类型
|
||||
*
|
||||
* @author <a href="https://github.com/Winnie-by996">Winnie</a>
|
||||
* @date 2024/9/13
|
||||
*/
|
||||
public enum StorageType {
|
||||
/**
|
||||
* 内存
|
||||
*/
|
||||
MEMORY,
|
||||
/**
|
||||
* redis(JedisClient)
|
||||
*/
|
||||
JEDIS,
|
||||
/**
|
||||
* redis(Redisson)
|
||||
*/
|
||||
REDISSON,
|
||||
/**
|
||||
* redis(RedisTemplate)
|
||||
*/
|
||||
REDIS_TEMPLATE
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.binarywang.solon.wxjava.channel.integration;
|
||||
|
||||
import com.binarywang.solon.wxjava.channel.configuration.services.WxChannelInJedisConfiguration;
|
||||
import com.binarywang.solon.wxjava.channel.configuration.services.WxChannelInMemoryConfiguration;
|
||||
import com.binarywang.solon.wxjava.channel.configuration.services.WxChannelInRedissonConfiguration;
|
||||
import com.binarywang.solon.wxjava.channel.properties.WxChannelMultiProperties;
|
||||
import org.noear.solon.core.AppContext;
|
||||
import org.noear.solon.core.Plugin;
|
||||
|
||||
/**
|
||||
* 微信视频号自动注册
|
||||
*
|
||||
* @author <a href="https://github.com/Winnie-by996">Winnie</a> 2024/9/13
|
||||
* @author noear 2024/10/9 created
|
||||
*/
|
||||
public class WxChannelMultiPluginImpl implements Plugin {
|
||||
@Override
|
||||
public void start(AppContext context) throws Throwable {
|
||||
context.beanMake(WxChannelMultiProperties.class);
|
||||
|
||||
context.beanMake(WxChannelInJedisConfiguration.class);
|
||||
context.beanMake(WxChannelInMemoryConfiguration.class);
|
||||
context.beanMake(WxChannelInRedissonConfiguration.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package com.binarywang.solon.wxjava.channel.properties;
|
||||
|
||||
import com.binarywang.solon.wxjava.channel.enums.HttpClientType;
|
||||
import com.binarywang.solon.wxjava.channel.enums.StorageType;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.noear.solon.annotation.Configuration;
|
||||
import org.noear.solon.annotation.Inject;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 微信多视频号接入相关配置属性
|
||||
*
|
||||
* @author <a href="https://github.com/Winnie-by996">Winnie</a>
|
||||
* @date 2024/9/13
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@Configuration
|
||||
@Inject("${" + WxChannelMultiProperties.PREFIX +"}")
|
||||
public class WxChannelMultiProperties implements Serializable {
|
||||
private static final long serialVersionUID = - 8361973118805546037L;
|
||||
public static final String PREFIX = "wx.channel";
|
||||
|
||||
private Map<String, WxChannelSingleProperties> apps = new HashMap<>();
|
||||
|
||||
/**
|
||||
* 存储策略
|
||||
*/
|
||||
private final ConfigStorage configStorage = new ConfigStorage();
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public static class ConfigStorage implements Serializable {
|
||||
private static final long serialVersionUID = - 5152619132544179942L;
|
||||
|
||||
/**
|
||||
* 存储类型.
|
||||
*/
|
||||
private StorageType type = StorageType.MEMORY;
|
||||
|
||||
/**
|
||||
* 指定key前缀.
|
||||
*/
|
||||
private String keyPrefix = "wx:channel:multi";
|
||||
|
||||
/**
|
||||
* redis连接配置.
|
||||
*/
|
||||
private final WxChannelMultiRedisProperties redis = new WxChannelMultiRedisProperties();
|
||||
|
||||
/**
|
||||
* http客户端类型.
|
||||
*/
|
||||
private HttpClientType httpClientType = HttpClientType.HTTP_CLIENT;
|
||||
|
||||
/**
|
||||
* http代理主机.
|
||||
*/
|
||||
private String httpProxyHost;
|
||||
|
||||
/**
|
||||
* http代理端口.
|
||||
*/
|
||||
private Integer httpProxyPort;
|
||||
|
||||
/**
|
||||
* http代理用户名.
|
||||
*/
|
||||
private String httpProxyUsername;
|
||||
|
||||
/**
|
||||
* http代理密码.
|
||||
*/
|
||||
private String httpProxyPassword;
|
||||
|
||||
/**
|
||||
* http 请求最大重试次数
|
||||
*
|
||||
* <p>{@link me.chanjar.weixin.channel.api.WxChannelService#setMaxRetryTimes(int)}</p>
|
||||
* <p>{@link me.chanjar.weixin.channel.api.impl.BaseWxChannelServiceImpl#setMaxRetryTimes(int)}</p>
|
||||
*/
|
||||
private int maxRetryTimes = 5;
|
||||
|
||||
/**
|
||||
* http 请求重试间隔
|
||||
*
|
||||
* <p>{@link me.chanjar.weixin.channel.api.WxChannelService#setRetrySleepMillis(int)}</p>
|
||||
* <p>{@link me.chanjar.weixin.channel.api.impl.BaseWxChannelServiceImpl#setRetrySleepMillis(int)}</p>
|
||||
*/
|
||||
private int retrySleepMillis = 1000;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.binarywang.solon.wxjava.channel.properties;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Redis配置
|
||||
*
|
||||
* @author <a href="https://github.com/Winnie-by996">Winnie</a>
|
||||
* @date 2024/9/13
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class WxChannelMultiRedisProperties implements Serializable {
|
||||
private static final long serialVersionUID = 9061055444734277357L;
|
||||
|
||||
/**
|
||||
* 主机地址.
|
||||
*/
|
||||
private String host = "127.0.0.1";
|
||||
|
||||
/**
|
||||
* 端口号.
|
||||
*/
|
||||
private int port = 6379;
|
||||
|
||||
/**
|
||||
* 密码.
|
||||
*/
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 超时.
|
||||
*/
|
||||
private int timeout = 2000;
|
||||
|
||||
/**
|
||||
* 数据库.
|
||||
*/
|
||||
private int database = 0;
|
||||
|
||||
/**
|
||||
* 最大活动连接数
|
||||
*/
|
||||
private Integer maxActive;
|
||||
|
||||
/**
|
||||
* 最大空闲连接数
|
||||
*/
|
||||
private Integer maxIdle;
|
||||
|
||||
/**
|
||||
* 最小空闲连接数
|
||||
*/
|
||||
private Integer minIdle;
|
||||
|
||||
/**
|
||||
* 最大等待时间
|
||||
*/
|
||||
private Integer maxWaitMillis;
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.binarywang.solon.wxjava.channel.properties;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 微信视频号相关配置属性
|
||||
*
|
||||
* @author <a href="https://github.com/Winnie-by996">Winnie</a>
|
||||
* @date 2024/9/13
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class WxChannelSingleProperties implements Serializable {
|
||||
private static final long serialVersionUID = 5306630351265124825L;
|
||||
|
||||
/**
|
||||
* 设置微信视频号的 appid.
|
||||
*/
|
||||
private String appId;
|
||||
|
||||
/**
|
||||
* 设置微信视频号的 secret.
|
||||
*/
|
||||
private String secret;
|
||||
|
||||
/**
|
||||
* 设置微信视频号的 token.
|
||||
*/
|
||||
private String token;
|
||||
|
||||
/**
|
||||
* 设置微信视频号的 EncodingAESKey.
|
||||
*/
|
||||
private String aesKey;
|
||||
|
||||
/**
|
||||
* 是否使用稳定版 Access Token
|
||||
*/
|
||||
private boolean useStableAccessToken = false;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.binarywang.solon.wxjava.channel.service;
|
||||
|
||||
import me.chanjar.weixin.channel.api.WxChannelService;
|
||||
|
||||
/**
|
||||
* 视频号 {@link WxChannelService} 所有实例存放类.
|
||||
*
|
||||
* @author <a href="https://github.com/Winnie-by996">Winnie</a>
|
||||
* @date 2024/9/13
|
||||
*/
|
||||
public interface WxChannelMultiServices {
|
||||
/**
|
||||
* 通过租户 Id 获取 WxChannelService
|
||||
*
|
||||
* @param tenantId 租户 Id
|
||||
* @return WxChannelService
|
||||
*/
|
||||
WxChannelService getWxChannelService(String tenantId);
|
||||
|
||||
/**
|
||||
* 根据租户 Id,从列表中移除一个 WxChannelService 实例
|
||||
*
|
||||
* @param tenantId 租户 Id
|
||||
*/
|
||||
void removeWxChannelService(String tenantId);
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.binarywang.solon.wxjava.channel.service;
|
||||
|
||||
import me.chanjar.weixin.channel.api.WxChannelService;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* 视频号 {@link WxChannelMultiServices} 实现
|
||||
*
|
||||
* @author <a href="https://github.com/Winnie-by996">Winnie</a>
|
||||
* @date 2024/9/13
|
||||
*/
|
||||
public class WxChannelMultiServicesImpl implements WxChannelMultiServices {
|
||||
private final Map<String, WxChannelService> services = new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
public WxChannelService getWxChannelService(String tenantId) {
|
||||
return this.services.get(tenantId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据租户 Id,添加一个 WxChannelService 到列表
|
||||
*
|
||||
* @param tenantId 租户 Id
|
||||
* @param wxChannelService WxChannelService 实例
|
||||
*/
|
||||
public void addWxChannelService(String tenantId, WxChannelService wxChannelService) {
|
||||
this.services.put(tenantId, wxChannelService);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeWxChannelService(String tenantId) {
|
||||
this.services.remove(tenantId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
solon.plugin=com.binarywang.solon.wxjava.channel.integration.WxChannelMultiPluginImpl
|
||||
solon.plugin.priority=10
|
||||
@@ -0,0 +1,15 @@
|
||||
package features.test;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.noear.solon.test.SolonTest;
|
||||
|
||||
/**
|
||||
* @author noear 2024/9/4 created
|
||||
*/
|
||||
@SolonTest
|
||||
public class LoadTest {
|
||||
@Test
|
||||
public void load(){
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
# 视频号配置
|
||||
## 应用 1 配置(必填)
|
||||
wx.channel.apps.tenantId1.app-id=appId
|
||||
wx.channel.apps.tenantId1.secret=secret
|
||||
## 选填
|
||||
wx.channel.apps.tenantId1.use-stable-access-token=false
|
||||
wx.channel.apps.tenantId1.token=
|
||||
wx.channel.apps.tenantId1.aes-key=
|
||||
## 应用 2 配置(必填)
|
||||
wx.channel.apps.tenantId2.app-id=@appId
|
||||
wx.channel.apps.tenantId2.secret=@secret
|
||||
## 选填
|
||||
wx.channel.apps.tenantId2.use-stable-access-token=false
|
||||
wx.channel.apps.tenantId2.token=
|
||||
wx.channel.apps.tenantId2.aes-key=
|
||||
|
||||
# ConfigStorage 配置(选填)
|
||||
## 配置类型: memory(默认), jedis, redisson, redis_template
|
||||
wx.channel.config-storage.type=memory
|
||||
## 相关redis前缀配置: wx:channel:multi(默认)
|
||||
wx.channel.config-storage.key-prefix=wx:channel:multi
|
||||
wx.channel.config-storage.redis.host=127.0.0.1
|
||||
wx.channel.config-storage.redis.port=6379
|
||||
wx.channel.config-storage.redis.password=123456
|
||||
|
||||
# http 客户端配置(选填)
|
||||
## # http客户端类型: http_client(默认)
|
||||
wx.channel.config-storage.http-client-type=http_client
|
||||
wx.channel.config-storage.http-proxy-host=
|
||||
wx.channel.config-storage.http-proxy-port=
|
||||
wx.channel.config-storage.http-proxy-username=
|
||||
wx.channel.config-storage.http-proxy-password=
|
||||
## 最大重试次数,默认:5 次,如果小于 0,则为 0
|
||||
wx.channel.config-storage.max-retry-times=5
|
||||
## 重试时间间隔步进,默认:1000 毫秒,如果小于 0,则为 1000
|
||||
wx.channel.config-storage.retry-sleep-millis=1000
|
||||
Reference in New Issue
Block a user