9
9
10
10
/**
11
11
* Jedis client implementor for wechat config storage
12
- *
12
+ *
13
13
* @author gaigeshen
14
14
*/
15
15
public class WxCpJedisConfigStorage implements WxCpConfigStorage {
@@ -41,42 +41,37 @@ public class WxCpJedisConfigStorage implements WxCpConfigStorage {
41
41
/* Redis clients pool */
42
42
private final JedisPool jedisPool ;
43
43
44
- /**
45
- *
46
- *
47
- * @param jedis
48
- */
49
44
public WxCpJedisConfigStorage (String host , int port ) {
50
45
this .jedisPool = new JedisPool (host , port );
51
46
}
52
-
47
+
53
48
/**
54
- *
49
+ *
55
50
* This method will be destroy jedis pool
56
51
*/
57
52
public void destroy () {
58
53
this .jedisPool .destroy ();
59
54
}
60
-
55
+
61
56
@ Override
62
57
public String getAccessToken () {
63
58
try (Jedis jedis = this .jedisPool .getResource ()) {
64
59
return jedis .get (ACCESS_TOKEN_KEY );
65
60
}
66
61
}
67
-
62
+
68
63
@ Override
69
64
public boolean isAccessTokenExpired () {
70
65
try (Jedis jedis = this .jedisPool .getResource ()) {
71
66
String expiresTimeStr = jedis .get (ACCESS_TOKEN_EXPIRES_TIME_KEY );
72
-
67
+
73
68
if (expiresTimeStr != null ) {
74
69
Long expiresTime = Long .parseLong (expiresTimeStr );
75
70
return System .currentTimeMillis () > expiresTime ;
76
71
}
77
-
72
+
78
73
return true ;
79
-
74
+
80
75
}
81
76
}
82
77
@@ -96,7 +91,7 @@ public synchronized void updateAccessToken(WxAccessToken accessToken) {
96
91
public synchronized void updateAccessToken (String accessToken , int expiresInSeconds ) {
97
92
try (Jedis jedis = this .jedisPool .getResource ()) {
98
93
jedis .set (ACCESS_TOKEN_KEY , accessToken );
99
-
94
+
100
95
jedis .set (ACCESS_TOKEN_EXPIRES_TIME_KEY ,
101
96
(System .currentTimeMillis () + (expiresInSeconds - 200 ) * 1000L ) + "" );
102
97
}
@@ -111,17 +106,17 @@ public String getJsapiTicket() {
111
106
112
107
@ Override
113
108
public boolean isJsapiTicketExpired () {
114
-
109
+
115
110
try (Jedis jedis = this .jedisPool .getResource ()) {
116
111
String expiresTimeStr = jedis .get (JS_API_TICKET_EXPIRES_TIME_KEY );
117
-
112
+
118
113
if (expiresTimeStr != null ) {
119
114
Long expiresTime = Long .parseLong (expiresTimeStr );
120
115
return System .currentTimeMillis () > expiresTime ;
121
116
}
122
-
117
+
123
118
return true ;
124
-
119
+
125
120
}
126
121
}
127
122
@@ -134,14 +129,14 @@ public void expireJsapiTicket() {
134
129
135
130
@ Override
136
131
public synchronized void updateJsapiTicket (String jsapiTicket , int expiresInSeconds ) {
137
-
132
+
138
133
try (Jedis jedis = this .jedisPool .getResource ()) {
139
134
jedis .set (JS_API_TICKET_KEY , jsapiTicket );
140
-
135
+
141
136
jedis .set (JS_API_TICKET_EXPIRES_TIME_KEY ,
142
137
(System .currentTimeMillis () + (expiresInSeconds - 200 ) * 1000L + "" ));
143
138
}
144
-
139
+
145
140
}
146
141
147
142
@ Override
@@ -173,14 +168,14 @@ public String getAesKey() {
173
168
public long getExpiresTime () {
174
169
try (Jedis jedis = this .jedisPool .getResource ()) {
175
170
String expiresTimeStr = jedis .get (ACCESS_TOKEN_EXPIRES_TIME_KEY );
176
-
171
+
177
172
if (expiresTimeStr != null ) {
178
173
Long expiresTime = Long .parseLong (expiresTimeStr );
179
174
return expiresTime ;
180
175
}
181
-
176
+
182
177
return 0L ;
183
-
178
+
184
179
}
185
180
}
186
181
@@ -240,7 +235,7 @@ public void setAgentId(String agentId) {
240
235
}
241
236
242
237
// ============================ Setters below
243
-
238
+
244
239
public void setOauth2redirectUri (String oauth2redirectUri ) {
245
240
this .oauth2redirectUri = oauth2redirectUri ;
246
241
}
0 commit comments