@@ -65,7 +65,7 @@ public class WxCpServiceImpl implements WxCpService {
*/
protected final Object globalJsapiTicketRefreshLock = new Object ( ) ;
protected WxCpConfigStorage wxCpC onfigStorage;
protected WxCpConfigStorage c onfigStorage;
protected CloseableHttpClient httpClient ;
@@ -81,7 +81,7 @@ public class WxCpServiceImpl implements WxCpService {
@Override
public boolean checkSignature ( String msgSignature , String timestamp , String nonce , String data ) {
try {
return SHA1 . gen ( this . wxCpC onfigStorage. getToken ( ) , timestamp , nonce , data )
return SHA1 . gen ( this . c onfigStorage. getToken ( ) , timestamp , nonce , data )
. equals ( msgSignature ) ;
} catch ( Exception e ) {
return false ;
@@ -102,14 +102,14 @@ public class WxCpServiceImpl implements WxCpService {
@Override
public String getAccessToken ( boolean forceRefresh ) throws WxErrorException {
if ( forceRefresh ) {
this . wxCpC onfigStorage. expireAccessToken ( ) ;
this . c onfigStorage. expireAccessToken ( ) ;
}
if ( this . wxCpC onfigStorage. isAccessTokenExpired ( ) ) {
if ( this . c onfigStorage. isAccessTokenExpired ( ) ) {
synchronized ( this . globalAccessTokenRefreshLock ) {
if ( this . wxCpC onfigStorage. isAccessTokenExpired ( ) ) {
if ( this . c onfigStorage. isAccessTokenExpired ( ) ) {
String url = " https://qyapi.weixin.qq.com/cgi-bin/gettoken? "
+ " &corpid= " + this . wxCpC onfigStorage. getCorpId ( ) + " &corpsecret= "
+ this . wxCpC onfigStorage. getCorpSecret ( ) ;
+ " &corpid= " + this . c onfigStorage. getCorpId ( )
+ " &corpsecret= " + this . c onfigStorage. getCorpSecret ( ) ;
try {
HttpGet httpGet = new HttpGet ( url ) ;
if ( this . httpProxy ! = null ) {
@@ -129,7 +129,7 @@ public class WxCpServiceImpl implements WxCpService {
throw new WxErrorException ( error ) ;
}
WxAccessToken accessToken = WxAccessToken . fromJson ( resultContent ) ;
this . wxCpC onfigStorage. updateAccessToken (
this . c onfigStorage. updateAccessToken (
accessToken . getAccessToken ( ) , accessToken . getExpiresIn ( ) ) ;
} catch ( ClientProtocolException e ) {
throw new RuntimeException ( e ) ;
@@ -139,7 +139,7 @@ public class WxCpServiceImpl implements WxCpService {
}
}
}
return this . wxCpC onfigStorage. getAccessToken ( ) ;
return this . c onfigStorage. getAccessToken ( ) ;
}
@Override
@@ -150,23 +150,23 @@ public class WxCpServiceImpl implements WxCpService {
@Override
public String getJsapiTicket ( boolean forceRefresh ) throws WxErrorException {
if ( forceRefresh ) {
this . wxCpC onfigStorage. expireJsapiTicket ( ) ;
this . c onfigStorage. expireJsapiTicket ( ) ;
}
if ( this . wxCpC onfigStorage. isJsapiTicketExpired ( ) ) {
if ( this . c onfigStorage. isJsapiTicketExpired ( ) ) {
synchronized ( this . globalJsapiTicketRefreshLock ) {
if ( this . wxCpC onfigStorage. isJsapiTicketExpired ( ) ) {
if ( this . c onfigStorage. isJsapiTicketExpired ( ) ) {
String url = " https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket " ;
String responseContent = execute ( new SimpleGetRequestExecutor ( ) , url , null ) ;
JsonElement tmpJsonElement = new JsonParser ( ) . parse ( responseContent ) ;
JsonObject tmpJsonObject = tmpJsonElement . getAsJsonObject ( ) ;
String jsapiTicket = tmpJsonObject . get ( " ticket " ) . getAsString ( ) ;
int expiresInSeconds = tmpJsonObject . get ( " expires_in " ) . getAsInt ( ) ;
this . wxCpC onfigStorage. updateJsapiTicket ( jsapiTicket ,
this . c onfigStorage. updateJsapiTicket ( jsapiTicket ,
expiresInSeconds ) ;
}
}
}
return this . wxCpC onfigStorage. getJsapiTicket ( ) ;
return this . c onfigStorage. getJsapiTicket ( ) ;
}
@Override
@@ -187,7 +187,7 @@ public class WxCpServiceImpl implements WxCpService {
jsapiSignature . setSignature ( signature ) ;
// Fixed bug
jsapiSignature . setAppid ( this . wxCpC onfigStorage. getCorpId ( ) ) ;
jsapiSignature . setAppid ( this . c onfigStorage. getCorpId ( ) ) ;
return jsapiSignature ;
}
@@ -200,19 +200,19 @@ public class WxCpServiceImpl implements WxCpService {
@Override
public void menuCreate ( WxMenu menu ) throws WxErrorException {
menuCreate ( this . wxCpC onfigStorage. getAgentId ( ) , menu ) ;
menuCreate ( this . c onfigStorage. getAgentId ( ) , menu ) ;
}
@Override
public void menuCreate ( String agentId , WxMenu menu ) throws WxErrorException {
String url = " https://qyapi.weixin.qq.com/cgi-bin/menu/create?agentid= "
+ this . wxCpC onfigStorage. getAgentId ( ) ;
+ this . c onfigStorage. getAgentId ( ) ;
post ( url , menu . toJson ( ) ) ;
}
@Override
public void menuDelete ( ) throws WxErrorException {
menuDelete ( this . wxCpC onfigStorage. getAgentId ( ) ) ;
menuDelete ( this . c onfigStorage. getAgentId ( ) ) ;
}
@Override
@@ -223,7 +223,7 @@ public class WxCpServiceImpl implements WxCpService {
@Override
public WxMenu menuGet ( ) throws WxErrorException {
return menuGet ( this . wxCpC onfigStorage. getAgentId ( ) ) ;
return menuGet ( this . c onfigStorage. getAgentId ( ) ) ;
}
@Override
@@ -258,7 +258,7 @@ public class WxCpServiceImpl implements WxCpService {
String url = " https://qyapi.weixin.qq.com/cgi-bin/media/get " ;
return execute (
new MediaDownloadRequestExecutor (
this . wxCpC onfigStorage. getTmpDirFile ( ) ) ,
this . c onfigStorage. getTmpDirFile ( ) ) ,
url , " media_id= " + media_id ) ;
}
@@ -475,7 +475,7 @@ public class WxCpServiceImpl implements WxCpService {
@Override
public String oauth2buildAuthorizationUrl ( String state ) {
return this . oauth2buildAuthorizationUrl (
this . wxCpC onfigStorage. getOauth2redirectUri ( ) ,
this . c onfigStorage. getOauth2redirectUri ( ) ,
state
) ;
}
@@ -483,7 +483,7 @@ public class WxCpServiceImpl implements WxCpService {
@Override
public String oauth2buildAuthorizationUrl ( String redirectUri , String state ) {
String url = " https://open.weixin.qq.com/connect/oauth2/authorize? " ;
url + = " appid= " + this . wxCpC onfigStorage. getCorpId ( ) ;
url + = " appid= " + this . c onfigStorage. getCorpId ( ) ;
url + = " &redirect_uri= " + URIUtil . encodeURIComponent ( redirectUri ) ;
url + = " &response_type=code " ;
url + = " &scope=snsapi_base " ;
@@ -496,7 +496,7 @@ public class WxCpServiceImpl implements WxCpService {
@Override
public String [ ] oauth2getUserInfo ( String code ) throws WxErrorException {
return oauth2getUserInfo ( this . wxCpC onfigStorage. getAgentId ( ) , code ) ;
return oauth2getUserInfo ( this . c onfigStorage. getAgentId ( ) , code ) ;
}
@Override
@@ -599,7 +599,7 @@ public class WxCpServiceImpl implements WxCpService {
*/
if ( error . getErrorCode ( ) = = 42001 | | error . getErrorCode ( ) = = 40001 ) {
// 强制设置wxCpConfigStorage它的access token过期了, 这样在下一次请求里就会刷新access token
this . wxCpC onfigStorage. expireAccessToken ( ) ;
this . c onfigStorage. expireAccessToken ( ) ;
return execute ( executor , uri , data ) ;
}
if ( error . getErrorCode ( ) ! = 0 ) {
@@ -619,20 +619,22 @@ public class WxCpServiceImpl implements WxCpService {
@Override
public void setWxCpConfigStorage ( WxCpConfigStorage wxConfigProvider ) {
this . wxCpC onfigStorage = wxConfigProvider ;
ApacheHttpClientBuilder apacheHttpClientBuilder = this . wxCpC onfigStorage
this . c onfigStorage = wxConfigProvider ;
ApacheHttpClientBuilder apacheHttpClientBuilder = this . c onfigStorage
. getApacheHttpClientBuilder ( ) ;
if ( null = = apacheHttpClientBuilder ) {
apacheHttpClientBuilder = DefaultApacheHttpClientBuilder . get ( ) ;
}
apacheHttpClientBuilder
. httpProxyHost ( this . wxCpConfigStorage . getHttpProxyHost ( ) )
. httpProxyPort ( this . wxCpConfigStorage . getHttpProxyPort ( ) )
. httpProxyUsername ( this . wxCpConfigStorage . getHttpProxyUsername ( ) )
. httpProxyPassword ( this . wxCpConfigStorage . getHttpProxyPassword ( ) ) ;
this . httpProxy = new Http Host( this . wxCpC onfigStorage. getHttpProxyHost ( ) ,
this . wxCpC onfigStorage. getHttpProxyPort ( ) ) ;
apacheHttpClientBuilder . httpProxy Host( this . c onfigStorage. getHttpProxyHost ( ) )
. httpProxyPort ( this . c onfigStorage. getHttpProxyPort ( ) )
. httpProxyUsername ( this . configStorage . getHttpProxyUsername ( ) )
. httpProxyPassword ( this . configStorage . getHttpProxyPassword ( ) ) ;
if ( this . configStorage . getHttpProxyHost ( ) ! = null & & this . configStorage . getHttpProxyPort ( ) > 0 ) {
this . httpProxy = new HttpHost ( this . configStorage . getHttpProxyHost ( ) , this . configStorage . getHttpProxyPort ( ) ) ;
}
this . httpClient = apacheHttpClientBuilder . build ( ) ;
}