针对AccessToken,jsapi ticket添加强制刷新的功能
This commit is contained in:
@@ -51,11 +51,11 @@ public interface WxCpService {
|
||||
* 程序员在非必要情况下尽量不要主动调用此方法
|
||||
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=获取access_token
|
||||
* </pre>
|
||||
*
|
||||
* @param forceRefresh 强制刷新
|
||||
* @return
|
||||
* @throws me.chanjar.weixin.common.exception.WxErrorException
|
||||
*/
|
||||
public String getAccessToken() throws WxErrorException;
|
||||
public String getAccessToken(boolean forceRefresh) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
|
||||
@@ -71,7 +71,10 @@ public class WxCpServiceImpl implements WxCpService {
|
||||
execute(new SimpleGetRequestExecutor(), url, null);
|
||||
}
|
||||
|
||||
public String getAccessToken() throws WxErrorException {
|
||||
public String getAccessToken(boolean forceRefresh) throws WxErrorException {
|
||||
if (forceRefresh) {
|
||||
wxCpConfigStorage.expireAccessToken();
|
||||
}
|
||||
if (wxCpConfigStorage.isAccessTokenExpired()) {
|
||||
synchronized (GLOBAL_ACCESS_TOKEN_REFRESH_LOCK) {
|
||||
if (wxCpConfigStorage.isAccessTokenExpired()) {
|
||||
@@ -359,7 +362,7 @@ public class WxCpServiceImpl implements WxCpService {
|
||||
* @throws WxErrorException
|
||||
*/
|
||||
public <T, E> T execute(RequestExecutor<T, E> executor, String uri, E data) throws WxErrorException {
|
||||
String accessToken = getAccessToken();
|
||||
String accessToken = getAccessToken(false);
|
||||
|
||||
String uriWithAccessToken = uri;
|
||||
uriWithAccessToken += uri.indexOf('?') == -1 ? "?access_token=" + accessToken : "&access_token=" + accessToken;
|
||||
|
||||
Reference in New Issue
Block a user