Skip to content

Commit 7ee9ac0

Browse files
committed
replace this.wxMpConfigStorage with this.getWxMpConfigStorage() #155
1 parent 4be0299 commit 7ee9ac0

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public class WxMpServiceImpl implements WxMpService {
5555
@Override
5656
public boolean checkSignature(String timestamp, String nonce, String signature) {
5757
try {
58-
return SHA1.gen(this.wxMpConfigStorage.getToken(), timestamp, nonce)
58+
return SHA1.gen(this.getWxMpConfigStorage().getToken(), timestamp, nonce)
5959
.equals(signature);
6060
} catch (Exception e) {
6161
return false;
@@ -69,18 +69,18 @@ public String getAccessToken() throws WxErrorException {
6969

7070
@Override
7171
public String getAccessToken(boolean forceRefresh) throws WxErrorException {
72-
Lock lock = this.wxMpConfigStorage.getAccessTokenLock();
72+
Lock lock = this.getWxMpConfigStorage().getAccessTokenLock();
7373
try {
7474
lock.lock();
7575

7676
if (forceRefresh) {
77-
this.wxMpConfigStorage.expireAccessToken();
77+
this.getWxMpConfigStorage().expireAccessToken();
7878
}
7979

80-
if (this.wxMpConfigStorage.isAccessTokenExpired()) {
80+
if (this.getWxMpConfigStorage().isAccessTokenExpired()) {
8181
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();
8484
try {
8585
HttpGet httpGet = new HttpGet(url);
8686
if (this.httpProxy != null) {
@@ -94,7 +94,7 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException {
9494
throw new WxErrorException(error);
9595
}
9696
WxAccessToken accessToken = WxAccessToken.fromJson(resultContent);
97-
this.wxMpConfigStorage.updateAccessToken(accessToken.getAccessToken(),
97+
this.getWxMpConfigStorage().updateAccessToken(accessToken.getAccessToken(),
9898
accessToken.getExpiresIn());
9999
} finally {
100100
httpGet.releaseConnection();
@@ -106,7 +106,7 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException {
106106
} finally {
107107
lock.unlock();
108108
}
109-
return this.wxMpConfigStorage.getAccessToken();
109+
return this.getWxMpConfigStorage().getAccessToken();
110110
}
111111

112112
@Override
@@ -116,27 +116,27 @@ public String getJsapiTicket() throws WxErrorException {
116116

117117
@Override
118118
public String getJsapiTicket(boolean forceRefresh) throws WxErrorException {
119-
Lock lock = this.wxMpConfigStorage.getJsapiTicketLock();
119+
Lock lock = this.getWxMpConfigStorage().getJsapiTicketLock();
120120
try {
121121
lock.lock();
122122

123123
if (forceRefresh) {
124-
this.wxMpConfigStorage.expireJsapiTicket();
124+
this.getWxMpConfigStorage().expireJsapiTicket();
125125
}
126126

127-
if (this.wxMpConfigStorage.isJsapiTicketExpired()) {
127+
if (this.getWxMpConfigStorage().isJsapiTicketExpired()) {
128128
String url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi";
129129
String responseContent = execute(new SimpleGetRequestExecutor(), url, null);
130130
JsonElement tmpJsonElement = JSON_PARSER.parse(responseContent);
131131
JsonObject tmpJsonObject = tmpJsonElement.getAsJsonObject();
132132
String jsapiTicket = tmpJsonObject.get("ticket").getAsString();
133133
int expiresInSeconds = tmpJsonObject.get("expires_in").getAsInt();
134-
this.wxMpConfigStorage.updateJsapiTicket(jsapiTicket, expiresInSeconds);
134+
this.getWxMpConfigStorage().updateJsapiTicket(jsapiTicket, expiresInSeconds);
135135
}
136136
} finally {
137137
lock.unlock();
138138
}
139-
return this.wxMpConfigStorage.getJsapiTicket();
139+
return this.getWxMpConfigStorage().getJsapiTicket();
140140
}
141141

142142
@Override
@@ -147,7 +147,7 @@ public WxJsapiSignature createJsapiSignature(String url) throws WxErrorException
147147
String signature = SHA1.genWithAmple("jsapi_ticket=" + jsapiTicket,
148148
"noncestr=" + noncestr, "timestamp=" + timestamp, "url=" + url);
149149
WxJsapiSignature jsapiSignature = new WxJsapiSignature();
150-
jsapiSignature.setAppId(this.wxMpConfigStorage.getAppId());
150+
jsapiSignature.setAppId(this.getWxMpConfigStorage().getAppId());
151151
jsapiSignature.setTimestamp(timestamp);
152152
jsapiSignature.setNonceStr(noncestr);
153153
jsapiSignature.setUrl(url);
@@ -212,7 +212,7 @@ public WxMpSemanticQueryResult semanticQuery(WxMpSemanticQuery semanticQuery) th
212212
public String oauth2buildAuthorizationUrl(String redirectURI, String scope, String state) {
213213
StringBuilder url = new StringBuilder();
214214
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());
216216
url.append("&redirect_uri=").append(URIUtil.encodeURIComponent(redirectURI));
217217
url.append("&response_type=code");
218218
url.append("&scope=").append(scope);
@@ -228,7 +228,7 @@ public String buildQrConnectUrl(String redirectURI, String scope,
228228
String state) {
229229
StringBuilder url = new StringBuilder();
230230
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());
232232
url.append("&redirect_uri=").append(URIUtil.encodeURIComponent(redirectURI));
233233
url.append("&response_type=code");
234234
url.append("&scope=").append(scope);
@@ -254,8 +254,8 @@ private WxMpOAuth2AccessToken getOAuth2AccessToken(StringBuilder url) throws WxE
254254
public WxMpOAuth2AccessToken oauth2getAccessToken(String code) throws WxErrorException {
255255
StringBuilder url = new StringBuilder();
256256
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());
259259
url.append("&code=").append(code);
260260
url.append("&grant_type=authorization_code");
261261

@@ -266,7 +266,7 @@ public WxMpOAuth2AccessToken oauth2getAccessToken(String code) throws WxErrorExc
266266
public WxMpOAuth2AccessToken oauth2refreshAccessToken(String refreshToken) throws WxErrorException {
267267
StringBuilder url = new StringBuilder();
268268
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());
270270
url.append("&grant_type=refresh_token");
271271
url.append("&refresh_token=").append(refreshToken);
272272

@@ -393,8 +393,8 @@ protected synchronized <T, E> T executeInternal(RequestExecutor<T, E> executor,
393393
*/
394394
if (error.getErrorCode() == 42001 || error.getErrorCode() == 40001) {
395395
// 强制设置wxMpConfigStorage它的access token过期了,这样在下一次请求里就会刷新access token
396-
this.wxMpConfigStorage.expireAccessToken();
397-
if (this.wxMpConfigStorage.autoRefreshToken()) {
396+
this.getWxMpConfigStorage().expireAccessToken();
397+
if (this.getWxMpConfigStorage().autoRefreshToken()) {
398398
return this.execute(executor, uri, data);
399399
}
400400
}
@@ -426,20 +426,20 @@ private void initHttpClient() {
426426
apacheHttpClientBuilder = DefaultApacheHttpClientBuilder.get();
427427
}
428428

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());
433433

434-
// if (this.wxMpConfigStorage.getSSLContext() != null) {
434+
// if (this.getWxMpConfigStorage().getSSLContext() != null) {
435435
// SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
436-
// this.wxMpConfigStorage.getSSLContext(), new String[] { "TLSv1" }, null,
436+
// this.getWxMpConfigStorage().getSSLContext(), new String[] { "TLSv1" }, null,
437437
// new DefaultHostnameVerifier());
438438
// apacheHttpClientBuilder.sslConnectionSocketFactory(sslsf);
439439
// }
440440

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());
443443
}
444444

445445
this.httpClient = apacheHttpClientBuilder.build();

0 commit comments

Comments
 (0)