@@ -55,7 +55,7 @@ public class WxMpServiceImpl implements WxMpService {
55
55
@ Override
56
56
public boolean checkSignature (String timestamp , String nonce , String signature ) {
57
57
try {
58
- return SHA1 .gen (this .wxMpConfigStorage .getToken (), timestamp , nonce )
58
+ return SHA1 .gen (this .getWxMpConfigStorage () .getToken (), timestamp , nonce )
59
59
.equals (signature );
60
60
} catch (Exception e ) {
61
61
return false ;
@@ -69,18 +69,18 @@ public String getAccessToken() throws WxErrorException {
69
69
70
70
@ Override
71
71
public String getAccessToken (boolean forceRefresh ) throws WxErrorException {
72
- Lock lock = this .wxMpConfigStorage .getAccessTokenLock ();
72
+ Lock lock = this .getWxMpConfigStorage () .getAccessTokenLock ();
73
73
try {
74
74
lock .lock ();
75
75
76
76
if (forceRefresh ) {
77
- this .wxMpConfigStorage .expireAccessToken ();
77
+ this .getWxMpConfigStorage () .expireAccessToken ();
78
78
}
79
79
80
- if (this .wxMpConfigStorage .isAccessTokenExpired ()) {
80
+ if (this .getWxMpConfigStorage () .isAccessTokenExpired ()) {
81
81
String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential" +
82
- "&appid=" + this .wxMpConfigStorage .getAppId () + "&secret="
83
- + this .wxMpConfigStorage .getSecret ();
82
+ "&appid=" + this .getWxMpConfigStorage () .getAppId () + "&secret="
83
+ + this .getWxMpConfigStorage () .getSecret ();
84
84
try {
85
85
HttpGet httpGet = new HttpGet (url );
86
86
if (this .httpProxy != null ) {
@@ -94,7 +94,7 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException {
94
94
throw new WxErrorException (error );
95
95
}
96
96
WxAccessToken accessToken = WxAccessToken .fromJson (resultContent );
97
- this .wxMpConfigStorage .updateAccessToken (accessToken .getAccessToken (),
97
+ this .getWxMpConfigStorage () .updateAccessToken (accessToken .getAccessToken (),
98
98
accessToken .getExpiresIn ());
99
99
} finally {
100
100
httpGet .releaseConnection ();
@@ -106,7 +106,7 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException {
106
106
} finally {
107
107
lock .unlock ();
108
108
}
109
- return this .wxMpConfigStorage .getAccessToken ();
109
+ return this .getWxMpConfigStorage () .getAccessToken ();
110
110
}
111
111
112
112
@ Override
@@ -116,27 +116,27 @@ public String getJsapiTicket() throws WxErrorException {
116
116
117
117
@ Override
118
118
public String getJsapiTicket (boolean forceRefresh ) throws WxErrorException {
119
- Lock lock = this .wxMpConfigStorage .getJsapiTicketLock ();
119
+ Lock lock = this .getWxMpConfigStorage () .getJsapiTicketLock ();
120
120
try {
121
121
lock .lock ();
122
122
123
123
if (forceRefresh ) {
124
- this .wxMpConfigStorage .expireJsapiTicket ();
124
+ this .getWxMpConfigStorage () .expireJsapiTicket ();
125
125
}
126
126
127
- if (this .wxMpConfigStorage .isJsapiTicketExpired ()) {
127
+ if (this .getWxMpConfigStorage () .isJsapiTicketExpired ()) {
128
128
String url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi" ;
129
129
String responseContent = execute (new SimpleGetRequestExecutor (), url , null );
130
130
JsonElement tmpJsonElement = JSON_PARSER .parse (responseContent );
131
131
JsonObject tmpJsonObject = tmpJsonElement .getAsJsonObject ();
132
132
String jsapiTicket = tmpJsonObject .get ("ticket" ).getAsString ();
133
133
int expiresInSeconds = tmpJsonObject .get ("expires_in" ).getAsInt ();
134
- this .wxMpConfigStorage .updateJsapiTicket (jsapiTicket , expiresInSeconds );
134
+ this .getWxMpConfigStorage () .updateJsapiTicket (jsapiTicket , expiresInSeconds );
135
135
}
136
136
} finally {
137
137
lock .unlock ();
138
138
}
139
- return this .wxMpConfigStorage .getJsapiTicket ();
139
+ return this .getWxMpConfigStorage () .getJsapiTicket ();
140
140
}
141
141
142
142
@ Override
@@ -147,7 +147,7 @@ public WxJsapiSignature createJsapiSignature(String url) throws WxErrorException
147
147
String signature = SHA1 .genWithAmple ("jsapi_ticket=" + jsapiTicket ,
148
148
"noncestr=" + noncestr , "timestamp=" + timestamp , "url=" + url );
149
149
WxJsapiSignature jsapiSignature = new WxJsapiSignature ();
150
- jsapiSignature .setAppId (this .wxMpConfigStorage .getAppId ());
150
+ jsapiSignature .setAppId (this .getWxMpConfigStorage () .getAppId ());
151
151
jsapiSignature .setTimestamp (timestamp );
152
152
jsapiSignature .setNonceStr (noncestr );
153
153
jsapiSignature .setUrl (url );
@@ -212,7 +212,7 @@ public WxMpSemanticQueryResult semanticQuery(WxMpSemanticQuery semanticQuery) th
212
212
public String oauth2buildAuthorizationUrl (String redirectURI , String scope , String state ) {
213
213
StringBuilder url = new StringBuilder ();
214
214
url .append ("https://open.weixin.qq.com/connect/oauth2/authorize?" );
215
- url .append ("appid=" ).append (this .wxMpConfigStorage .getAppId ());
215
+ url .append ("appid=" ).append (this .getWxMpConfigStorage () .getAppId ());
216
216
url .append ("&redirect_uri=" ).append (URIUtil .encodeURIComponent (redirectURI ));
217
217
url .append ("&response_type=code" );
218
218
url .append ("&scope=" ).append (scope );
@@ -228,7 +228,7 @@ public String buildQrConnectUrl(String redirectURI, String scope,
228
228
String state ) {
229
229
StringBuilder url = new StringBuilder ();
230
230
url .append ("https://open.weixin.qq.com/connect/qrconnect?" );
231
- url .append ("appid=" ).append (this .wxMpConfigStorage .getAppId ());
231
+ url .append ("appid=" ).append (this .getWxMpConfigStorage () .getAppId ());
232
232
url .append ("&redirect_uri=" ).append (URIUtil .encodeURIComponent (redirectURI ));
233
233
url .append ("&response_type=code" );
234
234
url .append ("&scope=" ).append (scope );
@@ -254,8 +254,8 @@ private WxMpOAuth2AccessToken getOAuth2AccessToken(StringBuilder url) throws WxE
254
254
public WxMpOAuth2AccessToken oauth2getAccessToken (String code ) throws WxErrorException {
255
255
StringBuilder url = new StringBuilder ();
256
256
url .append ("https://api.weixin.qq.com/sns/oauth2/access_token?" );
257
- url .append ("appid=" ).append (this .wxMpConfigStorage .getAppId ());
258
- url .append ("&secret=" ).append (this .wxMpConfigStorage .getSecret ());
257
+ url .append ("appid=" ).append (this .getWxMpConfigStorage () .getAppId ());
258
+ url .append ("&secret=" ).append (this .getWxMpConfigStorage () .getSecret ());
259
259
url .append ("&code=" ).append (code );
260
260
url .append ("&grant_type=authorization_code" );
261
261
@@ -266,7 +266,7 @@ public WxMpOAuth2AccessToken oauth2getAccessToken(String code) throws WxErrorExc
266
266
public WxMpOAuth2AccessToken oauth2refreshAccessToken (String refreshToken ) throws WxErrorException {
267
267
StringBuilder url = new StringBuilder ();
268
268
url .append ("https://api.weixin.qq.com/sns/oauth2/refresh_token?" );
269
- url .append ("appid=" ).append (this .wxMpConfigStorage .getAppId ());
269
+ url .append ("appid=" ).append (this .getWxMpConfigStorage () .getAppId ());
270
270
url .append ("&grant_type=refresh_token" );
271
271
url .append ("&refresh_token=" ).append (refreshToken );
272
272
@@ -393,8 +393,8 @@ protected synchronized <T, E> T executeInternal(RequestExecutor<T, E> executor,
393
393
*/
394
394
if (error .getErrorCode () == 42001 || error .getErrorCode () == 40001 ) {
395
395
// 强制设置wxMpConfigStorage它的access token过期了,这样在下一次请求里就会刷新access token
396
- this .wxMpConfigStorage .expireAccessToken ();
397
- if (this .wxMpConfigStorage .autoRefreshToken ()) {
396
+ this .getWxMpConfigStorage () .expireAccessToken ();
397
+ if (this .getWxMpConfigStorage () .autoRefreshToken ()) {
398
398
return this .execute (executor , uri , data );
399
399
}
400
400
}
@@ -426,20 +426,20 @@ private void initHttpClient() {
426
426
apacheHttpClientBuilder = DefaultApacheHttpClientBuilder .get ();
427
427
}
428
428
429
- apacheHttpClientBuilder .httpProxyHost (this .wxMpConfigStorage .getHttpProxyHost ())
430
- .httpProxyPort (this .wxMpConfigStorage .getHttpProxyPort ())
431
- .httpProxyUsername (this .wxMpConfigStorage .getHttpProxyUsername ())
432
- .httpProxyPassword (this .wxMpConfigStorage .getHttpProxyPassword ());
429
+ apacheHttpClientBuilder .httpProxyHost (this .getWxMpConfigStorage () .getHttpProxyHost ())
430
+ .httpProxyPort (this .getWxMpConfigStorage () .getHttpProxyPort ())
431
+ .httpProxyUsername (this .getWxMpConfigStorage () .getHttpProxyUsername ())
432
+ .httpProxyPassword (this .getWxMpConfigStorage () .getHttpProxyPassword ());
433
433
434
- // if (this.wxMpConfigStorage .getSSLContext() != null) {
434
+ // if (this.getWxMpConfigStorage() .getSSLContext() != null) {
435
435
// SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
436
- // this.wxMpConfigStorage .getSSLContext(), new String[] { "TLSv1" }, null,
436
+ // this.getWxMpConfigStorage() .getSSLContext(), new String[] { "TLSv1" }, null,
437
437
// new DefaultHostnameVerifier());
438
438
// apacheHttpClientBuilder.sslConnectionSocketFactory(sslsf);
439
439
// }
440
440
441
- if (this .wxMpConfigStorage .getHttpProxyHost () != null && this .wxMpConfigStorage .getHttpProxyPort () > 0 ) {
442
- this .httpProxy = new HttpHost (this .wxMpConfigStorage .getHttpProxyHost (), this .wxMpConfigStorage .getHttpProxyPort ());
441
+ if (this .getWxMpConfigStorage () .getHttpProxyHost () != null && this .getWxMpConfigStorage () .getHttpProxyPort () > 0 ) {
442
+ this .httpProxy = new HttpHost (this .getWxMpConfigStorage () .getHttpProxyHost (), this .getWxMpConfigStorage () .getHttpProxyPort ());
443
443
}
444
444
445
445
this .httpClient = apacheHttpClientBuilder .build ();
0 commit comments