diff --git a/CHANGE.md b/CHANGE.md index 7d721ed0..eb0234ae 100644 --- a/CHANGE.md +++ b/CHANGE.md @@ -303,4 +303,6 @@ * 2015-05-30 - **大的调整:去掉httpclient依赖** \ No newline at end of file + + **去掉httpclient依赖** + + + **去掉redis依赖** \ No newline at end of file diff --git a/weixin4j-base/pom.xml b/weixin4j-base/pom.xml index c37b07b8..aab4834d 100644 --- a/weixin4j-base/pom.xml +++ b/weixin4j-base/pom.xml @@ -22,10 +22,5 @@ fastjson 1.2.3 - - redis.clients - jedis - 2.6.0 - \ No newline at end of file diff --git a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/token/RedisTokenHolder.java b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/token/RedisTokenHolder.java deleted file mode 100644 index 5f7bbd29..00000000 --- a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/token/RedisTokenHolder.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.foxinmy.weixin4j.token; - -import redis.clients.jedis.Jedis; -import redis.clients.jedis.JedisPool; -import redis.clients.jedis.JedisPoolConfig; -import redis.clients.jedis.exceptions.JedisException; - -import com.foxinmy.weixin4j.exception.WeixinException; -import com.foxinmy.weixin4j.model.Token; -import com.foxinmy.weixin4j.util.StringUtil; - -/** - * 用REDIS保存TOKEN - * - * @className RedisTokenHolder - * @author jy - * @date 2015年1月9日 - * @since JDK 1.7 - * @see com.foxinmy.weixin4j.token.TokenCreator - */ -public class RedisTokenHolder implements TokenHolder { - - private JedisPool jedisPool; - private final TokenCreator tokenCreator; - - public final static int MAX_TOTAL = 50; - public final static int MAX_IDLE = 5; - public final static int MAX_WAIT_MILLIS = 2000; - public final static boolean TEST_ON_BORROW = false; - public final static boolean TEST_ON_RETURN = true; - - public RedisTokenHolder(TokenCreator tokenCreator) { - this("localhost", 6379, tokenCreator); - } - - public RedisTokenHolder(String host, int port, TokenCreator tokenCreator) { - JedisPoolConfig jedisPoolConfig = new JedisPoolConfig(); - jedisPoolConfig.setMaxTotal(MAX_TOTAL); - jedisPoolConfig.setMaxIdle(MAX_IDLE); - jedisPoolConfig.setMaxWaitMillis(MAX_WAIT_MILLIS); - jedisPoolConfig.setTestOnBorrow(TEST_ON_BORROW); - jedisPoolConfig.setTestOnReturn(TEST_ON_RETURN); - this.jedisPool = new JedisPool(jedisPoolConfig, host, port); - this.tokenCreator = tokenCreator; - } - - public RedisTokenHolder(String host, int port, - JedisPoolConfig jedisPoolConfig, TokenCreator tokenCreator) { - this(new JedisPool(jedisPoolConfig, host, port), tokenCreator); - } - - public RedisTokenHolder(JedisPool jedisPool, TokenCreator tokenCreator) { - this.jedisPool = jedisPool; - this.tokenCreator = tokenCreator; - } - - @Override - public Token getToken() throws WeixinException { - Token token = null; - Jedis jedis = null; - try { - jedis = jedisPool.getResource(); - String cacheKey = tokenCreator.getCacheKey(); - String accessToken = jedis.get(cacheKey); - if (StringUtil.isBlank(accessToken)) { - token = tokenCreator.createToken(); - jedis.setex(cacheKey, (int) token.getExpiresIn(), - token.getAccessToken()); - } else { - token = new Token(accessToken); - } - } catch (JedisException e) { - jedisPool.returnBrokenResource(jedis); - } finally { - jedisPool.returnResource(jedis); - } - return token; - } -} diff --git a/weixin4j-mp/README.md b/weixin4j-mp/README.md index 76b6de14..a0b165d8 100644 --- a/weixin4j-mp/README.md +++ b/weixin4j-mp/README.md @@ -91,7 +91,7 @@ weixin.properties说明 // weixinProxy = new WeixinProxy(weixinAccount); weixinProxy.getUser(openId); -> 针对`token`存储有两种方案,`File存储`/`Redis存储`,当然也可自己实现`TokenHolder`,默认使用文件(xml)的方式保存token,如果环境中支持`redis`,建议使用`RedisTokenHolder`. +> 针对`token`存储有两种方案,`File存储`/`Redis存储`,当然也可自己实现`TokenHolder`,默认使用文件(xml)的方式保存token,如果环境中支持`redis`,建议使用(RedisTokenHolder)[https://github.com/foxinmy/weixin4j/wiki/%E7%94%A8redis%E4%BF%9D%E5%AD%98token]. > > WeixinProxy weixinProxy = new WeixinProxy(new RedisTokenHolder()); diff --git a/weixin4j-qy/README.md b/weixin4j-qy/README.md index a63060dd..eb1a54be 100644 --- a/weixin4j-qy/README.md +++ b/weixin4j-qy/README.md @@ -58,8 +58,8 @@ weixin.properties说明 // weixinProxy = new WeixinProxy(weixinAccount); weixinProxy.getUser(userid); -> 针对`token`存储有两种方案,`File存储`/`Redis存储`,当然也可自己实现`TokenHolder`,默认使用文件(xml)的方式保存token,如果环境中支持`redis`,建议使用`RedisTokenHolder`. -> +> 针对`token`存储有两种方案,`File存储`/`Redis存储`,当然也可自己实现`TokenHolder`,默认使用文件(xml)的方式保存token,如果环境中支持`redis`,建议使用(RedisTokenHolder)[https://github.com/foxinmy/weixin4j/wiki/%E7%94%A8redis%E4%BF%9D%E5%AD%98token]. + > WeixinProxy weixinProxy = new WeixinProxy(new RedisTokenHolder()); > // weixinProxy = new WeixinProxy(new RedisTokenHolder(weixinAccount));