{"record":{"id":"88847b0dad1f16fd","repo":"binarywang/WxJava","slug":"secret-88847b","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/WxCpServiceImpl.java","lineNumber":132,"sourceCode":"  }\n\n  @Override\n  public String getMsgAuditAccessToken(boolean forceRefresh) throws WxErrorException {\n    final WxCpConfigStorage configStorage = getWxCpConfigStorage();\n    if (!configStorage.isMsgAuditAccessTokenExpired() && !forceRefresh) {\n      return configStorage.getMsgAuditAccessToken();\n    }\n    Lock lock = configStorage.getMsgAuditAccessTokenLock();\n    lock.lock();\n    try {\n      // 拿到锁之后，再次判断一下最新的token是否过期，避免重刷\n      if (!configStorage.isMsgAuditAccessTokenExpired() && !forceRefresh) {\n        return configStorage.getMsgAuditAccessToken();\n      }\n      // 使用会话存档secret获取access_token\n      String msgAuditSecret = configStorage.getMsgAuditSecret();\n      if (msgAuditSecret == null || msgAuditSecret.trim().isEmpty()) {\n        throw new WxErrorException(\"会话存档secret未配置\");\n      }\n      String url = String.format(configStorage.getApiUrl(WxCpApiPathConsts.GET_TOKEN),\n        this.configStorage.getCorpId(), msgAuditSecret);\n      try {\n        HttpGet httpGet = new HttpGet(url);\n        if (getRequestHttpProxy() != null) {\n          RequestConfig config = RequestConfig.custom().setProxy(getRequestHttpProxy()).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);\n        configStorage.updateMsgAuditAccessToken(accessToken.getAccessToken(), accessToken.getExpiresIn());\n      } catch (IOException e) {","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/binarywang/WxJava/blob/1c43293a3c2c9d7e91304b6d037fb017f680d0c6/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpServiceImpl.java#L114-L150","documentation":"Thrown (as checked WxErrorException) by getMsgAuditAccessToken() in the default WxCpServiceImpl when the chat-archive secret is null or blank. The msg-audit secret is a dedicated credential for the 会话存档 feature, separate from both the corp secret and the contact secret.","triggerScenarios":"Any msg-audit operation (chat records, media files, agreement info) through the default WxCpServiceImpl when configStorage.getMsgAuditSecret() is null or empty.","commonSituations":"Config object created without calling setMsgAuditSecret(); the 会话存档 feature is not enabled in the WeChat admin console; the secret env var is absent in production; using WxCpInMemoryConfigStorage which loses state on restart.","solutions":["Call configStorage.setMsgAuditSecret(\"...\") during initialization","In Spring Boot, set wx.cp.msg-audit-secret in application.yml","Enable the 会话存档 feature in the WeChat Work admin console and copy the secret","Also set msgAuditPriKey — decryption will fail without it even if the token succeeds"],"exampleFix":"// before\nconfig.setCorpId(corpId);\nconfig.setCorpSecret(corpSecret);\n// msgAuditSecret and msgAuditPriKey missing\n\n// after\nconfig.setMsgAuditSecret(System.getenv(\"WX_CP_MSG_AUDIT_SECRET\"));\nconfig.setMsgAuditPriKey(System.getenv(\"WX_CP_MSG_AUDIT_PRI_KEY\"));","handlingStrategy":"validation","validationCode":"// Validate msg-audit secret and private key at startup\nString secret = configStorage.getMsgAuditSecret();\nString priKey = configStorage.getMsgAuditPriKey();\nif (StringUtils.isBlank(secret) || StringUtils.isBlank(priKey)) {\n  throw new IllegalStateException(\"会话存档功能需要同时配置 msgAuditSecret 和 msgAuditPriKey\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set both msgAuditSecret and msgAuditPriKey during initialization","Enable 会话存档 in the WeChat Work admin console before using these APIs","For Spring Boot, configure wx.cp.msg-audit-secret and wx.cp.msg-audit-pri-key","Store the RSA private key securely (env var or secret manager)"],"tags":["wechat-cp","config","msg-audit","access-token","secret","default-httpclient"],"backgroundTag":null,"analyzedSha":"1c43293a3c2c9d7e91304b6d037fb017f680d0c6","analyzedAt":"2026-08-14T02:29:11.060Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}