@@ -65,7 +65,7 @@ public class WxCpServiceImpl implements WxCpService {
6565 */
6666 protected final Object globalJsapiTicketRefreshLock = new Object ();
6767
68- protected WxCpConfigStorage wxCpConfigStorage ;
68+ protected WxCpConfigStorage configStorage ;
6969
7070 protected CloseableHttpClient httpClient ;
7171
@@ -81,7 +81,7 @@ public class WxCpServiceImpl implements WxCpService {
8181 @ Override
8282 public boolean checkSignature (String msgSignature , String timestamp , String nonce , String data ) {
8383 try {
84- return SHA1 .gen (this .wxCpConfigStorage .getToken (), timestamp , nonce , data )
84+ return SHA1 .gen (this .configStorage .getToken (), timestamp , nonce , data )
8585 .equals (msgSignature );
8686 } catch (Exception e ) {
8787 return false ;
@@ -102,14 +102,14 @@ public String getAccessToken() throws WxErrorException {
102102 @ Override
103103 public String getAccessToken (boolean forceRefresh ) throws WxErrorException {
104104 if (forceRefresh ) {
105- this .wxCpConfigStorage .expireAccessToken ();
105+ this .configStorage .expireAccessToken ();
106106 }
107- if (this .wxCpConfigStorage .isAccessTokenExpired ()) {
107+ if (this .configStorage .isAccessTokenExpired ()) {
108108 synchronized (this .globalAccessTokenRefreshLock ) {
109- if (this .wxCpConfigStorage .isAccessTokenExpired ()) {
109+ if (this .configStorage .isAccessTokenExpired ()) {
110110 String url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?"
111- + "&corpid=" + this .wxCpConfigStorage .getCorpId () + "&corpsecret="
112- + this .wxCpConfigStorage .getCorpSecret ();
111+ + "&corpid=" + this .configStorage .getCorpId ()
112+ + "&corpsecret=" + this .configStorage .getCorpSecret ();
113113 try {
114114 HttpGet httpGet = new HttpGet (url );
115115 if (this .httpProxy != null ) {
@@ -129,7 +129,7 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException {
129129 throw new WxErrorException (error );
130130 }
131131 WxAccessToken accessToken = WxAccessToken .fromJson (resultContent );
132- this .wxCpConfigStorage .updateAccessToken (
132+ this .configStorage .updateAccessToken (
133133 accessToken .getAccessToken (), accessToken .getExpiresIn ());
134134 } catch (ClientProtocolException e ) {
135135 throw new RuntimeException (e );
@@ -139,7 +139,7 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException {
139139 }
140140 }
141141 }
142- return this .wxCpConfigStorage .getAccessToken ();
142+ return this .configStorage .getAccessToken ();
143143 }
144144
145145 @ Override
@@ -150,23 +150,23 @@ public String getJsapiTicket() throws WxErrorException {
150150 @ Override
151151 public String getJsapiTicket (boolean forceRefresh ) throws WxErrorException {
152152 if (forceRefresh ) {
153- this .wxCpConfigStorage .expireJsapiTicket ();
153+ this .configStorage .expireJsapiTicket ();
154154 }
155- if (this .wxCpConfigStorage .isJsapiTicketExpired ()) {
155+ if (this .configStorage .isJsapiTicketExpired ()) {
156156 synchronized (this .globalJsapiTicketRefreshLock ) {
157- if (this .wxCpConfigStorage .isJsapiTicketExpired ()) {
157+ if (this .configStorage .isJsapiTicketExpired ()) {
158158 String url = "https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket" ;
159159 String responseContent = execute (new SimpleGetRequestExecutor (), url , null );
160160 JsonElement tmpJsonElement = new JsonParser ().parse (responseContent );
161161 JsonObject tmpJsonObject = tmpJsonElement .getAsJsonObject ();
162162 String jsapiTicket = tmpJsonObject .get ("ticket" ).getAsString ();
163163 int expiresInSeconds = tmpJsonObject .get ("expires_in" ).getAsInt ();
164- this .wxCpConfigStorage .updateJsapiTicket (jsapiTicket ,
164+ this .configStorage .updateJsapiTicket (jsapiTicket ,
165165 expiresInSeconds );
166166 }
167167 }
168168 }
169- return this .wxCpConfigStorage .getJsapiTicket ();
169+ return this .configStorage .getJsapiTicket ();
170170 }
171171
172172 @ Override
@@ -187,7 +187,7 @@ public WxJsapiSignature createJsapiSignature(String url) throws WxErrorException
187187 jsapiSignature .setSignature (signature );
188188
189189 // Fixed bug
190- jsapiSignature .setAppid (this .wxCpConfigStorage .getCorpId ());
190+ jsapiSignature .setAppid (this .configStorage .getCorpId ());
191191
192192 return jsapiSignature ;
193193 }
@@ -200,19 +200,19 @@ public void messageSend(WxCpMessage message) throws WxErrorException {
200200
201201 @ Override
202202 public void menuCreate (WxMenu menu ) throws WxErrorException {
203- menuCreate (this .wxCpConfigStorage .getAgentId (), menu );
203+ menuCreate (this .configStorage .getAgentId (), menu );
204204 }
205205
206206 @ Override
207207 public void menuCreate (String agentId , WxMenu menu ) throws WxErrorException {
208208 String url = "https://qyapi.weixin.qq.com/cgi-bin/menu/create?agentid="
209- + this .wxCpConfigStorage .getAgentId ();
209+ + this .configStorage .getAgentId ();
210210 post (url , menu .toJson ());
211211 }
212212
213213 @ Override
214214 public void menuDelete () throws WxErrorException {
215- menuDelete (this .wxCpConfigStorage .getAgentId ());
215+ menuDelete (this .configStorage .getAgentId ());
216216 }
217217
218218 @ Override
@@ -223,7 +223,7 @@ public void menuDelete(String agentId) throws WxErrorException {
223223
224224 @ Override
225225 public WxMenu menuGet () throws WxErrorException {
226- return menuGet (this .wxCpConfigStorage .getAgentId ());
226+ return menuGet (this .configStorage .getAgentId ());
227227 }
228228
229229 @ Override
@@ -258,7 +258,7 @@ public File mediaDownload(String media_id) throws WxErrorException {
258258 String url = "https://qyapi.weixin.qq.com/cgi-bin/media/get" ;
259259 return execute (
260260 new MediaDownloadRequestExecutor (
261- this .wxCpConfigStorage .getTmpDirFile ()),
261+ this .configStorage .getTmpDirFile ()),
262262 url , "media_id=" + media_id );
263263 }
264264
@@ -475,15 +475,15 @@ public void tagRemoveUsers(String tagId, List<String> userIds) throws WxErrorExc
475475 @ Override
476476 public String oauth2buildAuthorizationUrl (String state ) {
477477 return this .oauth2buildAuthorizationUrl (
478- this .wxCpConfigStorage .getOauth2redirectUri (),
478+ this .configStorage .getOauth2redirectUri (),
479479 state
480480 );
481481 }
482482
483483 @ Override
484484 public String oauth2buildAuthorizationUrl (String redirectUri , String state ) {
485485 String url = "https://open.weixin.qq.com/connect/oauth2/authorize?" ;
486- url += "appid=" + this .wxCpConfigStorage .getCorpId ();
486+ url += "appid=" + this .configStorage .getCorpId ();
487487 url += "&redirect_uri=" + URIUtil .encodeURIComponent (redirectUri );
488488 url += "&response_type=code" ;
489489 url += "&scope=snsapi_base" ;
@@ -496,7 +496,7 @@ public String oauth2buildAuthorizationUrl(String redirectUri, String state) {
496496
497497 @ Override
498498 public String [] oauth2getUserInfo (String code ) throws WxErrorException {
499- return oauth2getUserInfo (this .wxCpConfigStorage .getAgentId (), code );
499+ return oauth2getUserInfo (this .configStorage .getAgentId (), code );
500500 }
501501
502502 @ Override
@@ -599,7 +599,7 @@ protected synchronized <T, E> T executeInternal(RequestExecutor<T, E> executor,
599599 */
600600 if (error .getErrorCode () == 42001 || error .getErrorCode () == 40001 ) {
601601 // 强制设置wxCpConfigStorage它的access token过期了,这样在下一次请求里就会刷新access token
602- this .wxCpConfigStorage .expireAccessToken ();
602+ this .configStorage .expireAccessToken ();
603603 return execute (executor , uri , data );
604604 }
605605 if (error .getErrorCode () != 0 ) {
@@ -619,20 +619,22 @@ protected CloseableHttpClient getHttpclient() {
619619
620620 @ Override
621621 public void setWxCpConfigStorage (WxCpConfigStorage wxConfigProvider ) {
622- this .wxCpConfigStorage = wxConfigProvider ;
623- ApacheHttpClientBuilder apacheHttpClientBuilder = this .wxCpConfigStorage
622+ this .configStorage = wxConfigProvider ;
623+ ApacheHttpClientBuilder apacheHttpClientBuilder = this .configStorage
624624 .getApacheHttpClientBuilder ();
625625 if (null == apacheHttpClientBuilder ) {
626626 apacheHttpClientBuilder = DefaultApacheHttpClientBuilder .get ();
627627 }
628- apacheHttpClientBuilder
629- .httpProxyHost (this .wxCpConfigStorage .getHttpProxyHost ())
630- .httpProxyPort (this .wxCpConfigStorage .getHttpProxyPort ())
631- .httpProxyUsername (this .wxCpConfigStorage .getHttpProxyUsername ())
632- .httpProxyPassword (this .wxCpConfigStorage .getHttpProxyPassword ());
633-
634- this .httpProxy = new HttpHost (this .wxCpConfigStorage .getHttpProxyHost (),
635- this .wxCpConfigStorage .getHttpProxyPort ());
628+
629+ apacheHttpClientBuilder .httpProxyHost (this .configStorage .getHttpProxyHost ())
630+ .httpProxyPort (this .configStorage .getHttpProxyPort ())
631+ .httpProxyUsername (this .configStorage .getHttpProxyUsername ())
632+ .httpProxyPassword (this .configStorage .getHttpProxyPassword ());
633+
634+ if (this .configStorage .getHttpProxyHost () != null && this .configStorage .getHttpProxyPort () > 0 ) {
635+ this .httpProxy = new HttpHost (this .configStorage .getHttpProxyHost (), this .configStorage .getHttpProxyPort ());
636+ }
637+
636638 this .httpClient = apacheHttpClientBuilder .build ();
637639 }
638640
0 commit comments