{"record":{"id":"7a7fff05f11681fc","repo":"binarywang/WxJava","slug":"secret-7a7fff","errorCode":null,"errorMessage":"会话存档secret未配置","messagePattern":"会话存档secret未配置","errorType":"validation","errorClass":"WxErrorException","httpStatus":null,"severity":"error","filePath":"weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceHttpComponentsImpl.java","lineNumber":140,"sourceCode":"  }\n\n  @Override\n  public String getMsgAuditAccessToken(boolean forceRefresh) throws WxErrorException {\n    if (!this.configStorage.isMsgAuditAccessTokenExpired() && !forceRefresh) {\n      return this.configStorage.getMsgAuditAccessToken();\n    }\n\n    Lock lock = this.configStorage.getMsgAuditAccessTokenLock();\n    lock.lock();\n    try {\n      // 拿到锁之后，再次判断一下最新的token是否过期，避免重刷\n      if (!this.configStorage.isMsgAuditAccessTokenExpired() && !forceRefresh) {\n        return this.configStorage.getMsgAuditAccessToken();\n      }\n      // 使用会话存档secret获取access_token\n      String msgAuditSecret = this.configStorage.getMsgAuditSecret();\n      if (msgAuditSecret == null || msgAuditSecret.trim().isEmpty()) {\n        throw new WxErrorException(\"会话存档secret未配置\");\n      }\n      String url = String.format(this.configStorage.getApiUrl(WxCpApiPathConsts.GET_TOKEN),\n        this.configStorage.getCorpId(), msgAuditSecret);\n\n      try {\n        HttpGet httpGet = new HttpGet(url);\n        if (this.httpProxy != null) {\n          RequestConfig config = RequestConfig.custom()\n            .setProxy(this.httpProxy).build();\n          httpGet.setConfig(config);\n        }\n        String resultContent = getRequestHttpClient().execute(httpGet, BasicResponseHandler.INSTANCE);\n        WxError error = WxError.fromJson(resultContent, WxType.CP);\n        if (error.getErrorCode() != 0) {\n          throw new WxErrorException(error);\n        }\n\n        WxAccessToken accessToken = WxAccessToken.fromJson(resultContent);","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/binarywang/WxJava/blob/1c43293a3c2c9d7e91304b6d037fb017f680d0c6/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceHttpComponentsImpl.java#L122-L158","documentation":"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.","triggerScenarios":"Any msg-audit operation via WxCpServiceHttpComponentsImpl when configStorage.getMsgAuditSecret() is null or blank.","commonSituations":"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.","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 → 管理工具 → 会话内容操作"],"exampleFix":"// before\nconfig.setMsgAuditSecret(null); // or never called\n\n// after\nconfig.setMsgAuditSecret(System.getenv(\"WX_CP_MSG_AUDIT_SECRET\"));","handlingStrategy":"validation","validationCode":"// Validate msg-audit secret for HttpComponents impl\nString msgAuditSecret = configStorage.getMsgAuditSecret();\nif (StringUtils.isBlank(msgAuditSecret)) {\n  throw new IllegalStateException(\"会话存档 secret 未配置\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["wechat-cp","config","msg-audit","access-token","secret","httpcomponents"],"backgroundTag":null,"analyzedSha":"1c43293a3c2c9d7e91304b6d037fb017f680d0c6","analyzedAt":"2026-08-14T02:29:11.060Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}