99
1010/**
1111 * Jedis client implementor for wechat config storage
12- *
12+ *
1313 * @author gaigeshen
1414 */
1515public class WxCpJedisConfigStorage implements WxCpConfigStorage {
@@ -41,42 +41,37 @@ public class WxCpJedisConfigStorage implements WxCpConfigStorage {
4141 /* Redis clients pool */
4242 private final JedisPool jedisPool ;
4343
44- /**
45- *
46- *
47- * @param jedis
48- */
4944 public WxCpJedisConfigStorage (String host , int port ) {
5045 this .jedisPool = new JedisPool (host , port );
5146 }
52-
47+
5348 /**
54- *
49+ *
5550 * This method will be destroy jedis pool
5651 */
5752 public void destroy () {
5853 this .jedisPool .destroy ();
5954 }
60-
55+
6156 @ Override
6257 public String getAccessToken () {
6358 try (Jedis jedis = this .jedisPool .getResource ()) {
6459 return jedis .get (ACCESS_TOKEN_KEY );
6560 }
6661 }
67-
62+
6863 @ Override
6964 public boolean isAccessTokenExpired () {
7065 try (Jedis jedis = this .jedisPool .getResource ()) {
7166 String expiresTimeStr = jedis .get (ACCESS_TOKEN_EXPIRES_TIME_KEY );
72-
67+
7368 if (expiresTimeStr != null ) {
7469 Long expiresTime = Long .parseLong (expiresTimeStr );
7570 return System .currentTimeMillis () > expiresTime ;
7671 }
77-
72+
7873 return true ;
79-
74+
8075 }
8176 }
8277
@@ -96,7 +91,7 @@ public synchronized void updateAccessToken(WxAccessToken accessToken) {
9691 public synchronized void updateAccessToken (String accessToken , int expiresInSeconds ) {
9792 try (Jedis jedis = this .jedisPool .getResource ()) {
9893 jedis .set (ACCESS_TOKEN_KEY , accessToken );
99-
94+
10095 jedis .set (ACCESS_TOKEN_EXPIRES_TIME_KEY ,
10196 (System .currentTimeMillis () + (expiresInSeconds - 200 ) * 1000L ) + "" );
10297 }
@@ -111,17 +106,17 @@ public String getJsapiTicket() {
111106
112107 @ Override
113108 public boolean isJsapiTicketExpired () {
114-
109+
115110 try (Jedis jedis = this .jedisPool .getResource ()) {
116111 String expiresTimeStr = jedis .get (JS_API_TICKET_EXPIRES_TIME_KEY );
117-
112+
118113 if (expiresTimeStr != null ) {
119114 Long expiresTime = Long .parseLong (expiresTimeStr );
120115 return System .currentTimeMillis () > expiresTime ;
121116 }
122-
117+
123118 return true ;
124-
119+
125120 }
126121 }
127122
@@ -134,14 +129,14 @@ public void expireJsapiTicket() {
134129
135130 @ Override
136131 public synchronized void updateJsapiTicket (String jsapiTicket , int expiresInSeconds ) {
137-
132+
138133 try (Jedis jedis = this .jedisPool .getResource ()) {
139134 jedis .set (JS_API_TICKET_KEY , jsapiTicket );
140-
135+
141136 jedis .set (JS_API_TICKET_EXPIRES_TIME_KEY ,
142137 (System .currentTimeMillis () + (expiresInSeconds - 200 ) * 1000L + "" ));
143138 }
144-
139+
145140 }
146141
147142 @ Override
@@ -173,14 +168,14 @@ public String getAesKey() {
173168 public long getExpiresTime () {
174169 try (Jedis jedis = this .jedisPool .getResource ()) {
175170 String expiresTimeStr = jedis .get (ACCESS_TOKEN_EXPIRES_TIME_KEY );
176-
171+
177172 if (expiresTimeStr != null ) {
178173 Long expiresTime = Long .parseLong (expiresTimeStr );
179174 return expiresTime ;
180175 }
181-
176+
182177 return 0L ;
183-
178+
184179 }
185180 }
186181
@@ -240,7 +235,7 @@ public void setAgentId(String agentId) {
240235 }
241236
242237 // ============================ Setters below
243-
238+
244239 public void setOauth2redirectUri (String oauth2redirectUri ) {
245240 this .oauth2redirectUri = oauth2redirectUri ;
246241 }
0 commit comments