diff --git a/spring-boot-starters/wx-java-miniapp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/miniapp/config/WxMaAutoConfiguration.java b/spring-boot-starters/wx-java-miniapp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/miniapp/config/WxMaAutoConfiguration.java
index 7c727c968..a07e8008b 100644
--- a/spring-boot-starters/wx-java-miniapp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/miniapp/config/WxMaAutoConfiguration.java
+++ b/spring-boot-starters/wx-java-miniapp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/miniapp/config/WxMaAutoConfiguration.java
@@ -9,6 +9,7 @@ import cn.binarywang.wx.miniapp.config.WxMaConfig;
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
import cn.binarywang.wx.miniapp.config.impl.WxMaRedisBetterConfigImpl;
import com.binarywang.spring.starter.wxjava.miniapp.enums.HttpClientType;
+import com.binarywang.spring.starter.wxjava.miniapp.properties.RedisProperties;
import com.binarywang.spring.starter.wxjava.miniapp.properties.WxMaProperties;
import lombok.AllArgsConstructor;
import me.chanjar.weixin.common.redis.JedisWxRedisOps;
@@ -52,14 +53,19 @@ public class WxMaAutoConfiguration {
public WxMaService service(WxMaConfig wxMaConfig) {
HttpClientType httpClientType = wxMaProperties.getConfigStorage().getHttpClientType();
WxMaService wxMaService;
- if (httpClientType == HttpClientType.OkHttp) {
- wxMaService = new WxMaServiceOkHttpImpl();
- } else if (httpClientType == HttpClientType.JoddHttp) {
- wxMaService = new WxMaServiceJoddHttpImpl();
- } else if (httpClientType == HttpClientType.HttpClient) {
- wxMaService = new WxMaServiceHttpClientImpl();
- } else {
- wxMaService = new WxMaServiceImpl();
+ switch (httpClientType) {
+ case OkHttp:
+ wxMaService = new WxMaServiceOkHttpImpl();
+ break;
+ case JoddHttp:
+ wxMaService = new WxMaServiceJoddHttpImpl();
+ break;
+ case HttpClient:
+ wxMaService = new WxMaServiceHttpClientImpl();
+ break;
+ default:
+ wxMaService = new WxMaServiceImpl();
+ break;
}
wxMaService.setWxMaConfig(wxMaConfig);
return wxMaService;
@@ -102,7 +108,7 @@ public class WxMaAutoConfiguration {
}
private WxMaDefaultConfigImpl wxMaJedisConfigStorage() {
- WxMaProperties.RedisProperties redisProperties = wxMaProperties.getConfigStorage().getRedis();
+ RedisProperties redisProperties = wxMaProperties.getConfigStorage().getRedis();
JedisPool jedisPool;
if (StringUtils.isNotEmpty(redisProperties.getHost())) {
JedisPoolConfig config = new JedisPoolConfig();
diff --git a/spring-boot-starters/wx-java-miniapp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/miniapp/properties/RedisProperties.java b/spring-boot-starters/wx-java-miniapp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/miniapp/properties/RedisProperties.java
new file mode 100644
index 000000000..9cfaf80e8
--- /dev/null
+++ b/spring-boot-starters/wx-java-miniapp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/miniapp/properties/RedisProperties.java
@@ -0,0 +1,43 @@
+package com.binarywang.spring.starter.wxjava.miniapp.properties;
+
+import lombok.Data;
+
+/**
+ * redis 配置.
+ *
+ * @author Binary Wang
+ * @date 2020-08-30
+ */
+@Data
+public class RedisProperties {
+
+ /**
+ * 主机地址.不填则从spring容器内获取JedisPool
+ */
+ private String host;
+
+ /**
+ * 端口号.
+ */
+ private int port = 6379;
+
+ /**
+ * 密码.
+ */
+ private String password;
+
+ /**
+ * 超时.
+ */
+ private int timeout = 2000;
+
+ /**
+ * 数据库.
+ */
+ private int database = 0;
+
+ private Integer maxActive;
+ private Integer maxIdle;
+ private Integer maxWaitMillis;
+ private Integer minIdle;
+}
diff --git a/spring-boot-starters/wx-java-miniapp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/miniapp/properties/WxMaProperties.java b/spring-boot-starters/wx-java-miniapp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/miniapp/properties/WxMaProperties.java
index 0139215ea..25a004776 100644
--- a/spring-boot-starters/wx-java-miniapp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/miniapp/properties/WxMaProperties.java
+++ b/spring-boot-starters/wx-java-miniapp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/miniapp/properties/WxMaProperties.java
@@ -88,37 +88,4 @@ public class WxMaProperties {
private String httpProxyPassword;
}
- @Data
- public static class RedisProperties {
-
- /**
- * 主机地址.不填则从spring容器内获取JedisPool
- */
- private String host;
-
- /**
- * 端口号.
- */
- private int port = 6379;
-
- /**
- * 密码.
- */
- private String password;
-
- /**
- * 超时.
- */
- private int timeout = 2000;
-
- /**
- * 数据库.
- */
- private int database = 0;
-
- private Integer maxActive;
- private Integer maxIdle;
- private Integer maxWaitMillis;
- private Integer minIdle;
- }
}
diff --git a/spring-boot-starters/wx-java-mp-spring-boot-starter/README.md b/spring-boot-starters/wx-java-mp-spring-boot-starter/README.md
index 65cc5bbbf..5059a59f5 100644
--- a/spring-boot-starters/wx-java-mp-spring-boot-starter/README.md
+++ b/spring-boot-starters/wx-java-mp-spring-boot-starter/README.md
@@ -16,12 +16,12 @@
wx.mp.token = @token
wx.mp.aesKey = @aesKey
# 存储配置redis(可选)
- wx.mp.config-storage.type = redis # 配置类型: memory(默认), redis, jedis, redistemplate
+ wx.mp.config-storage.type = Jedis # 配置类型: Memory(默认), Jedis, RedisTemplate
wx.mp.config-storage.key-prefix = wx # 相关redis前缀配置: wx(默认)
wx.mp.config-storage.redis.host = 127.0.0.1
wx.mp.config-storage.redis.port = 6379
# http客户端配置
- wx.mp.config-storage.http-client-type=httpclient # http客户端类型: httpclient(默认), okhttp, joddhttp
+ wx.mp.config-storage.http-client-type=httpclient # http客户端类型: HttpClient(默认), OkHttp, JoddHttp
wx.mp.config-storage.http-proxy-host=
wx.mp.config-storage.http-proxy-port=
wx.mp.config-storage.http-proxy-username=
diff --git a/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/config/WxMpServiceAutoConfiguration.java b/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/config/WxMpServiceAutoConfiguration.java
index 1c942bbfa..3f1195a4c 100644
--- a/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/config/WxMpServiceAutoConfiguration.java
+++ b/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/config/WxMpServiceAutoConfiguration.java
@@ -1,7 +1,7 @@
package com.binarywang.spring.starter.wxjava.mp.config;
+import com.binarywang.spring.starter.wxjava.mp.enums.HttpClientType;
import com.binarywang.spring.starter.wxjava.mp.properties.WxMpProperties;
-import me.chanjar.weixin.common.api.WxOcrService;
import me.chanjar.weixin.mp.api.*;
import me.chanjar.weixin.mp.api.impl.WxMpServiceHttpClientImpl;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
@@ -23,16 +23,21 @@ public class WxMpServiceAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public WxMpService wxMpService(WxMpConfigStorage configStorage, WxMpProperties wxMpProperties) {
- WxMpProperties.HttpClientType httpClientType = wxMpProperties.getConfigStorage().getHttpClientType();
+ HttpClientType httpClientType = wxMpProperties.getConfigStorage().getHttpClientType();
WxMpService wxMpService;
- if (httpClientType == WxMpProperties.HttpClientType.okhttp) {
- wxMpService = newWxMpServiceOkHttpImpl();
- } else if (httpClientType == WxMpProperties.HttpClientType.joddhttp) {
- wxMpService = newWxMpServiceJoddHttpImpl();
- } else if (httpClientType == WxMpProperties.HttpClientType.httpclient) {
- wxMpService = newWxMpServiceHttpClientImpl();
- } else {
- wxMpService = newWxMpServiceImpl();
+ switch (httpClientType) {
+ case OkHttp:
+ wxMpService = newWxMpServiceOkHttpImpl();
+ break;
+ case JoddHttp:
+ wxMpService = newWxMpServiceJoddHttpImpl();
+ break;
+ case HttpClient:
+ wxMpService = newWxMpServiceHttpClientImpl();
+ break;
+ default:
+ wxMpService = newWxMpServiceImpl();
+ break;
}
wxMpService.setWxMpConfigStorage(configStorage);
diff --git a/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/config/WxMpStorageAutoConfiguration.java b/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/config/WxMpStorageAutoConfiguration.java
index fc15e7605..ad4fb31e4 100644
--- a/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/config/WxMpStorageAutoConfiguration.java
+++ b/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/config/WxMpStorageAutoConfiguration.java
@@ -1,5 +1,7 @@
package com.binarywang.spring.starter.wxjava.mp.config;
+import com.binarywang.spring.starter.wxjava.mp.properties.RedisProperties;
+import com.binarywang.spring.starter.wxjava.mp.enums.StorageType;
import com.binarywang.spring.starter.wxjava.mp.properties.WxMpProperties;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.redis.JedisWxRedisOps;
@@ -26,7 +28,6 @@ import redis.clients.jedis.JedisPoolConfig;
@Configuration
@RequiredArgsConstructor
public class WxMpStorageAutoConfiguration {
-
private final ApplicationContext applicationContext;
private final WxMpProperties wxMpProperties;
@@ -40,25 +41,29 @@ public class WxMpStorageAutoConfiguration {
@Bean
@ConditionalOnMissingBean(WxMpConfigStorage.class)
public WxMpConfigStorage wxMpConfigStorage() {
- WxMpProperties.StorageType type = wxMpProperties.getConfigStorage().getType();
+ StorageType type = wxMpProperties.getConfigStorage().getType();
WxMpConfigStorage config;
- if (type == WxMpProperties.StorageType.redis || type == WxMpProperties.StorageType.jedis) {
- config = wxMpInJedisConfigStorage();
- } else if (type == WxMpProperties.StorageType.redistemplate) {
- config = wxMpInRedisTemplateConfigStorage();
- } else {
- config = wxMpInMemoryConfigStorage();
+ switch (type) {
+ case Jedis:
+ config = jedisConfigStorage();
+ break;
+ case RedisTemplate:
+ config = redisTemplateConfigStorage();
+ break;
+ default:
+ config = defaultConfigStorage();
+ break;
}
return config;
}
- private WxMpConfigStorage wxMpInMemoryConfigStorage() {
+ private WxMpConfigStorage defaultConfigStorage() {
WxMpDefaultConfigImpl config = new WxMpDefaultConfigImpl();
setWxMpInfo(config);
return config;
}
- private WxMpConfigStorage wxMpInJedisConfigStorage() {
+ private WxMpConfigStorage jedisConfigStorage() {
JedisPool jedisPool;
if (StringUtils.isNotEmpty(redisHost) || StringUtils.isNotEmpty(redisHost2)) {
jedisPool = getJedisPool();
@@ -71,7 +76,7 @@ public class WxMpStorageAutoConfiguration {
return wxMpRedisConfig;
}
- private WxMpConfigStorage wxMpInRedisTemplateConfigStorage() {
+ private WxMpConfigStorage redisTemplateConfigStorage() {
StringRedisTemplate redisTemplate = applicationContext.getBean(StringRedisTemplate.class);
WxRedisOps redisOps = new RedisTemplateWxRedisOps(redisTemplate);
WxMpRedisConfigImpl wxMpRedisConfig = new WxMpRedisConfigImpl(redisOps, wxMpProperties.getConfigStorage().getKeyPrefix());
@@ -97,7 +102,7 @@ public class WxMpStorageAutoConfiguration {
private JedisPool getJedisPool() {
WxMpProperties.ConfigStorage storage = wxMpProperties.getConfigStorage();
- WxMpProperties.RedisProperties redis = storage.getRedis();
+ RedisProperties redis = storage.getRedis();
JedisPoolConfig config = new JedisPoolConfig();
if (redis.getMaxActive() != null) {
diff --git a/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/enums/HttpClientType.java b/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/enums/HttpClientType.java
new file mode 100644
index 000000000..1fa235e4a
--- /dev/null
+++ b/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/enums/HttpClientType.java
@@ -0,0 +1,22 @@
+package com.binarywang.spring.starter.wxjava.mp.enums;
+
+/**
+ * httpclient类型.
+ *
+ * @author Binary Wang
+ * @date 2020-08-30
+ */
+public enum HttpClientType {
+ /**
+ * HttpClient.
+ */
+ HttpClient,
+ /**
+ * OkHttp.
+ */
+ OkHttp,
+ /**
+ * JoddHttp.
+ */
+ JoddHttp,
+}
diff --git a/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/enums/StorageType.java b/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/enums/StorageType.java
new file mode 100644
index 000000000..7dcb5a115
--- /dev/null
+++ b/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/enums/StorageType.java
@@ -0,0 +1,22 @@
+package com.binarywang.spring.starter.wxjava.mp.enums;
+
+/**
+ * storage类型.
+ *
+ * @author Binary Wang
+ * @date 2020-08-30
+ */
+public enum StorageType {
+ /**
+ * 内存.
+ */
+ Memory,
+ /**
+ * redis(JedisClient).
+ */
+ Jedis,
+ /**
+ * redis(RedisTemplate).
+ */
+ RedisTemplate
+}
diff --git a/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/properties/RedisProperties.java b/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/properties/RedisProperties.java
new file mode 100644
index 000000000..c8c3307fe
--- /dev/null
+++ b/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/properties/RedisProperties.java
@@ -0,0 +1,46 @@
+package com.binarywang.spring.starter.wxjava.mp.properties;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * redis 配置属性.
+ *
+ * @author Binary Wang
+ * @date 2020-08-30
+ */
+@Data
+public class RedisProperties implements Serializable {
+ private static final long serialVersionUID = -5924815351660074401L;
+
+ /**
+ * 主机地址.
+ */
+ 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 maxWaitMillis;
+ private Integer minIdle;
+}
diff --git a/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/properties/WxMpProperties.java b/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/properties/WxMpProperties.java
index 60b39d9cd..af21cd9da 100644
--- a/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/properties/WxMpProperties.java
+++ b/spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/properties/WxMpProperties.java
@@ -1,12 +1,14 @@
package com.binarywang.spring.starter.wxjava.mp.properties;
+import com.binarywang.spring.starter.wxjava.mp.enums.HttpClientType;
+import com.binarywang.spring.starter.wxjava.mp.enums.StorageType;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import java.io.Serializable;
import static com.binarywang.spring.starter.wxjava.mp.properties.WxMpProperties.PREFIX;
-import static com.binarywang.spring.starter.wxjava.mp.properties.WxMpProperties.StorageType.memory;
+import static com.binarywang.spring.starter.wxjava.mp.enums.StorageType.Memory;
/**
@@ -51,7 +53,7 @@ public class WxMpProperties {
/**
* 存储类型.
*/
- private StorageType type = memory;
+ private StorageType type = Memory;
/**
* 指定key前缀.
@@ -90,73 +92,4 @@ public class WxMpProperties {
}
- public enum StorageType {
- /**
- * 内存.
- */
- memory,
- /**
- * jedis.
- */
- redis,
- /**
- * redis(JedisClient).
- */
- jedis,
- /**
- * redis(RedisTemplate).
- */
- redistemplate
- }
-
- public enum HttpClientType {
- /**
- * HttpClient.
- */
- httpclient,
- /**
- * OkHttp.
- */
- okhttp,
- /**
- * JoddHttp.
- */
- joddhttp
- }
-
- @Data
- public static class RedisProperties implements Serializable {
- private static final long serialVersionUID = -5924815351660074401L;
-
- /**
- * 主机地址.
- */
- 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 maxWaitMillis;
- private Integer minIdle;
- }
-
}