| @@ -9,7 +9,7 @@ import redis.clients.jedis.JedisPool; | |||||
| /** | /** | ||||
| * Jedis client implementor for wechat config storage | * Jedis client implementor for wechat config storage | ||||
| * | |||||
| * | |||||
| * @author gaigeshen | * @author gaigeshen | ||||
| */ | */ | ||||
| public class WxCpJedisConfigStorage implements WxCpConfigStorage { | public class WxCpJedisConfigStorage implements WxCpConfigStorage { | ||||
| @@ -41,42 +41,37 @@ public class WxCpJedisConfigStorage implements WxCpConfigStorage { | |||||
| /* Redis clients pool */ | /* Redis clients pool */ | ||||
| private final JedisPool jedisPool; | private final JedisPool jedisPool; | ||||
| /** | |||||
| * | |||||
| * | |||||
| * @param jedis | |||||
| */ | |||||
| public WxCpJedisConfigStorage(String host, int port) { | public WxCpJedisConfigStorage(String host, int port) { | ||||
| this.jedisPool = new JedisPool(host, port); | this.jedisPool = new JedisPool(host, port); | ||||
| } | } | ||||
| /** | /** | ||||
| * | |||||
| * | |||||
| * This method will be destroy jedis pool | * This method will be destroy jedis pool | ||||
| */ | */ | ||||
| public void destroy() { | public void destroy() { | ||||
| this.jedisPool.destroy(); | this.jedisPool.destroy(); | ||||
| } | } | ||||
| @Override | @Override | ||||
| public String getAccessToken() { | public String getAccessToken() { | ||||
| try (Jedis jedis = this.jedisPool.getResource()) { | try (Jedis jedis = this.jedisPool.getResource()) { | ||||
| return jedis.get(ACCESS_TOKEN_KEY); | return jedis.get(ACCESS_TOKEN_KEY); | ||||
| } | } | ||||
| } | } | ||||
| @Override | @Override | ||||
| public boolean isAccessTokenExpired() { | public boolean isAccessTokenExpired() { | ||||
| try (Jedis jedis = this.jedisPool.getResource()) { | try (Jedis jedis = this.jedisPool.getResource()) { | ||||
| String expiresTimeStr = jedis.get(ACCESS_TOKEN_EXPIRES_TIME_KEY); | String expiresTimeStr = jedis.get(ACCESS_TOKEN_EXPIRES_TIME_KEY); | ||||
| if (expiresTimeStr != null) { | if (expiresTimeStr != null) { | ||||
| Long expiresTime = Long.parseLong(expiresTimeStr); | Long expiresTime = Long.parseLong(expiresTimeStr); | ||||
| return System.currentTimeMillis() > expiresTime; | return System.currentTimeMillis() > expiresTime; | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| } | } | ||||
| @@ -96,7 +91,7 @@ public class WxCpJedisConfigStorage implements WxCpConfigStorage { | |||||
| public synchronized void updateAccessToken(String accessToken, int expiresInSeconds) { | public synchronized void updateAccessToken(String accessToken, int expiresInSeconds) { | ||||
| try (Jedis jedis = this.jedisPool.getResource()) { | try (Jedis jedis = this.jedisPool.getResource()) { | ||||
| jedis.set(ACCESS_TOKEN_KEY, accessToken); | jedis.set(ACCESS_TOKEN_KEY, accessToken); | ||||
| jedis.set(ACCESS_TOKEN_EXPIRES_TIME_KEY, | jedis.set(ACCESS_TOKEN_EXPIRES_TIME_KEY, | ||||
| (System.currentTimeMillis() + (expiresInSeconds - 200) * 1000L) + ""); | (System.currentTimeMillis() + (expiresInSeconds - 200) * 1000L) + ""); | ||||
| } | } | ||||
| @@ -111,17 +106,17 @@ public class WxCpJedisConfigStorage implements WxCpConfigStorage { | |||||
| @Override | @Override | ||||
| public boolean isJsapiTicketExpired() { | public boolean isJsapiTicketExpired() { | ||||
| try (Jedis jedis = this.jedisPool.getResource()) { | try (Jedis jedis = this.jedisPool.getResource()) { | ||||
| String expiresTimeStr = jedis.get(JS_API_TICKET_EXPIRES_TIME_KEY); | String expiresTimeStr = jedis.get(JS_API_TICKET_EXPIRES_TIME_KEY); | ||||
| if (expiresTimeStr != null) { | if (expiresTimeStr != null) { | ||||
| Long expiresTime = Long.parseLong(expiresTimeStr); | Long expiresTime = Long.parseLong(expiresTimeStr); | ||||
| return System.currentTimeMillis() > expiresTime; | return System.currentTimeMillis() > expiresTime; | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| } | } | ||||
| @@ -134,14 +129,14 @@ public class WxCpJedisConfigStorage implements WxCpConfigStorage { | |||||
| @Override | @Override | ||||
| public synchronized void updateJsapiTicket(String jsapiTicket, int expiresInSeconds) { | public synchronized void updateJsapiTicket(String jsapiTicket, int expiresInSeconds) { | ||||
| try (Jedis jedis = this.jedisPool.getResource()) { | try (Jedis jedis = this.jedisPool.getResource()) { | ||||
| jedis.set(JS_API_TICKET_KEY, jsapiTicket); | jedis.set(JS_API_TICKET_KEY, jsapiTicket); | ||||
| jedis.set(JS_API_TICKET_EXPIRES_TIME_KEY, | jedis.set(JS_API_TICKET_EXPIRES_TIME_KEY, | ||||
| (System.currentTimeMillis() + (expiresInSeconds - 200) * 1000L + "")); | (System.currentTimeMillis() + (expiresInSeconds - 200) * 1000L + "")); | ||||
| } | } | ||||
| } | } | ||||
| @Override | @Override | ||||
| @@ -173,14 +168,14 @@ public class WxCpJedisConfigStorage implements WxCpConfigStorage { | |||||
| public long getExpiresTime() { | public long getExpiresTime() { | ||||
| try (Jedis jedis = this.jedisPool.getResource()) { | try (Jedis jedis = this.jedisPool.getResource()) { | ||||
| String expiresTimeStr = jedis.get(ACCESS_TOKEN_EXPIRES_TIME_KEY); | String expiresTimeStr = jedis.get(ACCESS_TOKEN_EXPIRES_TIME_KEY); | ||||
| if (expiresTimeStr != null) { | if (expiresTimeStr != null) { | ||||
| Long expiresTime = Long.parseLong(expiresTimeStr); | Long expiresTime = Long.parseLong(expiresTimeStr); | ||||
| return expiresTime; | return expiresTime; | ||||
| } | } | ||||
| return 0L; | return 0L; | ||||
| } | } | ||||
| } | } | ||||
| @@ -240,7 +235,7 @@ public class WxCpJedisConfigStorage implements WxCpConfigStorage { | |||||
| } | } | ||||
| // ============================ Setters below | // ============================ Setters below | ||||
| public void setOauth2redirectUri(String oauth2redirectUri) { | public void setOauth2redirectUri(String oauth2redirectUri) { | ||||
| this.oauth2redirectUri = oauth2redirectUri; | this.oauth2redirectUri = oauth2redirectUri; | ||||
| } | } | ||||