binarywang/WxJava · error · WxErrorException

getchatdata err ret {}

Error message

getchatdata err ret {}

What it means

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.

Source

Thrown at weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpMsgAuditServiceImpl.java:58

  private final WxCpService cpService;

  /** 每个线程持有独立 SDK 实例,懒初始化,线程内跨调用复用 */
  private final ThreadLocal<Long> threadLocalSdk = new ThreadLocal<>();

  /** 跟踪所有已创建的 SDK,用于 closeAllSdks() 统一清理 */
  private final Set<Long> managedSdks = ConcurrentHashMap.newKeySet();

  @Override
  public WxCpChatDatas getChatDatas(long seq, @NonNull long limit, String proxy, String passwd,
                                    @NonNull long timeout) throws Exception {
    // 旧版 API:每次调用创建新 SDK,由调用方负责通过 Finance.DestroySdk(chatDatas.getSdk()) 释放
    long sdk = this.createSdk();

    long slice = Finance.NewSlice();
    long ret = Finance.GetChatData(sdk, seq, limit, proxy, passwd, timeout, slice);
    if (ret != 0) {
      Finance.FreeSlice(slice);
      throw new WxErrorException("getchatdata err ret " + ret);
    }

    // 拉取会话存档
    String content = Finance.GetContentFromSlice(slice);
    Finance.FreeSlice(slice);
    WxCpChatDatas chatDatas = WxCpChatDatas.fromJson(content);
    if (chatDatas.getErrCode().intValue() != 0) {
      throw new WxErrorException(chatDatas.toJson());
    }

    chatDatas.setSdk(sdk);
    return chatDatas;
  }

  /**
   * 获取当前线程的 SDK,不存在则初始化。
   * SDK 在线程内跨调用复用,无需每次重新初始化。
   *

View on GitHub (pinned to 1c43293a3c)

Solutions

  1. Inspect the numeric ret code in the exception message to identify the root cause (e.g., 10002 = secret error, 10003 = SDK path error).
  2. Verify the msgAuditSecret matches the conversation archive secret from the WeCom admin console (not the general corp secret).
  3. Check that the native Finance library files are loaded for the correct OS/architecture and that Finance.Init succeeded.
  4. If using a proxy, verify proxy and password parameters are correct.
Defensive patterns

Strategy: try-catch

Try / catch

try {
    WxCpChatDatas chatDatas = cpService.getMsgAuditService().getChatDatas(seq, limit, proxy, passwd, timeout);
} catch (WxErrorException e) {
    String msg = e.getMessage(); // contains numeric ret code
    if (msg.contains("ret 10002")) {
        // incorrect secret - update msgAuditSecret
    } else if (msg.contains("ret 10003")) {
        // incorrect SDK path - fix msgAuditLibPath
    }
    log.error("getChatDatas failed: {}", msg, e);
    throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of binarywang/WxJava@1c43293a3c (2026-08-14). Data as JSON: /api/errors/1ccd28385c83aa5e. Report an issue: GitHub.