11package me .chanjar .weixin .open .api .impl ;
22
3+ import org .apache .commons .lang3 .StringUtils ;
34import redis .clients .jedis .Jedis ;
45import 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