Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【微信公众号】增加是否启用 StableAccessToken 配置 #3261

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
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
## 选填
wx.mp.tenantId1.token=@token
wx.mp.tenantId1.aes-key=@aesKey
wx.mp.tenantId1.use-stable-access-token=@useStableAccessToken
## 应用 2 配置(必填)
wx.mp.tenantId2.app-id=@appId
wx.mp.tenantId2.app-secret =@secret
## 选填
wx.mp.tenantId2.token=@token
wx.mp.tenantId2.aes-key=@aesKey
wx.mp.tenantId2.use-stable-access-token=@useStableAccessToken

# ConfigStorage 配置(选填)
## 配置类型: memory(默认), jedis, redisson, redis_template
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ private void configApp(WxMpDefaultConfigImpl config, WxMpSingleProperties corpPr
String appSecret = corpProperties.getAppSecret();
String token = corpProperties.getToken();
String aesKey = corpProperties.getAesKey();
boolean useStableAccessToken = corpProperties.isUseStableAccessToken();

config.setAppId(appId);
config.setSecret(appSecret);
Expand All @@ -124,6 +125,7 @@ private void configApp(WxMpDefaultConfigImpl config, WxMpSingleProperties corpPr
if (StringUtils.isNotBlank(aesKey)) {
config.setAesKey(aesKey);
}
config.setUseStableAccessToken(useStableAccessToken);
}

private void configHttp(WxMpDefaultConfigImpl config, WxMpMultiProperties.ConfigStorage storage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,9 @@ public class WxMpSingleProperties implements Serializable {
* 设置微信公众号的 EncodingAESKey.
*/
private String aesKey;

/**
* 是否使用稳定版 Access Token
*/
private boolean useStableAccessToken = false;
}
25 changes: 12 additions & 13 deletions spring-boot-starters/wx-java-mp-spring-boot-starter/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# wx-java-mp-spring-boot-starter

## 快速开始

1. 引入依赖
```xml
<dependency>
Expand All @@ -11,15 +13,16 @@
2. 添加配置(application.properties)
```properties
# 公众号配置(必填)
wx.mp.appId = appId
wx.mp.secret = @secret
wx.mp.token = @token
wx.mp.aesKey = @aesKey
wx.mp.app-id=appId
wx.mp.secret=@secret
wx.mp.token=@token
wx.mp.aes-key=@aesKey
wx.mp.use-stable-access-token=@useStableAccessToken
# 存储配置redis(可选)
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
wx.mp.config-storage.type= edis # 配置类型: 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
#单机和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
Expand All @@ -35,13 +38,9 @@
#wx.mp.hosts.mp-host=http://proxy.com/
```
3. 自动注入的类型

- `WxMpService`
- `WxMpConfigStorage`

4、参考demo:
https://github.com/binarywang/wx-java-mp-demo





Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
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.WxMpHostConfig;
import me.chanjar.weixin.mp.config.WxMpConfigStorage;
import me.chanjar.weixin.mp.config.WxMpHostConfig;
import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl;
import me.chanjar.weixin.mp.config.impl.WxMpRedisConfigImpl;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -122,7 +122,7 @@ private void setWxMpInfo(WxMpDefaultConfigImpl config) {
config.setSecret(properties.getSecret());
config.setToken(properties.getToken());
config.setAesKey(properties.getAesKey());

config.setUseStableAccessToken(wxMpProperties.isUseStableAccessToken());
config.setHttpProxyHost(configStorageProperties.getHttpProxyHost());
config.setHttpProxyUsername(configStorageProperties.getHttpProxyUsername());
config.setHttpProxyPassword(configStorageProperties.getHttpProxyPassword());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ public class WxMpProperties {
* 设置微信公众号的EncodingAESKey.
*/
private String aesKey;

/**
* 是否使用稳定版 Access Token
*/
private boolean useStableAccessToken = false;

/**
* 自定义host配置
Expand Down