🎨 #4117 【微信小店】微信小店独立模块创建
This commit is contained in:
@@ -0,0 +1,146 @@
|
||||
package com.binarywang.solon.wxjava.store.configuration.services;
|
||||
|
||||
import com.binarywang.solon.wxjava.store.enums.HttpClientType;
|
||||
import com.binarywang.solon.wxjava.store.properties.WxStoreMultiProperties;
|
||||
import com.binarywang.solon.wxjava.store.properties.WxStoreSingleProperties;
|
||||
import com.binarywang.solon.wxjava.store.service.WxStoreMultiServices;
|
||||
import com.binarywang.solon.wxjava.store.service.WxStoreMultiServicesImpl;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.binarywang.wxjava.store.api.WxStoreService;
|
||||
import com.binarywang.wxjava.store.api.impl.WxStoreServiceHttpComponentsImpl;
|
||||
import com.binarywang.wxjava.store.api.impl.WxStoreServiceHttpClientImpl;
|
||||
import com.binarywang.wxjava.store.api.impl.WxStoreServiceImpl;
|
||||
import com.binarywang.wxjava.store.config.WxStoreConfig;
|
||||
import com.binarywang.wxjava.store.config.impl.WxStoreDefaultConfigImpl;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* WxStoreConfigStorage 抽象配置类
|
||||
*
|
||||
* @author <a href="https://github.com/Winnie-by996">Winnie</a> 2024/9/13
|
||||
* @author noear
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public abstract class AbstractWxStoreConfiguration {
|
||||
protected WxStoreMultiServices wxStoreMultiServices(WxStoreMultiProperties wxStoreMultiProperties) {
|
||||
Map<String, WxStoreSingleProperties> appsMap = wxStoreMultiProperties.getApps();
|
||||
if (appsMap == null || appsMap.isEmpty()) {
|
||||
log.warn("微信小店应用参数未配置,通过 WxStoreMultiServices#getWxStoreService(\"tenantId\")获取实例将返回空");
|
||||
return new WxStoreMultiServicesImpl();
|
||||
}
|
||||
/**
|
||||
* 校验 appId 是否唯一,避免使用 redis 缓存 token、ticket 时错乱。
|
||||
*
|
||||
* 查看 {@link com.binarywang.wxjava.store.config.impl.WxStoreRedisConfigImpl#setAppid(String)}
|
||||
*/
|
||||
Collection<WxStoreSingleProperties> 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 的唯一性");
|
||||
}
|
||||
}
|
||||
WxStoreMultiServicesImpl services = new WxStoreMultiServicesImpl();
|
||||
|
||||
Set<Map.Entry<String, WxStoreSingleProperties>> entries = appsMap.entrySet();
|
||||
for (Map.Entry<String, WxStoreSingleProperties> entry : entries) {
|
||||
String tenantId = entry.getKey();
|
||||
WxStoreSingleProperties wxStoreSingleProperties = entry.getValue();
|
||||
WxStoreDefaultConfigImpl storage = this.wxStoreConfigStorage(wxStoreMultiProperties);
|
||||
this.configApp(storage, wxStoreSingleProperties);
|
||||
this.configHttp(storage, wxStoreMultiProperties.getConfigStorage());
|
||||
WxStoreService wxStoreService = this.wxStoreService(storage, wxStoreMultiProperties);
|
||||
services.addWxStoreService(tenantId, wxStoreService);
|
||||
}
|
||||
return services;
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置 WxStoreDefaultConfigImpl
|
||||
*
|
||||
* @param wxStoreMultiProperties 参数
|
||||
* @return WxStoreDefaultConfigImpl
|
||||
*/
|
||||
protected abstract WxStoreDefaultConfigImpl wxStoreConfigStorage(WxStoreMultiProperties wxStoreMultiProperties);
|
||||
|
||||
public WxStoreService wxStoreService(WxStoreConfig wxStoreConfig, WxStoreMultiProperties wxStoreMultiProperties) {
|
||||
WxStoreMultiProperties.ConfigStorage storage = wxStoreMultiProperties.getConfigStorage();
|
||||
HttpClientType httpClientType = storage.getHttpClientType();
|
||||
WxStoreService wxStoreService;
|
||||
switch (httpClientType) {
|
||||
// case OK_HTTP:
|
||||
// wxStoreService = new WxStoreServiceOkHttpImpl(false, false);
|
||||
// break;
|
||||
case HTTP_CLIENT:
|
||||
wxStoreService = new WxStoreServiceHttpClientImpl();
|
||||
break;
|
||||
case HTTP_COMPONENTS:
|
||||
wxStoreService = new WxStoreServiceHttpComponentsImpl();
|
||||
break;
|
||||
default:
|
||||
wxStoreService = new WxStoreServiceImpl();
|
||||
break;
|
||||
}
|
||||
|
||||
wxStoreService.setConfig(wxStoreConfig);
|
||||
int maxRetryTimes = storage.getMaxRetryTimes();
|
||||
if (maxRetryTimes < 0) {
|
||||
maxRetryTimes = 0;
|
||||
}
|
||||
int retrySleepMillis = storage.getRetrySleepMillis();
|
||||
if (retrySleepMillis < 0) {
|
||||
retrySleepMillis = 1000;
|
||||
}
|
||||
wxStoreService.setRetrySleepMillis(retrySleepMillis);
|
||||
wxStoreService.setMaxRetryTimes(maxRetryTimes);
|
||||
return wxStoreService;
|
||||
}
|
||||
|
||||
private void configApp(WxStoreDefaultConfigImpl config, WxStoreSingleProperties wxStoreSingleProperties) {
|
||||
String appId = wxStoreSingleProperties.getAppId();
|
||||
String appSecret = wxStoreSingleProperties.getSecret();
|
||||
String token = wxStoreSingleProperties.getToken();
|
||||
String aesKey = wxStoreSingleProperties.getAesKey();
|
||||
boolean useStableAccessToken = wxStoreSingleProperties.isUseStableAccessToken();
|
||||
|
||||
config.setAppid(appId);
|
||||
config.setSecret(appSecret);
|
||||
if (StringUtils.isNotBlank(token)) {
|
||||
config.setToken(token);
|
||||
}
|
||||
if (StringUtils.isNotBlank(aesKey)) {
|
||||
config.setAesKey(aesKey);
|
||||
}
|
||||
config.setStableAccessToken(useStableAccessToken);
|
||||
}
|
||||
|
||||
private void configHttp(WxStoreDefaultConfigImpl config, WxStoreMultiProperties.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.store.configuration.services;
|
||||
|
||||
import com.binarywang.solon.wxjava.store.properties.WxStoreMultiProperties;
|
||||
import com.binarywang.solon.wxjava.store.properties.WxStoreMultiRedisProperties;
|
||||
import com.binarywang.solon.wxjava.store.service.WxStoreMultiServices;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import com.binarywang.wxjava.store.config.impl.WxStoreDefaultConfigImpl;
|
||||
import com.binarywang.wxjava.store.config.impl.WxStoreRedisConfigImpl;
|
||||
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 = "${"+WxStoreMultiProperties.PREFIX + ".configStorage.type} = jedis",
|
||||
onClass = JedisPool.class
|
||||
)
|
||||
@RequiredArgsConstructor
|
||||
public class WxStoreInJedisConfiguration extends AbstractWxStoreConfiguration {
|
||||
private final WxStoreMultiProperties wxStoreMultiProperties;
|
||||
private final AppContext applicationContext;
|
||||
|
||||
@Bean
|
||||
public WxStoreMultiServices wxStoreMultiServices() {
|
||||
return this.wxStoreMultiServices(wxStoreMultiProperties);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected WxStoreDefaultConfigImpl wxStoreConfigStorage(WxStoreMultiProperties wxStoreMultiProperties) {
|
||||
return this.configRedis(wxStoreMultiProperties);
|
||||
}
|
||||
|
||||
private WxStoreDefaultConfigImpl configRedis(WxStoreMultiProperties wxStoreMultiProperties) {
|
||||
WxStoreMultiRedisProperties wxStoreMultiRedisProperties = wxStoreMultiProperties.getConfigStorage().getRedis();
|
||||
JedisPool jedisPool;
|
||||
if (wxStoreMultiRedisProperties != null && StringUtils.isNotEmpty(wxStoreMultiRedisProperties.getHost())) {
|
||||
jedisPool = getJedisPool(wxStoreMultiProperties);
|
||||
} else {
|
||||
jedisPool = applicationContext.getBean(JedisPool.class);
|
||||
}
|
||||
return new WxStoreRedisConfigImpl(new JedisWxRedisOps(jedisPool), wxStoreMultiProperties.getConfigStorage().getKeyPrefix());
|
||||
}
|
||||
|
||||
private JedisPool getJedisPool(WxStoreMultiProperties wxStoreMultiProperties) {
|
||||
WxStoreMultiProperties.ConfigStorage storage = wxStoreMultiProperties.getConfigStorage();
|
||||
WxStoreMultiRedisProperties 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.store.configuration.services;
|
||||
|
||||
import com.binarywang.solon.wxjava.store.properties.WxStoreMultiProperties;
|
||||
import com.binarywang.solon.wxjava.store.service.WxStoreMultiServices;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import com.binarywang.wxjava.store.config.impl.WxStoreDefaultConfigImpl;
|
||||
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 = "${"+WxStoreMultiProperties.PREFIX + ".configStorage.type} = memory",
|
||||
onClass = JedisPool.class
|
||||
)
|
||||
@RequiredArgsConstructor
|
||||
public class WxStoreInMemoryConfiguration extends AbstractWxStoreConfiguration {
|
||||
private final WxStoreMultiProperties wxStoreMultiProperties;
|
||||
|
||||
@Bean
|
||||
public WxStoreMultiServices wxStoreMultiServices() {
|
||||
return this.wxStoreMultiServices(wxStoreMultiProperties);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected WxStoreDefaultConfigImpl wxStoreConfigStorage(WxStoreMultiProperties wxStoreMultiProperties) {
|
||||
return this.configInMemory();
|
||||
}
|
||||
|
||||
private WxStoreDefaultConfigImpl configInMemory() {
|
||||
return new WxStoreDefaultConfigImpl();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.binarywang.solon.wxjava.store.configuration.services;
|
||||
|
||||
import com.binarywang.solon.wxjava.store.properties.WxStoreMultiProperties;
|
||||
import com.binarywang.solon.wxjava.store.properties.WxStoreMultiRedisProperties;
|
||||
import com.binarywang.solon.wxjava.store.service.WxStoreMultiServices;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import com.binarywang.wxjava.store.config.impl.WxStoreDefaultConfigImpl;
|
||||
import com.binarywang.wxjava.store.config.impl.WxStoreRedissonConfigImpl;
|
||||
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 = "${"+WxStoreMultiProperties.PREFIX + ".configStorage.type} = redisson",
|
||||
onClass = Redisson.class
|
||||
)
|
||||
@RequiredArgsConstructor
|
||||
public class WxStoreInRedissonConfiguration extends AbstractWxStoreConfiguration {
|
||||
private final WxStoreMultiProperties wxStoreMultiProperties;
|
||||
private final AppContext applicationContext;
|
||||
|
||||
@Bean
|
||||
public WxStoreMultiServices wxStoreMultiServices() {
|
||||
return this.wxStoreMultiServices(wxStoreMultiProperties);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected WxStoreDefaultConfigImpl wxStoreConfigStorage(WxStoreMultiProperties wxStoreMultiProperties) {
|
||||
return this.configRedisson(wxStoreMultiProperties);
|
||||
}
|
||||
|
||||
private WxStoreDefaultConfigImpl configRedisson(WxStoreMultiProperties wxStoreMultiProperties) {
|
||||
WxStoreMultiRedisProperties redisProperties = wxStoreMultiProperties.getConfigStorage().getRedis();
|
||||
RedissonClient redissonClient;
|
||||
if (redisProperties != null && StringUtils.isNotEmpty(redisProperties.getHost())) {
|
||||
redissonClient = getRedissonClient(wxStoreMultiProperties);
|
||||
} else {
|
||||
redissonClient = applicationContext.getBean(RedissonClient.class);
|
||||
}
|
||||
return new WxStoreRedissonConfigImpl(redissonClient, wxStoreMultiProperties.getConfigStorage().getKeyPrefix());
|
||||
}
|
||||
|
||||
private RedissonClient getRedissonClient(WxStoreMultiProperties wxStoreMultiProperties) {
|
||||
WxStoreMultiProperties.ConfigStorage storage = wxStoreMultiProperties.getConfigStorage();
|
||||
WxStoreMultiRedisProperties 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,23 @@
|
||||
package com.binarywang.solon.wxjava.store.enums;
|
||||
|
||||
/**
|
||||
* httpclient类型
|
||||
*
|
||||
* @author <a href="https://github.com/Winnie-by996">Winnie</a>
|
||||
* @date 2024/9/13
|
||||
*/
|
||||
public enum HttpClientType {
|
||||
/**
|
||||
* HttpClient
|
||||
*/
|
||||
HTTP_CLIENT,
|
||||
/**
|
||||
* HttpComponents
|
||||
*/
|
||||
HTTP_COMPONENTS
|
||||
// WxStoreServiceOkHttpImpl 实现经测试无法正常完成业务固暂不支持OK_HTTP方式
|
||||
// /**
|
||||
// * OkHttp.
|
||||
// */
|
||||
// OK_HTTP,
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.binarywang.solon.wxjava.store.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.store.integration;
|
||||
|
||||
import com.binarywang.solon.wxjava.store.configuration.services.WxStoreInJedisConfiguration;
|
||||
import com.binarywang.solon.wxjava.store.configuration.services.WxStoreInMemoryConfiguration;
|
||||
import com.binarywang.solon.wxjava.store.configuration.services.WxStoreInRedissonConfiguration;
|
||||
import com.binarywang.solon.wxjava.store.properties.WxStoreMultiProperties;
|
||||
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 WxStoreMultiPluginImpl implements Plugin {
|
||||
@Override
|
||||
public void start(AppContext context) throws Throwable {
|
||||
context.beanMake(WxStoreMultiProperties.class);
|
||||
|
||||
context.beanMake(WxStoreInJedisConfiguration.class);
|
||||
context.beanMake(WxStoreInMemoryConfiguration.class);
|
||||
context.beanMake(WxStoreInRedissonConfiguration.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package com.binarywang.solon.wxjava.store.properties;
|
||||
|
||||
import com.binarywang.solon.wxjava.store.enums.HttpClientType;
|
||||
import com.binarywang.solon.wxjava.store.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("${" + WxStoreMultiProperties.PREFIX +"}")
|
||||
public class WxStoreMultiProperties implements Serializable {
|
||||
private static final long serialVersionUID = - 8361973118805546037L;
|
||||
public static final String PREFIX = "wx.store";
|
||||
|
||||
private Map<String, WxStoreSingleProperties> 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:store:multi";
|
||||
|
||||
/**
|
||||
* redis连接配置.
|
||||
*/
|
||||
private final WxStoreMultiRedisProperties redis = new WxStoreMultiRedisProperties();
|
||||
|
||||
/**
|
||||
* 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 com.binarywang.wxjava.store.api.WxStoreService#setMaxRetryTimes(int)}</p>
|
||||
* <p>{@link com.binarywang.wxjava.store.api.impl.BaseWxStoreServiceImpl#setMaxRetryTimes(int)}</p>
|
||||
*/
|
||||
private int maxRetryTimes = 5;
|
||||
|
||||
/**
|
||||
* http 请求重试间隔
|
||||
*
|
||||
* <p>{@link com.binarywang.wxjava.store.api.WxStoreService#setRetrySleepMillis(int)}</p>
|
||||
* <p>{@link com.binarywang.wxjava.store.api.impl.BaseWxStoreServiceImpl#setRetrySleepMillis(int)}</p>
|
||||
*/
|
||||
private int retrySleepMillis = 1000;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.binarywang.solon.wxjava.store.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 WxStoreMultiRedisProperties 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.store.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 WxStoreSingleProperties 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.store.service;
|
||||
|
||||
import com.binarywang.wxjava.store.api.WxStoreService;
|
||||
|
||||
/**
|
||||
* 视频号 {@link WxStoreService} 所有实例存放类.
|
||||
*
|
||||
* @author <a href="https://github.com/Winnie-by996">Winnie</a>
|
||||
* @date 2024/9/13
|
||||
*/
|
||||
public interface WxStoreMultiServices {
|
||||
/**
|
||||
* 通过租户 Id 获取 WxStoreService
|
||||
*
|
||||
* @param tenantId 租户 Id
|
||||
* @return WxStoreService
|
||||
*/
|
||||
WxStoreService getWxStoreService(String tenantId);
|
||||
|
||||
/**
|
||||
* 根据租户 Id,从列表中移除一个 WxStoreService 实例
|
||||
*
|
||||
* @param tenantId 租户 Id
|
||||
*/
|
||||
void removeWxStoreService(String tenantId);
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.binarywang.solon.wxjava.store.service;
|
||||
|
||||
import com.binarywang.wxjava.store.api.WxStoreService;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* 视频号 {@link WxStoreMultiServices} 实现
|
||||
*
|
||||
* @author <a href="https://github.com/Winnie-by996">Winnie</a>
|
||||
* @date 2024/9/13
|
||||
*/
|
||||
public class WxStoreMultiServicesImpl implements WxStoreMultiServices {
|
||||
private final Map<String, WxStoreService> services = new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
public WxStoreService getWxStoreService(String tenantId) {
|
||||
return this.services.get(tenantId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据租户 Id,添加一个 WxStoreService 到列表
|
||||
*
|
||||
* @param tenantId 租户 Id
|
||||
* @param wxStoreService WxStoreService 实例
|
||||
*/
|
||||
public void addWxStoreService(String tenantId, WxStoreService wxStoreService) {
|
||||
this.services.put(tenantId, wxStoreService);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeWxStoreService(String tenantId) {
|
||||
this.services.remove(tenantId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
solon.plugin=com.binarywang.solon.wxjava.store.integration.WxStoreMultiPluginImpl
|
||||
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.store.apps.tenantId1.app-id=appId
|
||||
wx.store.apps.tenantId1.secret=secret
|
||||
## 选填
|
||||
wx.store.apps.tenantId1.use-stable-access-token=false
|
||||
wx.store.apps.tenantId1.token=
|
||||
wx.store.apps.tenantId1.aes-key=
|
||||
## 应用 2 配置(必填)
|
||||
wx.store.apps.tenantId2.app-id=@appId
|
||||
wx.store.apps.tenantId2.secret=@secret
|
||||
## 选填
|
||||
wx.store.apps.tenantId2.use-stable-access-token=false
|
||||
wx.store.apps.tenantId2.token=
|
||||
wx.store.apps.tenantId2.aes-key=
|
||||
|
||||
# ConfigStorage 配置(选填)
|
||||
## 配置类型: memory(默认), jedis, redisson, redis_template
|
||||
wx.store.config-storage.type=memory
|
||||
## 相关redis前缀配置: wx:store:multi(默认)
|
||||
wx.store.config-storage.key-prefix=wx:store:multi
|
||||
wx.store.config-storage.redis.host=127.0.0.1
|
||||
wx.store.config-storage.redis.port=6379
|
||||
wx.store.config-storage.redis.password=123456
|
||||
|
||||
# http 客户端配置(选填)
|
||||
## # http客户端类型: http_client(默认)
|
||||
wx.store.config-storage.http-client-type=http_client
|
||||
wx.store.config-storage.http-proxy-host=
|
||||
wx.store.config-storage.http-proxy-port=
|
||||
wx.store.config-storage.http-proxy-username=
|
||||
wx.store.config-storage.http-proxy-password=
|
||||
## 最大重试次数,默认:5 次,如果小于 0,则为 0
|
||||
wx.store.config-storage.max-retry-times=5
|
||||
## 重试时间间隔步进,默认:1000 毫秒,如果小于 0,则为 1000
|
||||
wx.store.config-storage.retry-sleep-millis=1000
|
||||
Reference in New Issue
Block a user