Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ public interface WxMpService {
*/
String getAccessToken(boolean forceRefresh) throws WxErrorException;


/**
* <pre>
* 强制accessToken过期
* </pre>
*/
void expireAccessToken();

/**
* 获得jsapi_ticket,不强制刷新jsapi_ticket
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public String getAccessToken() throws WxErrorException {
@Override
public String getAccessToken(boolean forceRefresh) throws WxErrorException {
if (forceRefresh) {
this.configStorage.expireAccessToken();
expireAccessToken();
}
if (this.configStorage.isAccessTokenExpired()) {
synchronized (this.globalAccessTokenRefreshLock) {
Expand Down Expand Up @@ -134,6 +134,11 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException {
return this.configStorage.getAccessToken();
}

@Override
public void expireAccessToken(){
this.configStorage.expireAccessToken();
}

@Override
public String getJsapiTicket() throws WxErrorException {
return getJsapiTicket(false);
Expand Down Expand Up @@ -410,8 +415,10 @@ protected synchronized <T, E> T executeInternal(RequestExecutor<T, E> executor,
*/
if (error.getErrorCode() == 42001 || error.getErrorCode() == 40001) {
// 强制设置wxMpConfigStorage它的access token过期了,这样在下一次请求里就会刷新access token
this.configStorage.expireAccessToken();
return this.execute(executor, uri, data);
//this.configStorage.expireAccessToken();
//return this.execute(executor, uri, data);
//此方法可被重写
expireAccessToken();
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你这种做法虽然解决了你的死循环问题,但考虑不够全面,会导致token过期无法自动刷新的问题,造成用户请求无法直接得到结果,而必须再次重试

}
if (error.getErrorCode() != 0) {
this.log.error("\n[URL]: {}\n[PARAMS]: {}\n[RESPONSE]: {}", uri, data,
Expand Down