mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-05-05 13:17:46 +08:00
Merge remote-tracking branch 'wechat/develop' into develop
This commit is contained in:
commit
9603199597
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<artifactId>wx-java</artifactId>
|
||||
<version>3.9.3.B</version>
|
||||
<version>3.9.4.B</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>WxJava - Weixin/Wechat Java SDK</name>
|
||||
<description>微信开发Java SDK</description>
|
||||
|
@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<artifactId>wx-java</artifactId>
|
||||
<version>3.9.3.B</version>
|
||||
<version>3.9.4.B</version>
|
||||
</parent>
|
||||
<packaging>pom</packaging>
|
||||
<artifactId>wx-java-spring-boot-starters</artifactId>
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>wx-java-spring-boot-starters</artifactId>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<version>3.9.3.B</version>
|
||||
<version>3.9.4.B</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -20,12 +20,19 @@
|
||||
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
|
||||
#单机和sentinel同时存在时,优先使用sentinel配置
|
||||
#wx.mp.config-storage.redis.sentinel-ips=127.0.0.1:16379,127.0.0.1:26379
|
||||
#wx.mp.config-storage.redis.sentinel-name=mymaster
|
||||
# http客户端配置
|
||||
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=
|
||||
wx.mp.config-storage.http-proxy-password=
|
||||
# 公众号地址host配置
|
||||
#wx.mp.hosts.api-host=http://proxy.com/
|
||||
#wx.mp.hosts.open-host=http://proxy.com/
|
||||
#wx.mp.hosts.mp-host=http://proxy.com/
|
||||
```
|
||||
3. 自动注入的类型
|
||||
- `WxMpService`以及~~相关的服务类, 比如: `wxMpService.getXxxService`。~~
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>wx-java-spring-boot-starters</artifactId>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<version>3.9.3.B</version>
|
||||
<version>3.9.4.B</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -1,15 +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;
|
||||
import me.chanjar.weixin.common.redis.RedisTemplateWxRedisOps;
|
||||
import me.chanjar.weixin.common.redis.WxRedisOps;
|
||||
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
|
||||
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
|
||||
import me.chanjar.weixin.mp.config.impl.WxMpRedisConfigImpl;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
@ -17,8 +9,24 @@ import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
|
||||
import com.binarywang.spring.starter.wxjava.mp.enums.StorageType;
|
||||
import com.binarywang.spring.starter.wxjava.mp.properties.RedisProperties;
|
||||
import com.binarywang.spring.starter.wxjava.mp.properties.WxMpProperties;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import me.chanjar.weixin.common.redis.JedisWxRedisOps;
|
||||
import me.chanjar.weixin.common.redis.RedisTemplateWxRedisOps;
|
||||
import me.chanjar.weixin.common.redis.WxRedisOps;
|
||||
import me.chanjar.weixin.mp.bean.WxMpHostConfig;
|
||||
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
|
||||
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
|
||||
import me.chanjar.weixin.mp.config.impl.WxMpRedisConfigImpl;
|
||||
import redis.clients.jedis.JedisPool;
|
||||
import redis.clients.jedis.JedisPoolAbstract;
|
||||
import redis.clients.jedis.JedisPoolConfig;
|
||||
import redis.clients.jedis.JedisSentinelPool;
|
||||
|
||||
/**
|
||||
* 微信公众号存储策略自动配置.
|
||||
@ -54,6 +62,14 @@ public class WxMpStorageAutoConfiguration {
|
||||
config = defaultConfigStorage();
|
||||
break;
|
||||
}
|
||||
// wx host config
|
||||
if (null != wxMpProperties.getHosts() && StringUtils.isNotEmpty(wxMpProperties.getHosts().getApiHost())) {
|
||||
WxMpHostConfig hostConfig = new WxMpHostConfig();
|
||||
hostConfig.setApiHost(wxMpProperties.getHosts().getApiHost());
|
||||
hostConfig.setMpHost(wxMpProperties.getHosts().getMpHost());
|
||||
hostConfig.setOpenHost(wxMpProperties.getHosts().getOpenHost());
|
||||
config.setHostConfig(hostConfig);
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
@ -64,14 +80,15 @@ public class WxMpStorageAutoConfiguration {
|
||||
}
|
||||
|
||||
private WxMpConfigStorage jedisConfigStorage() {
|
||||
JedisPool jedisPool;
|
||||
JedisPoolAbstract jedisPool;
|
||||
if (StringUtils.isNotEmpty(redisHost) || StringUtils.isNotEmpty(redisHost2)) {
|
||||
jedisPool = getJedisPool();
|
||||
} else {
|
||||
jedisPool = applicationContext.getBean(JedisPool.class);
|
||||
}
|
||||
WxRedisOps redisOps = new JedisWxRedisOps(jedisPool);
|
||||
WxMpRedisConfigImpl wxMpRedisConfig = new WxMpRedisConfigImpl(redisOps, wxMpProperties.getConfigStorage().getKeyPrefix());
|
||||
WxMpRedisConfigImpl wxMpRedisConfig = new WxMpRedisConfigImpl(redisOps,
|
||||
wxMpProperties.getConfigStorage().getKeyPrefix());
|
||||
setWxMpInfo(wxMpRedisConfig);
|
||||
return wxMpRedisConfig;
|
||||
}
|
||||
@ -79,7 +96,8 @@ public class WxMpStorageAutoConfiguration {
|
||||
private WxMpConfigStorage redisTemplateConfigStorage() {
|
||||
StringRedisTemplate redisTemplate = applicationContext.getBean(StringRedisTemplate.class);
|
||||
WxRedisOps redisOps = new RedisTemplateWxRedisOps(redisTemplate);
|
||||
WxMpRedisConfigImpl wxMpRedisConfig = new WxMpRedisConfigImpl(redisOps, wxMpProperties.getConfigStorage().getKeyPrefix());
|
||||
WxMpRedisConfigImpl wxMpRedisConfig = new WxMpRedisConfigImpl(redisOps,
|
||||
wxMpProperties.getConfigStorage().getKeyPrefix());
|
||||
setWxMpInfo(wxMpRedisConfig);
|
||||
return wxMpRedisConfig;
|
||||
}
|
||||
@ -100,7 +118,7 @@ public class WxMpStorageAutoConfiguration {
|
||||
}
|
||||
}
|
||||
|
||||
private JedisPool getJedisPool() {
|
||||
private JedisPoolAbstract getJedisPool() {
|
||||
WxMpProperties.ConfigStorage storage = wxMpProperties.getConfigStorage();
|
||||
RedisProperties redis = storage.getRedis();
|
||||
|
||||
@ -119,6 +137,10 @@ public class WxMpStorageAutoConfiguration {
|
||||
}
|
||||
config.setTestOnBorrow(true);
|
||||
config.setTestWhileIdle(true);
|
||||
if (StringUtils.isNotEmpty(redis.getSentinelIps())) {
|
||||
Set<String> sentinels = Sets.newHashSet(redis.getSentinelIps().split(","));
|
||||
return new JedisSentinelPool(redis.getSentinelName(), sentinels);
|
||||
}
|
||||
|
||||
return new JedisPool(config, redis.getHost(), redis.getPort(), redis.getTimeout(), redis.getPassword(),
|
||||
redis.getDatabase());
|
||||
|
@ -0,0 +1,18 @@
|
||||
package com.binarywang.spring.starter.wxjava.mp.properties;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class HostConfig implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = -4172767630740346001L;
|
||||
|
||||
private String apiHost;
|
||||
|
||||
private String openHost;
|
||||
|
||||
private String mpHost;
|
||||
|
||||
}
|
@ -39,6 +39,16 @@ public class RedisProperties implements Serializable {
|
||||
*/
|
||||
private int database = 0;
|
||||
|
||||
/**
|
||||
* sentinel ips
|
||||
*/
|
||||
private String sentinelIps;
|
||||
|
||||
/**
|
||||
* sentinel name
|
||||
*/
|
||||
private String sentinelName;
|
||||
|
||||
private Integer maxActive;
|
||||
private Integer maxIdle;
|
||||
private Integer maxWaitMillis;
|
||||
|
@ -41,6 +41,11 @@ public class WxMpProperties {
|
||||
*/
|
||||
private String aesKey;
|
||||
|
||||
/**
|
||||
* 自定义host配置
|
||||
*/
|
||||
private HostConfig hosts;
|
||||
|
||||
/**
|
||||
* 存储策略
|
||||
*/
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>wx-java-spring-boot-starters</artifactId>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<version>3.9.3.B</version>
|
||||
<version>3.9.4.B</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>wx-java-spring-boot-starters</artifactId>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<version>3.9.3.B</version>
|
||||
<version>3.9.4.B</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<artifactId>wx-java</artifactId>
|
||||
<version>3.9.3.B</version>
|
||||
<version>3.9.4.B</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>weixin-graal</artifactId>
|
||||
|
@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<artifactId>wx-java</artifactId>
|
||||
<version>3.9.3.B</version>
|
||||
<version>3.9.4.B</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>weixin-java-common</artifactId>
|
||||
|
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<artifactId>wx-java</artifactId>
|
||||
<version>3.9.3.B</version>
|
||||
<version>3.9.4.B</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>weixin-java-cp</artifactId>
|
||||
|
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<artifactId>wx-java</artifactId>
|
||||
<version>3.9.3.B</version>
|
||||
<version>3.9.4.B</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>weixin-java-miniapp</artifactId>
|
||||
|
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<artifactId>wx-java</artifactId>
|
||||
<version>3.9.3.B</version>
|
||||
<version>3.9.4.B</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>weixin-java-mp</artifactId>
|
||||
|
@ -7,7 +7,7 @@
|
||||
<parent>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<artifactId>wx-java</artifactId>
|
||||
<version>3.9.3.B</version>
|
||||
<version>3.9.4.B</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>weixin-java-open</artifactId>
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<artifactId>wx-java</artifactId>
|
||||
<version>3.9.3.B</version>
|
||||
<version>3.9.4.B</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user