mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-04-24 18:04:38 +08:00
修复变量名,保持跟set方法统一
This commit is contained in:
parent
236166526f
commit
2e3a33a74e
@ -37,7 +37,7 @@ public class WxMpServiceImpl implements WxMpService {
|
||||
|
||||
protected final Logger log = LoggerFactory.getLogger(this.getClass());
|
||||
protected WxSessionManager sessionManager = new StandardSessionManager();
|
||||
private WxMpConfigStorage configStorage;
|
||||
private WxMpConfigStorage wxMpConfigStorage;
|
||||
private WxMpKefuService kefuService = new WxMpKefuServiceImpl(this);
|
||||
private WxMpMaterialService materialService = new WxMpMaterialServiceImpl(this);
|
||||
private WxMpMenuService menuService = new WxMpMenuServiceImpl(this);
|
||||
@ -59,7 +59,7 @@ public class WxMpServiceImpl implements WxMpService {
|
||||
@Override
|
||||
public boolean checkSignature(String timestamp, String nonce, String signature) {
|
||||
try {
|
||||
return SHA1.gen(this.configStorage.getToken(), timestamp, nonce)
|
||||
return SHA1.gen(this.wxMpConfigStorage.getToken(), timestamp, nonce)
|
||||
.equals(signature);
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
@ -73,18 +73,18 @@ public class WxMpServiceImpl implements WxMpService {
|
||||
|
||||
@Override
|
||||
public String getAccessToken(boolean forceRefresh) throws WxErrorException {
|
||||
Lock lock = this.configStorage.getAccessTokenLock();
|
||||
Lock lock = this.wxMpConfigStorage.getAccessTokenLock();
|
||||
try {
|
||||
lock.lock();
|
||||
|
||||
if (forceRefresh) {
|
||||
this.configStorage.expireAccessToken();
|
||||
this.wxMpConfigStorage.expireAccessToken();
|
||||
}
|
||||
|
||||
if (this.configStorage.isAccessTokenExpired()) {
|
||||
if (this.wxMpConfigStorage.isAccessTokenExpired()) {
|
||||
String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential" +
|
||||
"&appid=" + this.configStorage.getAppId() + "&secret="
|
||||
+ this.configStorage.getSecret();
|
||||
"&appid=" + this.wxMpConfigStorage.getAppId() + "&secret="
|
||||
+ this.wxMpConfigStorage.getSecret();
|
||||
try {
|
||||
HttpGet httpGet = new HttpGet(url);
|
||||
if (this.httpProxy != null) {
|
||||
@ -98,7 +98,7 @@ public class WxMpServiceImpl implements WxMpService {
|
||||
throw new WxErrorException(error);
|
||||
}
|
||||
WxAccessToken accessToken = WxAccessToken.fromJson(resultContent);
|
||||
this.configStorage.updateAccessToken(accessToken.getAccessToken(),
|
||||
this.wxMpConfigStorage.updateAccessToken(accessToken.getAccessToken(),
|
||||
accessToken.getExpiresIn());
|
||||
} finally {
|
||||
httpGet.releaseConnection();
|
||||
@ -110,7 +110,7 @@ public class WxMpServiceImpl implements WxMpService {
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
return this.configStorage.getAccessToken();
|
||||
return this.wxMpConfigStorage.getAccessToken();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -120,27 +120,27 @@ public class WxMpServiceImpl implements WxMpService {
|
||||
|
||||
@Override
|
||||
public String getJsapiTicket(boolean forceRefresh) throws WxErrorException {
|
||||
Lock lock = this.configStorage.getJsapiTicketLock();
|
||||
Lock lock = this.wxMpConfigStorage.getJsapiTicketLock();
|
||||
try {
|
||||
lock.lock();
|
||||
|
||||
if (forceRefresh) {
|
||||
this.configStorage.expireJsapiTicket();
|
||||
this.wxMpConfigStorage.expireJsapiTicket();
|
||||
}
|
||||
|
||||
if (this.configStorage.isJsapiTicketExpired()) {
|
||||
if (this.wxMpConfigStorage.isJsapiTicketExpired()) {
|
||||
String url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi";
|
||||
String responseContent = execute(new SimpleGetRequestExecutor(), url, null);
|
||||
JsonElement tmpJsonElement = JSON_PARSER.parse(responseContent);
|
||||
JsonObject tmpJsonObject = tmpJsonElement.getAsJsonObject();
|
||||
String jsapiTicket = tmpJsonObject.get("ticket").getAsString();
|
||||
int expiresInSeconds = tmpJsonObject.get("expires_in").getAsInt();
|
||||
this.configStorage.updateJsapiTicket(jsapiTicket, expiresInSeconds);
|
||||
this.wxMpConfigStorage.updateJsapiTicket(jsapiTicket, expiresInSeconds);
|
||||
}
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
return this.configStorage.getJsapiTicket();
|
||||
return this.wxMpConfigStorage.getJsapiTicket();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -151,7 +151,7 @@ public class WxMpServiceImpl implements WxMpService {
|
||||
String signature = SHA1.genWithAmple("jsapi_ticket=" + jsapiTicket,
|
||||
"noncestr=" + noncestr, "timestamp=" + timestamp, "url=" + url);
|
||||
WxJsapiSignature jsapiSignature = new WxJsapiSignature();
|
||||
jsapiSignature.setAppid(this.configStorage.getAppId());
|
||||
jsapiSignature.setAppid(this.wxMpConfigStorage.getAppId());
|
||||
jsapiSignature.setTimestamp(timestamp);
|
||||
jsapiSignature.setNoncestr(noncestr);
|
||||
jsapiSignature.setUrl(url);
|
||||
@ -216,7 +216,7 @@ public class WxMpServiceImpl implements WxMpService {
|
||||
public String oauth2buildAuthorizationUrl(String redirectURI, String scope, String state) {
|
||||
StringBuilder url = new StringBuilder();
|
||||
url.append("https://open.weixin.qq.com/connect/oauth2/authorize?");
|
||||
url.append("appid=").append(this.configStorage.getAppId());
|
||||
url.append("appid=").append(this.wxMpConfigStorage.getAppId());
|
||||
url.append("&redirect_uri=").append(URIUtil.encodeURIComponent(redirectURI));
|
||||
url.append("&response_type=code");
|
||||
url.append("&scope=").append(scope);
|
||||
@ -232,7 +232,7 @@ public class WxMpServiceImpl implements WxMpService {
|
||||
String state) {
|
||||
StringBuilder url = new StringBuilder();
|
||||
url.append("https://open.weixin.qq.com/connect/qrconnect?");
|
||||
url.append("appid=").append(this.configStorage.getAppId());
|
||||
url.append("appid=").append(this.wxMpConfigStorage.getAppId());
|
||||
url.append("&redirect_uri=").append(URIUtil.encodeURIComponent(redirectURI));
|
||||
url.append("&response_type=code");
|
||||
url.append("&scope=").append(scope);
|
||||
@ -258,8 +258,8 @@ public class WxMpServiceImpl implements WxMpService {
|
||||
public WxMpOAuth2AccessToken oauth2getAccessToken(String code) throws WxErrorException {
|
||||
StringBuilder url = new StringBuilder();
|
||||
url.append("https://api.weixin.qq.com/sns/oauth2/access_token?");
|
||||
url.append("appid=").append(this.configStorage.getAppId());
|
||||
url.append("&secret=").append(this.configStorage.getSecret());
|
||||
url.append("appid=").append(this.wxMpConfigStorage.getAppId());
|
||||
url.append("&secret=").append(this.wxMpConfigStorage.getSecret());
|
||||
url.append("&code=").append(code);
|
||||
url.append("&grant_type=authorization_code");
|
||||
|
||||
@ -270,7 +270,7 @@ public class WxMpServiceImpl implements WxMpService {
|
||||
public WxMpOAuth2AccessToken oauth2refreshAccessToken(String refreshToken) throws WxErrorException {
|
||||
StringBuilder url = new StringBuilder();
|
||||
url.append("https://api.weixin.qq.com/sns/oauth2/refresh_token?");
|
||||
url.append("appid=").append(this.configStorage.getAppId());
|
||||
url.append("appid=").append(this.wxMpConfigStorage.getAppId());
|
||||
url.append("&grant_type=refresh_token");
|
||||
url.append("&refresh_token=").append(refreshToken);
|
||||
|
||||
@ -397,8 +397,8 @@ public class WxMpServiceImpl implements WxMpService {
|
||||
*/
|
||||
if (error.getErrorCode() == 42001 || error.getErrorCode() == 40001) {
|
||||
// 强制设置wxMpConfigStorage它的access token过期了,这样在下一次请求里就会刷新access token
|
||||
this.configStorage.expireAccessToken();
|
||||
if (this.configStorage.autoRefreshToken()) {
|
||||
this.wxMpConfigStorage.expireAccessToken();
|
||||
if (this.wxMpConfigStorage.autoRefreshToken()) {
|
||||
return this.execute(executor, uri, data);
|
||||
}
|
||||
}
|
||||
@ -424,26 +424,26 @@ public class WxMpServiceImpl implements WxMpService {
|
||||
}
|
||||
|
||||
private void initHttpClient() {
|
||||
ApacheHttpClientBuilder apacheHttpClientBuilder = this.configStorage
|
||||
ApacheHttpClientBuilder apacheHttpClientBuilder = this.wxMpConfigStorage
|
||||
.getApacheHttpClientBuilder();
|
||||
if (null == apacheHttpClientBuilder) {
|
||||
apacheHttpClientBuilder = DefaultApacheHttpClientBuilder.get();
|
||||
}
|
||||
|
||||
apacheHttpClientBuilder.httpProxyHost(this.configStorage.getHttpProxyHost())
|
||||
.httpProxyPort(this.configStorage.getHttpProxyPort())
|
||||
.httpProxyUsername(this.configStorage.getHttpProxyUsername())
|
||||
.httpProxyPassword(this.configStorage.getHttpProxyPassword());
|
||||
apacheHttpClientBuilder.httpProxyHost(this.wxMpConfigStorage.getHttpProxyHost())
|
||||
.httpProxyPort(this.wxMpConfigStorage.getHttpProxyPort())
|
||||
.httpProxyUsername(this.wxMpConfigStorage.getHttpProxyUsername())
|
||||
.httpProxyPassword(this.wxMpConfigStorage.getHttpProxyPassword());
|
||||
|
||||
// if (this.configStorage.getSSLContext() != null) {
|
||||
// if (this.wxMpConfigStorage.getSSLContext() != null) {
|
||||
// SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
|
||||
// this.configStorage.getSSLContext(), new String[] { "TLSv1" }, null,
|
||||
// this.wxMpConfigStorage.getSSLContext(), new String[] { "TLSv1" }, null,
|
||||
// new DefaultHostnameVerifier());
|
||||
// apacheHttpClientBuilder.sslConnectionSocketFactory(sslsf);
|
||||
// }
|
||||
|
||||
if (this.configStorage.getHttpProxyHost() != null && this.configStorage.getHttpProxyPort() > 0) {
|
||||
this.httpProxy = new HttpHost(this.configStorage.getHttpProxyHost(), this.configStorage.getHttpProxyPort());
|
||||
if (this.wxMpConfigStorage.getHttpProxyHost() != null && this.wxMpConfigStorage.getHttpProxyPort() > 0) {
|
||||
this.httpProxy = new HttpHost(this.wxMpConfigStorage.getHttpProxyHost(), this.wxMpConfigStorage.getHttpProxyPort());
|
||||
}
|
||||
|
||||
this.httpClient = apacheHttpClientBuilder.build();
|
||||
@ -451,12 +451,12 @@ public class WxMpServiceImpl implements WxMpService {
|
||||
|
||||
@Override
|
||||
public WxMpConfigStorage getWxMpConfigStorage() {
|
||||
return this.configStorage;
|
||||
return this.wxMpConfigStorage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWxMpConfigStorage(WxMpConfigStorage wxConfigProvider) {
|
||||
this.configStorage = wxConfigProvider;
|
||||
this.wxMpConfigStorage = wxConfigProvider;
|
||||
this.initHttpClient();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user