@@ -37,7 +37,7 @@ public class WxMpServiceImpl implements WxMpService {
3737
3838 protected final Logger log = LoggerFactory .getLogger (this .getClass ());
3939 protected WxSessionManager sessionManager = new StandardSessionManager ();
40- private WxMpConfigStorage configStorage ;
40+ private WxMpConfigStorage wxMpConfigStorage ;
4141 private WxMpKefuService kefuService = new WxMpKefuServiceImpl (this );
4242 private WxMpMaterialService materialService = new WxMpMaterialServiceImpl (this );
4343 private WxMpMenuService menuService = new WxMpMenuServiceImpl (this );
@@ -59,7 +59,7 @@ public class WxMpServiceImpl implements WxMpService {
5959 @ Override
6060 public boolean checkSignature (String timestamp , String nonce , String signature ) {
6161 try {
62- return SHA1 .gen (this .configStorage .getToken (), timestamp , nonce )
62+ return SHA1 .gen (this .wxMpConfigStorage .getToken (), timestamp , nonce )
6363 .equals (signature );
6464 } catch (Exception e ) {
6565 return false ;
@@ -73,18 +73,18 @@ public String getAccessToken() throws WxErrorException {
7373
7474 @ Override
7575 public String getAccessToken (boolean forceRefresh ) throws WxErrorException {
76- Lock lock = this .configStorage .getAccessTokenLock ();
76+ Lock lock = this .wxMpConfigStorage .getAccessTokenLock ();
7777 try {
7878 lock .lock ();
7979
8080 if (forceRefresh ) {
81- this .configStorage .expireAccessToken ();
81+ this .wxMpConfigStorage .expireAccessToken ();
8282 }
8383
84- if (this .configStorage .isAccessTokenExpired ()) {
84+ if (this .wxMpConfigStorage .isAccessTokenExpired ()) {
8585 String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential" +
86- "&appid=" + this .configStorage .getAppId () + "&secret="
87- + this .configStorage .getSecret ();
86+ "&appid=" + this .wxMpConfigStorage .getAppId () + "&secret="
87+ + this .wxMpConfigStorage .getSecret ();
8888 try {
8989 HttpGet httpGet = new HttpGet (url );
9090 if (this .httpProxy != null ) {
@@ -98,7 +98,7 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException {
9898 throw new WxErrorException (error );
9999 }
100100 WxAccessToken accessToken = WxAccessToken .fromJson (resultContent );
101- this .configStorage .updateAccessToken (accessToken .getAccessToken (),
101+ this .wxMpConfigStorage .updateAccessToken (accessToken .getAccessToken (),
102102 accessToken .getExpiresIn ());
103103 } finally {
104104 httpGet .releaseConnection ();
@@ -110,7 +110,7 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException {
110110 } finally {
111111 lock .unlock ();
112112 }
113- return this .configStorage .getAccessToken ();
113+ return this .wxMpConfigStorage .getAccessToken ();
114114 }
115115
116116 @ Override
@@ -120,27 +120,27 @@ public String getJsapiTicket() throws WxErrorException {
120120
121121 @ Override
122122 public String getJsapiTicket (boolean forceRefresh ) throws WxErrorException {
123- Lock lock = this .configStorage .getJsapiTicketLock ();
123+ Lock lock = this .wxMpConfigStorage .getJsapiTicketLock ();
124124 try {
125125 lock .lock ();
126126
127127 if (forceRefresh ) {
128- this .configStorage .expireJsapiTicket ();
128+ this .wxMpConfigStorage .expireJsapiTicket ();
129129 }
130130
131- if (this .configStorage .isJsapiTicketExpired ()) {
131+ if (this .wxMpConfigStorage .isJsapiTicketExpired ()) {
132132 String url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi" ;
133133 String responseContent = execute (new SimpleGetRequestExecutor (), url , null );
134134 JsonElement tmpJsonElement = JSON_PARSER .parse (responseContent );
135135 JsonObject tmpJsonObject = tmpJsonElement .getAsJsonObject ();
136136 String jsapiTicket = tmpJsonObject .get ("ticket" ).getAsString ();
137137 int expiresInSeconds = tmpJsonObject .get ("expires_in" ).getAsInt ();
138- this .configStorage .updateJsapiTicket (jsapiTicket , expiresInSeconds );
138+ this .wxMpConfigStorage .updateJsapiTicket (jsapiTicket , expiresInSeconds );
139139 }
140140 } finally {
141141 lock .unlock ();
142142 }
143- return this .configStorage .getJsapiTicket ();
143+ return this .wxMpConfigStorage .getJsapiTicket ();
144144 }
145145
146146 @ Override
@@ -151,7 +151,7 @@ public WxJsapiSignature createJsapiSignature(String url) throws WxErrorException
151151 String signature = SHA1 .genWithAmple ("jsapi_ticket=" + jsapiTicket ,
152152 "noncestr=" + noncestr , "timestamp=" + timestamp , "url=" + url );
153153 WxJsapiSignature jsapiSignature = new WxJsapiSignature ();
154- jsapiSignature .setAppid (this .configStorage .getAppId ());
154+ jsapiSignature .setAppid (this .wxMpConfigStorage .getAppId ());
155155 jsapiSignature .setTimestamp (timestamp );
156156 jsapiSignature .setNoncestr (noncestr );
157157 jsapiSignature .setUrl (url );
@@ -216,7 +216,7 @@ public WxMpSemanticQueryResult semanticQuery(WxMpSemanticQuery semanticQuery) th
216216 public String oauth2buildAuthorizationUrl (String redirectURI , String scope , String state ) {
217217 StringBuilder url = new StringBuilder ();
218218 url .append ("https://open.weixin.qq.com/connect/oauth2/authorize?" );
219- url .append ("appid=" ).append (this .configStorage .getAppId ());
219+ url .append ("appid=" ).append (this .wxMpConfigStorage .getAppId ());
220220 url .append ("&redirect_uri=" ).append (URIUtil .encodeURIComponent (redirectURI ));
221221 url .append ("&response_type=code" );
222222 url .append ("&scope=" ).append (scope );
@@ -232,7 +232,7 @@ public String buildQrConnectUrl(String redirectURI, String scope,
232232 String state ) {
233233 StringBuilder url = new StringBuilder ();
234234 url .append ("https://open.weixin.qq.com/connect/qrconnect?" );
235- url .append ("appid=" ).append (this .configStorage .getAppId ());
235+ url .append ("appid=" ).append (this .wxMpConfigStorage .getAppId ());
236236 url .append ("&redirect_uri=" ).append (URIUtil .encodeURIComponent (redirectURI ));
237237 url .append ("&response_type=code" );
238238 url .append ("&scope=" ).append (scope );
@@ -258,8 +258,8 @@ private WxMpOAuth2AccessToken getOAuth2AccessToken(StringBuilder url) throws WxE
258258 public WxMpOAuth2AccessToken oauth2getAccessToken (String code ) throws WxErrorException {
259259 StringBuilder url = new StringBuilder ();
260260 url .append ("https://api.weixin.qq.com/sns/oauth2/access_token?" );
261- url .append ("appid=" ).append (this .configStorage .getAppId ());
262- url .append ("&secret=" ).append (this .configStorage .getSecret ());
261+ url .append ("appid=" ).append (this .wxMpConfigStorage .getAppId ());
262+ url .append ("&secret=" ).append (this .wxMpConfigStorage .getSecret ());
263263 url .append ("&code=" ).append (code );
264264 url .append ("&grant_type=authorization_code" );
265265
@@ -270,7 +270,7 @@ public WxMpOAuth2AccessToken oauth2getAccessToken(String code) throws WxErrorExc
270270 public WxMpOAuth2AccessToken oauth2refreshAccessToken (String refreshToken ) throws WxErrorException {
271271 StringBuilder url = new StringBuilder ();
272272 url .append ("https://api.weixin.qq.com/sns/oauth2/refresh_token?" );
273- url .append ("appid=" ).append (this .configStorage .getAppId ());
273+ url .append ("appid=" ).append (this .wxMpConfigStorage .getAppId ());
274274 url .append ("&grant_type=refresh_token" );
275275 url .append ("&refresh_token=" ).append (refreshToken );
276276
@@ -397,8 +397,8 @@ protected synchronized <T, E> T executeInternal(RequestExecutor<T, E> executor,
397397 */
398398 if (error .getErrorCode () == 42001 || error .getErrorCode () == 40001 ) {
399399 // 强制设置wxMpConfigStorage它的access token过期了,这样在下一次请求里就会刷新access token
400- this .configStorage .expireAccessToken ();
401- if (this .configStorage .autoRefreshToken ()) {
400+ this .wxMpConfigStorage .expireAccessToken ();
401+ if (this .wxMpConfigStorage .autoRefreshToken ()) {
402402 return this .execute (executor , uri , data );
403403 }
404404 }
@@ -424,39 +424,39 @@ public CloseableHttpClient getHttpclient() {
424424 }
425425
426426 private void initHttpClient () {
427- ApacheHttpClientBuilder apacheHttpClientBuilder = this .configStorage
427+ ApacheHttpClientBuilder apacheHttpClientBuilder = this .wxMpConfigStorage
428428 .getApacheHttpClientBuilder ();
429429 if (null == apacheHttpClientBuilder ) {
430430 apacheHttpClientBuilder = DefaultApacheHttpClientBuilder .get ();
431431 }
432432
433- apacheHttpClientBuilder .httpProxyHost (this .configStorage .getHttpProxyHost ())
434- .httpProxyPort (this .configStorage .getHttpProxyPort ())
435- .httpProxyUsername (this .configStorage .getHttpProxyUsername ())
436- .httpProxyPassword (this .configStorage .getHttpProxyPassword ());
433+ apacheHttpClientBuilder .httpProxyHost (this .wxMpConfigStorage .getHttpProxyHost ())
434+ .httpProxyPort (this .wxMpConfigStorage .getHttpProxyPort ())
435+ .httpProxyUsername (this .wxMpConfigStorage .getHttpProxyUsername ())
436+ .httpProxyPassword (this .wxMpConfigStorage .getHttpProxyPassword ());
437437
438- // if (this.configStorage .getSSLContext() != null) {
438+ // if (this.wxMpConfigStorage .getSSLContext() != null) {
439439 // SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
440- // this.configStorage .getSSLContext(), new String[] { "TLSv1" }, null,
440+ // this.wxMpConfigStorage .getSSLContext(), new String[] { "TLSv1" }, null,
441441 // new DefaultHostnameVerifier());
442442 // apacheHttpClientBuilder.sslConnectionSocketFactory(sslsf);
443443 // }
444444
445- if (this .configStorage .getHttpProxyHost () != null && this .configStorage .getHttpProxyPort () > 0 ) {
446- this .httpProxy = new HttpHost (this .configStorage .getHttpProxyHost (), this .configStorage .getHttpProxyPort ());
445+ if (this .wxMpConfigStorage .getHttpProxyHost () != null && this .wxMpConfigStorage .getHttpProxyPort () > 0 ) {
446+ this .httpProxy = new HttpHost (this .wxMpConfigStorage .getHttpProxyHost (), this .wxMpConfigStorage .getHttpProxyPort ());
447447 }
448448
449449 this .httpClient = apacheHttpClientBuilder .build ();
450450 }
451451
452452 @ Override
453453 public WxMpConfigStorage getWxMpConfigStorage () {
454- return this .configStorage ;
454+ return this .wxMpConfigStorage ;
455455 }
456456
457457 @ Override
458458 public void setWxMpConfigStorage (WxMpConfigStorage wxConfigProvider ) {
459- this .configStorage = wxConfigProvider ;
459+ this .wxMpConfigStorage = wxConfigProvider ;
460460 this .initHttpClient ();
461461 }
462462
0 commit comments