8000 accessToken无效可能引起死循环 · Issue #77 · binarywang/WxJava · GitHub
[go: up one dir, main page]

Skip to content 8000
accessToken无效可能引起死循环 #77
Closed
@luckalphie

Description

@luckalphie

` protected synchronized <T, E> T executeInternal(RequestExecutor<T, E> executor, String uri, E data) throws WxErrorException {
if (uri.indexOf("access_token=") != -1) {
throw new IllegalArgumentException("uri参数中不允许有access_token: " + uri);
}
String accessToken = getAccessToken(false);

String uriWithAccessToken = uri;
uriWithAccessToken += uri.indexOf('?') == -1 ? "?access_token=" + accessToken : "&access_token=" + accessToken;

try {
  return executor.execute(getHttpclient(), this.httpProxy,
      uriWithAccessToken, data);
} catch (WxErrorException e) {
  WxError error = e.getError();
  /*
   * 发生以下情况时尝试刷新access_token
   * 40001 获取access_token时AppSecret错误,或者access_token无效
   * 42001 access_token超时
   */
  if (error.getErrorCode() == 42001 || error.getErrorCode() == 40001) {
    // 强制设置wxCpConfigStorage它的access token过期了,这样在下一次请求里就会刷新access token
    this.configStorage.expireAccessToken();
   //建议这里不循环调用,直接抛出异常,累计失败次数
    return execute(executor, uri, data);
  }
  if (error.getErrorCode() != 0) {
    throw new WxErrorException(error);
  }
  return null;
} catch (ClientProtocolException e) {
  throw new RuntimeException(e);
} catch (IOException e) {
  throw new RuntimeException(e);
}

}`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0