binarywang/WxJava · critical · WxErrorException
错误代码:{}, 错误信息:{}
Error message
错误代码:{}, 错误信息:{} What it means
Thrown as WxErrorException when the HttpComponents (HC5) implementation of getSuiteAccessToken() receives a non-zero error code from the suite_access_token endpoint. Identical logic to the Apache HttpClient variant (error 164) but uses Apache HttpComponents 5.x as the transport. The request posts suite_id, suite_secret, and suite_ticket.
Source
Thrown at weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpServiceHttpComponentsImpl.java:71
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, BasicResponseHandler.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() {
HttpComponentsClientBuilder apacheHttpClientBuilder = DefaultHttpComponentsClientBuilder.get();
apacheHttpClientBuilder.httpProxyHost(this.configStorage.getHttpProxyHost())
.httpProxyPort(this.configStorage.getHttpProxyPort())View on GitHub (pinned to 1c43293a3c)
Solutions
- Verify suite_id and suite_secret exactly match the Third-Party Platform console settings
- Ensure suite_ticket is being received and stored before it expires (2-hour validity, pushed every 10 min)
- Whitelist your server's public IP in the WeChat TP admin console
- Inspect WxError errorCode for the specific failure reason
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();
log.error("HttpComponents suite token error: code={}, msg={}",
error.getErrorCode(), error.getErrorMsg());
throw e;
} Prevention
- Verify suite_id and suite_secret match the TP console
- Ensure suite_ticket callback is functional and tickets are refreshed every 10 min
- Whitelist your server IP in the WeChat TP admin console
- Monitor token acquisition metrics and set up alerting
When it happens
Trigger: Suite access token request fails with errcode != 0: invalid suite_secret (640001), expired suite_ticket (40029), invalid suite_id (40098), or IP whitelist violation (60020).
Common situations: suite_secret mismatch; suite_ticket expired or not received; server IP not in whitelist; suite application under review or revoked.
Related errors
AI-assisted analysis of binarywang/WxJava@1c43293a3c (2026-08-14).
Data as JSON: /api/errors/3755506dd095fe0f.
Report an issue: GitHub.