针对AccessToken,jsapi ticket添加强制刷新的功能

This commit is contained in:
Daniel Qian
2015-01-20 14:30:44 +08:00
parent ae99bcdb63
commit 5c7448f212
4 changed files with 21 additions and 10 deletions

View File

@ -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>

View File

@ -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;