binarywang/WxJava · critical · WxErrorException
错误代码:{}, 错误信息:{}
Error message
错误代码:{}, 错误信息:{} What it means
Thrown as WxErrorException when the OkHttp implementation of getSuiteAccessToken() receives a non-zero error code from the suite_access_token endpoint. The request completed at the HTTP level (no IOException) but WeChat returned an error JSON. Identical logic to errors 164-166 but using OkHttp as the transport. Message format from WxError.toString().
Source
Thrown at weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpServiceOkHttpImpl.java:88
Request request = new Request.Builder()
.url(this.configStorage.getApiUrl(WxCpApiPathConsts.Tp.GET_SUITE_TOKEN)) // URL 不包含查询参数
.post(requestBody) // 使用 POST 方法
.build();
String resultContent = null;
try (Response response = client.newCall(request).execute()) {
if (!response.isSuccessful()) {
throw new IOException("Unexpected response code: " + response);
}
resultContent = response.body().string();
} catch (IOException e) {
log.error("获取 suite token 失败: {}", e.getMessage(), e);
throw new WxRuntimeException("获取 suite token 失败", e);
}
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);
}
return this.configStorage.getSuiteAccessToken();
}
@Override
public void initHttp() {
log.debug("WxCpServiceOkHttpImpl initHttp");
//设置代理
if (configStorage.getHttpProxyHost() != null && configStorage.getHttpProxyPort() > 0) {
httpProxy = OkHttpProxyInfo.httpProxy(configStorage.getHttpProxyHost(),
configStorage.getHttpProxyPort(),
configStorage.getHttpProxyUsername(),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
- 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("OkHttp 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 stored promptly
- Whitelist your server IP in the TP admin console
- Monitor suite_access_token acquisition success rate
When it happens
Trigger: Suite access token request completes but returns 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.
Related errors
AI-assisted analysis of binarywang/WxJava@1c43293a3c (2026-08-14).
Data as JSON: /api/errors/8e145bfc55b14607.
Report an issue: GitHub.