{"record":{"id":"3a64d54a71635d96","repo":"binarywang/WxJava","slug":"secret-3a64d5","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/WxCpServiceApacheHttpClientImpl.java","lineNumber":139,"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, ApacheBasicResponseHandler.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":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/binarywang/WxJava/blob/1c43293a3c2c9d7e91304b6d037fb017f680d0c6/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceApacheHttpClientImpl.java#L121-L157","documentation":"Thrown (as checked WxErrorException) by getMsgAuditAccessToken() in the Apache HttpClient implementation when the chat-archive secret (会话存档secret) is null or blank. This secret is required to obtain a dedicated access_token for the message-audit (会话存档) Finance SDK.","triggerScenarios":"Calling any msg-audit method that needs an access_token (getChatRecords, getMediaFile, etc.) via the Apache HttpClient service when configStorage.getMsgAuditSecret() returns null or blank.","commonSituations":"The config storage was initialized without setMsgAuditSecret(); the 会话存档 feature was not enabled in the WeChat Work admin console so the secret was never obtained; the secret env var is missing in production; using a multi-config (multi-corp) setup where one config object lacks the msgAudit secret.","solutions":["Set the msg-audit secret via configStorage.setMsgAuditSecret(\"your-msg-audit-secret\") during initialization","In Spring Boot starter, set wx.cp.msg-audit-secret in application.yml","Confirm the 会话存档 feature is enabled in the WeChat Work admin console and copy the exact secret","Ensure all corp configs in a multi-tenant setup include the msgAudit secret if they use archive features"],"exampleFix":"// before\nWxCpDefaultConfigImpl config = new WxCpDefaultConfigImpl();\nconfig.setCorpId(\"corp123\");\nconfig.setCorpSecret(\"app-secret\");\n// msgAuditSecret not set → getMsgAuditAccessToken fails\n\n// after\nconfig.setMsgAuditSecret(System.getenv(\"WX_CP_MSG_AUDIT_SECRET\"));\nconfig.setMsgAuditPriKey(System.getenv(\"WX_CP_MSG_AUDIT_PRI_KEY\")); // also needed for decryption","handlingStrategy":"validation","validationCode":"// Validate msg-audit secret at startup\nString msgAuditSecret = configStorage.getMsgAuditSecret();\nif (StringUtils.isBlank(msgAuditSecret)) {\n  throw new IllegalStateException(\"启动检查失败：会话存档 secret 未配置\");\n}\nString priKey = configStorage.getMsgAuditPriKey();\nif (StringUtils.isBlank(priKey)) {\n  throw new IllegalStateException(\"启动检查失败：会话存档私钥 msgAuditPriKey 未配置\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set both msgAuditSecret and msgAuditPriKey during initialization — both are needed","Confirm the 会话存档 feature is enabled in the WeChat Work admin console","Use env vars or a secrets manager for these credentials","For Spring Boot, configure wx.cp.msg-audit-secret and wx.cp.msg-audit-pri-key"],"tags":["wechat-cp","config","msg-audit","access-token","secret","apache-httpclient"],"backgroundTag":null,"analyzedSha":"1c43293a3c2c9d7e91304b6d037fb017f680d0c6","analyzedAt":"2026-08-14T02:29:11.060Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}