Skip to content

Commit 3481cca

Browse files
charmingohbinarywang
authored andcommitted
binarywang#559 微信开放平台:1. WxOpenInRedisConfigStorage 支持 JedisPool/JedisSentinelPool 等 Pool<Jedis> 的子类;2. WxOpenInRedisConfigStorage 增加 keyPrefix 以支持可配置的前缀;
1 parent 445b47b commit 3481cca

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenInRedisConfigStorage.java

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package me.chanjar.weixin.open.api.impl;
22

3+
import org.apache.commons.lang3.StringUtils;
34
import redis.clients.jedis.Jedis;
45
import redis.clients.jedis.JedisPool;
6+
import redis.clients.util.Pool;
57

68
/**
79
* @author <a href="https://github.com/007gzs">007</a>
@@ -15,25 +17,40 @@ public class WxOpenInRedisConfigStorage extends WxOpenInMemoryConfigStorage {
1517
private final static String JSAPI_TICKET_KEY = "wechat_jsapi_ticket:";
1618
private final static String CARD_API_TICKET_KEY = "wechat_card_api_ticket:";
1719

18-
protected final JedisPool jedisPool;
20+
protected final Pool<Jedis> jedisPool;
21+
/**
22+
* redis 存储的 key 的前缀,可为空
23+
*/
24+
private String keyPrefix;
1925
private String componentVerifyTicketKey;
2026
private String componentAccessTokenKey;
2127
private String authorizerRefreshTokenKey;
2228
private String authorizerAccessTokenKey;
2329
private String jsapiTicketKey;
2430
private String cardApiTicket;
2531

32+
public WxOpenInRedisConfigStorage(Pool<Jedis> jedisPool) {
33+
this.jedisPool = jedisPool;
34+
}
35+
36+
public WxOpenInRedisConfigStorage(Pool<Jedis> jedisPool, String keyPrefix) {
37+
this.jedisPool = jedisPool;
38+
this.keyPrefix = keyPrefix;
39+
}
40+
2641
public WxOpenInRedisConfigStorage(JedisPool jedisPool) {
2742
this.jedisPool = jedisPool;
2843
}
2944

3045
@Override
3146
public void setComponentAppId(String componentAppId) {
3247
super.setComponentAppId(componentAppId);
33-
this.componentVerifyTicketKey = COMPONENT_VERIFY_TICKET_KEY.concat(componentAppId);
34-
this.componentAccessTokenKey = COMPONENT_ACCESS_TOKEN_KEY.concat(componentAppId);
35-
this.authorizerRefreshTokenKey = AUTHORIZER_REFRESH_TOKEN_KEY.concat(componentAppId);
36-
this.authorizerAccessTokenKey = AUTHORIZER_ACCESS_TOKEN_KEY.concat(componentAppId);
48+
String prefix = StringUtils.isBlank(keyPrefix) ? "" :
49+
(StringUtils.endsWith(keyPrefix, ":") ? keyPrefix : (keyPrefix + ":"));
50+
componentVerifyTicketKey = prefix + COMPONENT_VERIFY_TICKET_KEY.concat(componentAppId);
51+
componentAccessTokenKey = prefix + COMPONENT_ACCESS_TOKEN_KEY.concat(componentAppId);
52+
authorizerRefreshTokenKey = prefix + AUTHORIZER_REFRESH_TOKEN_KEY.concat(componentAppId);
53+
authorizerAccessTokenKey = prefix + AUTHORIZER_ACCESS_TOKEN_KEY.concat(componentAppId);
3754
this.jsapiTicketKey = JSAPI_TICKET_KEY.concat(componentAppId);
3855
this.cardApiTicket = CARD_API_TICKET_KEY.concat(componentAppId);
3956
}

0 commit comments

Comments
 (0)