binarywang/WxJava · critical · WxErrorException

错误代码:{}, 错误信息:{}

Error message

错误代码:{}, 错误信息:{}

What it means

Thrown as WxErrorException when the Apache HttpClient implementation of getSuiteAccessToken() receives a non-zero error code from the suite_access_token endpoint (GET_SUITE_TOKEN). The request posts suite_id, suite_secret, and suite_ticket to WeChat; a non-zero response means the token could not be issued. The message format derives from WxError.toString().

Source

Thrown at weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpServiceApacheHttpClientImpl.java:72

    synchronized (this.globalSuiteAccessTokenRefreshLock) {
      try {
        HttpPost httpPost = new HttpPost(configStorage.getApiUrl(WxCpApiPathConsts.Tp.GET_SUITE_TOKEN));
        if (this.httpProxy != null) {
          RequestConfig config = RequestConfig.custom()
            .setProxy(this.httpProxy).build();
          httpPost.setConfig(config);
        }
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("suite_id", this.configStorage.getSuiteId());
        jsonObject.addProperty("suite_secret", this.configStorage.getSuiteSecret());
        jsonObject.addProperty("suite_ticket", this.getSuiteTicket());
        StringEntity entity = new StringEntity(jsonObject.toString(), StandardCharsets.UTF_8);
        httpPost.setEntity(entity);

        String resultContent = getRequestHttpClient().execute(httpPost, ApacheBasicResponseHandler.INSTANCE);
        WxError error = WxError.fromJson(resultContent, WxType.CP);
        if (error.getErrorCode() != 0) {
          throw new WxErrorException(error);
        }
        jsonObject = GsonParser.parse(resultContent);
        String suiteAccussToken = jsonObject.get("suite_access_token").getAsString();
        int expiresIn = jsonObject.get("expires_in").getAsInt();
        this.configStorage.updateSuiteAccessToken(suiteAccussToken, expiresIn);
      } catch (IOException e) {
        throw new WxRuntimeException(e);
      }
    }
    return this.configStorage.getSuiteAccessToken();
  }

  @Override
  public void initHttp() {
    ApacheHttpClientBuilder apacheHttpClientBuilder = this.configStorage.getApacheHttpClientBuilder();
    if (null == apacheHttpClientBuilder) {
      apacheHttpClientBuilder = DefaultApacheHttpClientBuilder.get();
    }

View on GitHub (pinned to 1c43293a3c)

Solutions

  1. Verify suite_id and suite_secret exactly match the Third-Party Platform console settings
  2. Ensure suite_ticket is being received via the callback URL and stored — it expires after 2 hours
  3. Whitelist your server's public IP in the WeChat TP admin console under IP白名单
  4. Inspect the WxError errorCode: 40029 = invalid suite_ticket, 640001 = invalid suite_secret, 60020 = IP not allowed
Defensive patterns

Strategy: try-catch

Validate before calling

// Verify suite credentials before relying on token auto-refresh
if (StringUtils.isBlank(configStorage.getSuiteId())
    || StringUtils.isBlank(configStorage.getSuiteSecret())) {
  throw new IllegalStateException("suite_id and suite_secret must be configured");
}

Try / catch

try {
  service.getSuiteAccessToken();
} catch (WxErrorException e) {
  WxError error = e.getError();
  if (error.getErrorCode() == 40029) {
    log.error("suite_ticket expired or missing — verify the callback endpoint");
  } else if (error.getErrorCode() == 60020) {
    log.error("Server IP not whitelisted in WeChat TP console");
  }
  throw e;
}

Prevention

When it happens

Trigger: Suite access token request fails with errcode != 0: invalid suite_secret (640001), missing or expired suite_ticket (40029), invalid suite_id (40098), or IP whitelist violation (60020).

Common situations: suite_secret does not match the TP console; suite_ticket not being received (WeChat pushes every 10 min, 2-hour validity); server IP not whitelisted; suite disabled or under review.

Related errors


AI-assisted analysis of binarywang/WxJava@1c43293a3c (2026-08-14). Data as JSON: /api/errors/1a8fc0fd879405af. Report an issue: GitHub.