binarywang/WxJava · error · WxErrorException
会话存档secret未配置
Error message
会话存档secret未配置
What it means
Thrown (as checked WxErrorException) by getMsgAuditAccessToken() in the HttpComponents implementation when the chat-archive secret is null or blank. Same validation as other HTTP client implementations but in the HttpClient 5 variant.
Source
Thrown at weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceHttpComponentsImpl.java:140
}
@Override
public String getMsgAuditAccessToken(boolean forceRefresh) throws WxErrorException {
if (!this.configStorage.isMsgAuditAccessTokenExpired() && !forceRefresh) {
return this.configStorage.getMsgAuditAccessToken();
}
Lock lock = this.configStorage.getMsgAuditAccessTokenLock();
lock.lock();
try {
// 拿到锁之后,再次判断一下最新的token是否过期,避免重刷
if (!this.configStorage.isMsgAuditAccessTokenExpired() && !forceRefresh) {
return this.configStorage.getMsgAuditAccessToken();
}
// 使用会话存档secret获取access_token
String msgAuditSecret = this.configStorage.getMsgAuditSecret();
if (msgAuditSecret == null || msgAuditSecret.trim().isEmpty()) {
throw new WxErrorException("会话存档secret未配置");
}
String url = String.format(this.configStorage.getApiUrl(WxCpApiPathConsts.GET_TOKEN),
this.configStorage.getCorpId(), msgAuditSecret);
try {
HttpGet httpGet = new HttpGet(url);
if (this.httpProxy != null) {
RequestConfig config = RequestConfig.custom()
.setProxy(this.httpProxy).build();
httpGet.setConfig(config);
}
String resultContent = getRequestHttpClient().execute(httpGet, BasicResponseHandler.INSTANCE);
WxError error = WxError.fromJson(resultContent, WxType.CP);
if (error.getErrorCode() != 0) {
throw new WxErrorException(error);
}
WxAccessToken accessToken = WxAccessToken.fromJson(resultContent);View on GitHub (pinned to 1c43293a3c)
Solutions
- Set the msg-audit secret via configStorage.setMsgAuditSecret() during initialization
- Ensure wx.cp.msg-audit-secret is set in application.yml for Spring Boot deployments
- Verify the secret in the WeChat Work admin console → 管理工具 → 会话内容操作
Example fix
// before
config.setMsgAuditSecret(null); // or never called
// after
config.setMsgAuditSecret(System.getenv("WX_CP_MSG_AUDIT_SECRET")); Defensive patterns
Strategy: validation
Validate before calling
// Validate msg-audit secret for HttpComponents impl
String msgAuditSecret = configStorage.getMsgAuditSecret();
if (StringUtils.isBlank(msgAuditSecret)) {
throw new IllegalStateException("会话存档 secret 未配置");
} Prevention
- Config validation should be the same across all HTTP client implementations
- Ensure wx.cp.msg-audit-secret is set in application.yml
- Run a startup health check for all secrets used by the active service implementation
When it happens
Trigger: Any msg-audit operation via WxCpServiceHttpComponentsImpl when configStorage.getMsgAuditSecret() is null or blank.
Common situations: Migrated to HttpComponents implementation without carrying over the msgAudit secret config; the 会话存档 secret was never obtained from the admin console; env var missing in the new deployment environment.
Related errors
AI-assisted analysis of binarywang/WxJava@1c43293a3c (2026-08-14).
Data as JSON: /api/errors/7a7fff05f11681fc.
Report an issue: GitHub.