Skip to content

Commit

Permalink
Merge pull request #1730 from Wechat-Group/develop
Browse files Browse the repository at this point in the history
合并develop分支,发布最新正式版
  • Loading branch information
binarywang committed Aug 23, 2020
2 parents 89011db + ec7ab21 commit 0fcd371
Show file tree
Hide file tree
Showing 467 changed files with 12,365 additions and 3,981 deletions.
16 changes: 10 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.binarywang</groupId>
<artifactId>wx-java</artifactId>
<version>3.8.0</version>
<version>3.9.0</version>
<packaging>pom</packaging>
<name>WxJava - Weixin/Wechat Java SDK</name>
<description>微信开发Java SDK</description>
Expand Down Expand Up @@ -90,6 +90,11 @@
<email>liuxinghao1988@gmail.com</email>
<url>https://github.com/howardliu-cn</url>
</developer>
<developer>
<name>huangxiaoming</name>
<email>huangxm129@163.com</email>
<url>https://github.com/huangxm129</url>
</developer>
</developers>

<scm>
Expand All @@ -111,8 +116,8 @@
</modules>

<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<httpclient.version>4.5</httpclient.version>
Expand All @@ -126,11 +131,10 @@
<artifactId>qrcode-utils</artifactId>
<version>1.1</version>
</dependency>
<!-- 由于jodd-http较新的3.8版本需要jdk8,故而此处采用较低版本 -->
<dependency>
<groupId>org.jodd</groupId>
<artifactId>jodd-http</artifactId>
<version>5.1.4</version>
<version>5.1.6</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -239,7 +243,7 @@
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.9.0</version>
<version>3.3.0</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion spring-boot-starters/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.github.binarywang</groupId>
<artifactId>wx-java</artifactId>
<version>3.8.0</version>
<version>3.9.0</version>
</parent>
<packaging>pom</packaging>
<artifactId>wx-java-spring-boot-starters</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
wx.miniapp.msgDataFormat = @msgDataFormat # 消息格式,XML或者JSON.
# 存储配置redis(可选)
# 注意: 指定redis.host值后不会使用容器注入的redis连接(JedisPool)
wx.miniapp.config-storage.type = jedis # 配置类型: memory(默认), jedis, redistemplate
wx.miniapp.config-storage.type = Jedis # 配置类型: Memory(默认), Jedis, RedisTemplate
wx.miniapp.config-storage.key-prefix = wa # 相关redis前缀配置: wa(默认)
wx.miniapp.config-storage.redis.host = 127.0.0.1
wx.miniapp.config-storage.redis.port = 6379
# http客户端配置
wx.miniapp.config-storage.http-client-type=httpclient # http客户端类型: httpclient(默认)
wx.miniapp.config-storage.http-client-type=HttpClient # http客户端类型: HttpClient(默认), OkHttp, JoddHttp
wx.miniapp.config-storage.http-proxy-host=
wx.miniapp.config-storage.http-proxy-port=
wx.miniapp.config-storage.http-proxy-username=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>wx-java-spring-boot-starters</artifactId>
<groupId>com.github.binarywang</groupId>
<version>3.8.0</version>
<version>3.9.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -22,13 +22,11 @@
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>${spring.boot.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package com.binarywang.spring.starter.wxjava.miniapp.config;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceHttpClientImpl;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceJoddHttpImpl;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceOkHttpImpl;
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.WxMaProperties;
import lombok.AllArgsConstructor;
import me.chanjar.weixin.common.redis.JedisWxRedisOps;
Expand Down Expand Up @@ -46,22 +50,35 @@ public class WxMaAutoConfiguration {
@Bean
@ConditionalOnMissingBean(WxMaService.class)
public WxMaService service(WxMaConfig wxMaConfig) {
final WxMaServiceImpl service = new WxMaServiceImpl();
service.setWxMaConfig(wxMaConfig);
return service;
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();
}
wxMaService.setWxMaConfig(wxMaConfig);
return wxMaService;
}

@Bean
@ConditionalOnMissingBean(WxMaConfig.class)
public WxMaConfig wxMaConfig() {
WxMaProperties.StorageType type = wxMaProperties.getConfigStorage().getType();
WxMaDefaultConfigImpl config;
if (type == WxMaProperties.StorageType.jedis) {
config = wxMaInJedisConfigStorage();
} else if (type == WxMaProperties.StorageType.redistemplate) {
config = wxMaInRedisTemplateConfigStorage();
} else {
config = wxMaInMemoryConfigStorage();
switch (wxMaProperties.getConfigStorage().getType()) {
case Jedis:
config = wxMaJedisConfigStorage();
break;
case RedisTemplate:
config = wxMaRedisTemplateConfigStorage();
break;
default:
config = wxMaDefaultConfigStorage();
break;
}

config.setAppid(StringUtils.trimToNull(this.wxMaProperties.getAppid()));
Expand All @@ -80,52 +97,42 @@ public WxMaConfig wxMaConfig() {
return config;
}

private WxMaDefaultConfigImpl wxMaInMemoryConfigStorage() {
WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
return config;
private WxMaDefaultConfigImpl wxMaDefaultConfigStorage() {
return new WxMaDefaultConfigImpl();
}

private WxMaDefaultConfigImpl wxMaInJedisConfigStorage() {
private WxMaDefaultConfigImpl wxMaJedisConfigStorage() {
WxMaProperties.RedisProperties redisProperties = wxMaProperties.getConfigStorage().getRedis();
JedisPool jedisPool;
if (redisProperties != null && StringUtils.isNotEmpty(redisProperties.getHost())) {
jedisPool = getJedisPool();
if (StringUtils.isNotEmpty(redisProperties.getHost())) {
JedisPoolConfig config = new JedisPoolConfig();
if (redisProperties.getMaxActive() != null) {
config.setMaxTotal(redisProperties.getMaxActive());
}
if (redisProperties.getMaxIdle() != null) {
config.setMaxIdle(redisProperties.getMaxIdle());
}
if (redisProperties.getMaxWaitMillis() != null) {
config.setMaxWaitMillis(redisProperties.getMaxWaitMillis());
}
if (redisProperties.getMinIdle() != null) {
config.setMinIdle(redisProperties.getMinIdle());
}
config.setTestOnBorrow(true);
config.setTestWhileIdle(true);

jedisPool = new JedisPool(config, redisProperties.getHost(), redisProperties.getPort(),
redisProperties.getTimeout(), redisProperties.getPassword(), redisProperties.getDatabase());
} else {
jedisPool = applicationContext.getBean(JedisPool.class);
}
WxRedisOps redisOps = new JedisWxRedisOps(jedisPool);
WxMaRedisBetterConfigImpl wxMaRedisConfig = new WxMaRedisBetterConfigImpl(redisOps, wxMaProperties.getConfigStorage().getKeyPrefix());
return wxMaRedisConfig;
return new WxMaRedisBetterConfigImpl(redisOps, wxMaProperties.getConfigStorage().getKeyPrefix());
}

private WxMaDefaultConfigImpl wxMaInRedisTemplateConfigStorage() {
private WxMaDefaultConfigImpl wxMaRedisTemplateConfigStorage() {
StringRedisTemplate redisTemplate = applicationContext.getBean(StringRedisTemplate.class);
WxRedisOps redisOps = new RedisTemplateWxRedisOps(redisTemplate);
WxMaRedisBetterConfigImpl wxMaRedisConfig = new WxMaRedisBetterConfigImpl(redisOps, wxMaProperties.getConfigStorage().getKeyPrefix());
return wxMaRedisConfig;
}

private JedisPool getJedisPool() {
WxMaProperties.ConfigStorage storage = wxMaProperties.getConfigStorage();
WxMaProperties.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());
return new WxMaRedisBetterConfigImpl(redisOps, wxMaProperties.getConfigStorage().getKeyPrefix());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.binarywang.spring.starter.wxjava.miniapp.enums;

/**
* httpclient类型.
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
* @date 2020-05-25
*/
public enum HttpClientType {
/**
* HttpClient.
*/
HttpClient,
/**
* OkHttp.
*/
OkHttp,
/**
* JoddHttp.
*/
JoddHttp,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.binarywang.spring.starter.wxjava.miniapp.enums;

/**
* storage类型.
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
* @date 2020-05-25
*/
public enum StorageType {
/**
* 内存.
*/
Memory,
/**
* redis(JedisClient).
*/
Jedis,
/**
* redis(RedisTemplate).
*/
RedisTemplate
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.binarywang.spring.starter.wxjava.miniapp.properties;

import com.binarywang.spring.starter.wxjava.miniapp.enums.HttpClientType;
import com.binarywang.spring.starter.wxjava.miniapp.enums.StorageType;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.io.Serializable;

/**
* 属性配置类.
*
Expand Down Expand Up @@ -42,16 +42,15 @@ public class WxMaProperties {
/**
* 存储策略
*/
private ConfigStorage configStorage = new ConfigStorage();
private final ConfigStorage configStorage = new ConfigStorage();

@Data
public static class ConfigStorage implements Serializable {
private static final long serialVersionUID = 4815731027000065434L;
public static class ConfigStorage {

/**
* 存储类型.
*/
private StorageType type = StorageType.memory;
private StorageType type = StorageType.Memory;

/**
* 指定key前缀.
Expand All @@ -61,12 +60,12 @@ public static class ConfigStorage implements Serializable {
/**
* redis连接配置.
*/
private RedisProperties redis;
private final RedisProperties redis = new RedisProperties();

/**
* http客户端类型.
*/
private HttpClientType httpClientType = HttpClientType.httpclient;
private HttpClientType httpClientType = HttpClientType.HttpClient;

/**
* http代理主机.
Expand All @@ -87,37 +86,13 @@ public static class ConfigStorage implements Serializable {
* http代理密码.
*/
private String httpProxyPassword;

}

public enum StorageType {
/**
* 内存.
*/
memory,
/**
* redis(JedisClient).
*/
jedis,
/**
* redis(RedisTemplate).
*/
redistemplate
}

public enum HttpClientType {
/**
* HttpClient.
*/
httpclient
}

@Data
public static class RedisProperties implements Serializable {
private static final long serialVersionUID = -5924815351660074401L;
public static class RedisProperties {

/**
* 主机地址.
* 主机地址.不填则从spring容器内获取JedisPool
*/
private String host;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>wx-java-spring-boot-starters</artifactId>
<groupId>com.github.binarywang</groupId>
<version>3.8.0</version>
<version>3.9.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down

0 comments on commit 0fcd371

Please sign in to comment.