Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion solon-plugins/wx-java-mp-solon-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<scope>compile</scope>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jodd</groupId>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.binarywang.solon.wxjava.mp.config.storage;

import com.binarywang.solon.wxjava.mp.properties.WxMpProperties;
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;

/**
* @author <a href="https://github.com/buaazyl">zhangyl</a>
*/
public abstract class AbstractWxMpConfigStorageConfiguration {

protected WxMpDefaultConfigImpl config(WxMpDefaultConfigImpl config, WxMpProperties properties) {
config.setAppId(properties.getAppId());
config.setSecret(properties.getSecret());
config.setToken(properties.getToken());
config.setAesKey(properties.getAesKey());
config.setUseStableAccessToken(properties.isUseStableAccessToken());

WxMpProperties.ConfigStorage configStorageProperties = properties.getConfigStorage();
config.setHttpProxyHost(configStorageProperties.getHttpProxyHost());
config.setHttpProxyUsername(configStorageProperties.getHttpProxyUsername());
config.setHttpProxyPassword(configStorageProperties.getHttpProxyPassword());
if (configStorageProperties.getHttpProxyPort() != null) {
config.setHttpProxyPort(configStorageProperties.getHttpProxyPort());
}
return config;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.binarywang.solon.wxjava.mp.config.storage;

import com.binarywang.solon.wxjava.mp.properties.RedisProperties;
import com.binarywang.solon.wxjava.mp.properties.WxMpProperties;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.redis.JedisWxRedisOps;
import me.chanjar.weixin.common.redis.WxRedisOps;
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
import me.chanjar.weixin.mp.config.impl.WxMpRedisConfigImpl;
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.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
* @author <a href="https://github.com/buaazyl">zhangyl</a>
*/
@Configuration
@Condition(
onProperty = "${" + WxMpProperties.PREFIX + ".config-storage.type} = jedis",
onClass = Jedis.class
)
@RequiredArgsConstructor
public class WxMpInJedisConfigStorageConfiguration extends AbstractWxMpConfigStorageConfiguration {
private final WxMpProperties properties;
private final AppContext applicationContext;

@Bean
@Condition(onMissingBean = WxMpConfigStorage.class)
public WxMpConfigStorage wxMpConfigStorage() {
WxMpRedisConfigImpl config = getWxMpRedisConfigImpl();
return this.config(config, properties);
}

private WxMpRedisConfigImpl getWxMpRedisConfigImpl() {
RedisProperties redisProperties = properties.getConfigStorage().getRedis();
JedisPool jedisPool;
if (redisProperties != null && StringUtils.isNotEmpty(redisProperties.getHost())) {
jedisPool = applicationContext.getBean("wxMpJedisPool");
} else {
jedisPool = applicationContext.getBean(JedisPool.class);
}
WxRedisOps redisOps = new JedisWxRedisOps(jedisPool);
return new WxMpRedisConfigImpl(redisOps, properties.getConfigStorage().getKeyPrefix());
}

@Bean
@Condition(onProperty = "${" + WxMpProperties.PREFIX + ".config-storage.redis.host}")
public JedisPool wxMpJedisPool() {
WxMpProperties.ConfigStorage storage = properties.getConfigStorage();
RedisProperties 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());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.binarywang.solon.wxjava.mp.config.storage;

import com.binarywang.solon.wxjava.mp.properties.WxMpProperties;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
import org.noear.solon.annotation.Bean;
import org.noear.solon.annotation.Condition;
import org.noear.solon.annotation.Configuration;

/**
* @author <a href="https://github.com/buaazyl">zhangyl</a>
*/
@Configuration
@Condition(
onProperty = "${" + WxMpProperties.PREFIX + ".config-storage.type:memory} = memory"
)
@RequiredArgsConstructor
public class WxMpInMemoryConfigStorageConfiguration extends AbstractWxMpConfigStorageConfiguration {
private final WxMpProperties properties;

@Bean
@Condition(onMissingBean = WxMpConfigStorage.class)
public WxMpConfigStorage wxMpConfigStorage() {
WxMpDefaultConfigImpl config = new WxMpDefaultConfigImpl();
config(config, properties);
return config;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.binarywang.solon.wxjava.mp.config.storage;

import com.binarywang.solon.wxjava.mp.properties.RedisProperties;
import com.binarywang.solon.wxjava.mp.properties.WxMpProperties;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
import me.chanjar.weixin.mp.config.impl.WxMpRedissonConfigImpl;
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;

/**
* @author <a href="https://github.com/buaazyl">zhangyl</a>
*/
@Configuration
@Condition(
onProperty = "${" + WxMpProperties.PREFIX + ".config-storage.type} = redisson",
onClass = Redisson.class
)
@RequiredArgsConstructor
public class WxMpInRedissonConfigStorageConfiguration extends AbstractWxMpConfigStorageConfiguration {
private final WxMpProperties properties;
private final AppContext applicationContext;

@Bean
@Condition(onMissingBean = WxMpConfigStorage.class)
public WxMpConfigStorage wxMaConfig() {
WxMpRedissonConfigImpl config = getWxMpInRedissonConfigStorage();
return this.config(config, properties);
}

private WxMpRedissonConfigImpl getWxMpInRedissonConfigStorage() {
RedisProperties redisProperties = properties.getConfigStorage().getRedis();
RedissonClient redissonClient;
if (redisProperties != null && StringUtils.isNotEmpty(redisProperties.getHost())) {
redissonClient = applicationContext.getBean("wxMpRedissonClient");
} else {
redissonClient = applicationContext.getBean(RedissonClient.class);
}
return new WxMpRedissonConfigImpl(redissonClient, properties.getConfigStorage().getKeyPrefix());
}

@Bean
@Condition(onProperty = "${" + WxMpProperties.PREFIX + ".config-storage.redis.host}")
public RedissonClient wxMpRedissonClient() {
WxMpProperties.ConfigStorage storage = properties.getConfigStorage();
RedisProperties redis = storage.getRedis();

Config config = new Config();
config.useSingleServer()
.setAddress("redis://" + redis.getHost() + ":" + redis.getPort())
.setDatabase(redis.getDatabase());
if (StringUtils.isNotBlank(redis.getPassword())) {
config.useSingleServer().setPassword(redis.getPassword());
}
config.setTransportMode(TransportMode.NIO);
return Redisson.create(config);
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.binarywang.solon.wxjava.mp.integration;

import com.binarywang.solon.wxjava.mp.config.WxMpServiceAutoConfiguration;
import com.binarywang.solon.wxjava.mp.config.WxMpStorageAutoConfiguration;
import com.binarywang.solon.wxjava.mp.config.storage.WxMpInJedisConfigStorageConfiguration;
import com.binarywang.solon.wxjava.mp.config.storage.WxMpInMemoryConfigStorageConfiguration;
import com.binarywang.solon.wxjava.mp.config.storage.WxMpInRedissonConfigStorageConfiguration;
import com.binarywang.solon.wxjava.mp.properties.WxMpProperties;
import org.noear.solon.core.AppContext;
import org.noear.solon.core.Plugin;
import org.noear.solon.core.util.ClassUtil;

/**
* @author noear 2024/9/2 created
Expand All @@ -13,8 +16,14 @@ public class WxMpPluginImpl implements Plugin {
@Override
public void start(AppContext context) throws Throwable {
context.beanMake(WxMpProperties.class);

context.beanMake(WxMpStorageAutoConfiguration.class);
context.beanMake(WxMpServiceAutoConfiguration.class);

context.beanMake(WxMpInMemoryConfigStorageConfiguration.class);
if (ClassUtil.loadClass("redis.clients.jedis.Jedis") != null) {
context.beanMake(WxMpInJedisConfigStorageConfiguration.class);
}
if (ClassUtil.loadClass("org.redisson.api.RedissonClient") != null) {
context.beanMake(WxMpInRedissonConfigStorageConfiguration.class);
}
}
}
7 changes: 6 additions & 1 deletion spring-boot-starters/wx-java-mp-spring-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<scope>compile</scope>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
Expand All @@ -44,6 +44,11 @@
<artifactId>httpclient5</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
Expand Down
Loading