{"record":{"id":"1ccd28385c83aa5e","repo":"binarywang/WxJava","slug":"getchatdata-err-ret","errorCode":null,"errorMessage":"getchatdata err ret {}","messagePattern":"getchatdata err ret (.+?)","errorType":"exception","errorClass":"WxErrorException","httpStatus":null,"severity":"error","filePath":"weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpMsgAuditServiceImpl.java","lineNumber":58,"sourceCode":"  private final WxCpService cpService;\n\n  /** 每个线程持有独立 SDK 实例，懒初始化，线程内跨调用复用 */\n  private final ThreadLocal<Long> threadLocalSdk = new ThreadLocal<>();\n\n  /** 跟踪所有已创建的 SDK，用于 closeAllSdks() 统一清理 */\n  private final Set<Long> managedSdks = ConcurrentHashMap.newKeySet();\n\n  @Override\n  public WxCpChatDatas getChatDatas(long seq, @NonNull long limit, String proxy, String passwd,\n                                    @NonNull long timeout) throws Exception {\n    // 旧版 API：每次调用创建新 SDK，由调用方负责通过 Finance.DestroySdk(chatDatas.getSdk()) 释放\n    long sdk = this.createSdk();\n\n    long slice = Finance.NewSlice();\n    long ret = Finance.GetChatData(sdk, seq, limit, proxy, passwd, timeout, slice);\n    if (ret != 0) {\n      Finance.FreeSlice(slice);\n      throw new WxErrorException(\"getchatdata err ret \" + ret);\n    }\n\n    // 拉取会话存档\n    String content = Finance.GetContentFromSlice(slice);\n    Finance.FreeSlice(slice);\n    WxCpChatDatas chatDatas = WxCpChatDatas.fromJson(content);\n    if (chatDatas.getErrCode().intValue() != 0) {\n      throw new WxErrorException(chatDatas.toJson());\n    }\n\n    chatDatas.setSdk(sdk);\n    return chatDatas;\n  }\n\n  /**\n   * 获取当前线程的 SDK，不存在则初始化。\n   * SDK 在线程内跨调用复用，无需每次重新初始化。\n   *","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/binarywang/WxJava/blob/1c43293a3c2c9d7e91304b6d037fb017f680d0c6/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpMsgAuditServiceImpl.java#L40-L76","documentation":"Thrown as WxErrorException (checked) in getChatDatas when the native Finance.GetChatData() function returns a non-zero ret code. The Finance library is the WeCom-provided native SDK (JNI) for fetching conversation archive data. A non-zero return indicates the SDK rejected the request internally, before any data slice was populated.","triggerScenarios":"Calling cpService.getMsgAuditService().getChatDatas(seq, limit, proxy, passwd, timeout) where the underlying Finance.GetChatData returns non-zero. Common ret codes include 10002 (incorrect secret), 10003 (incorrect SDK path), 10004 (incorrect private key), and network/timeout failures.","commonSituations":"The msgAuditSecret or corpId used in Finance.Init was wrong, the native library files failed to load correctly, or there is a proxy/network issue reaching the WeCom archive endpoint. The SDK was created successfully (createSdk passed) but the data-fetch call failed.","solutions":["Inspect the numeric ret code in the exception message to identify the root cause (e.g., 10002 = secret error, 10003 = SDK path error).","Verify the msgAuditSecret matches the conversation archive secret from the WeCom admin console (not the general corp secret).","Check that the native Finance library files are loaded for the correct OS/architecture and that Finance.Init succeeded.","If using a proxy, verify proxy and password parameters are correct."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    WxCpChatDatas chatDatas = cpService.getMsgAuditService().getChatDatas(seq, limit, proxy, passwd, timeout);\n} catch (WxErrorException e) {\n    String msg = e.getMessage(); // contains numeric ret code\n    if (msg.contains(\"ret 10002\")) {\n        // incorrect secret - update msgAuditSecret\n    } else if (msg.contains(\"ret 10003\")) {\n        // incorrect SDK path - fix msgAuditLibPath\n    }\n    log.error(\"getChatDatas failed: {}\", msg, e);\n    throw e;\n}","preventionTips":["Verify the msgAuditSecret and corpId are correct before deploying to production.","Test the Finance SDK initialization and data fetch in a staging environment first.","Log the full ret code for diagnosis; map common codes (10002=secret, 10003=path) to actionable fixes."],"tags":["weixin-cp","msg-audit","finance-sdk","native","config"],"backgroundTag":null,"analyzedSha":"1c43293a3c2c9d7e91304b6d037fb017f680d0c6","analyzedAt":"2026-08-14T02:29:11.060Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}