Skip to content

Conversation

@marktech0813
Copy link
Contributor

我找到了 WxCryptUtil.decrypt 函数,并对其进行了加固,通过在切片之前验证解密后的有效载荷长度,避免了 Arrays.copyOfRange 的 IllegalArgumentException 异常。如果数据格式错误(通常是由于 EncodingAESKey 错误或密文损坏),现在会抛出一个清晰的 WxRuntimeException 异常,而不是像之前那样抛出“20 > …”的错误。

构建和测试:

重新构建项目并重试回调验证;现在你应该会得到解密成功的结果,或者一个清晰、可操作的错误信息,而不是 IllegalArgumentException 异常。
我在 WxCryptUtil.decrypt 函数中添加了强大的长度检查,以防止运行时崩溃,并在密钥/密文错误时提供精确的错误消息。

如果仍然遇到“签名校验失败”或新的“数据格式非法”错误:

请确保以下三项完全匹配:token、时间戳、nonce 和确切的 Encrypt 值。
请验证您的 EncodingAESKey 是否适用于您的应用:
WeCom 自建应用:使用 corpId
第三方套件:使用 suiteId
请确保您根据不同的场景传递正确的 receiveid,并且传递的 token/EncodingAESKey 与 WeCom 控制台中配置的 token/EncodingAESKey 一致。

我找到了 WxCryptUtil.decrypt 函数,并对其进行了加固,通过在切片之前验证解密后的有效载荷长度,避免了 Arrays.copyOfRange 函数抛出的 IllegalArgumentException 异常。如果数据格式错误(通常是由于 EncodingAESKey 错误或密文损坏),现在会抛出一个清晰的 WxRuntimeException 异常,而不是像之前那样抛出“20 > …”的错误。

构建和测试:

重新构建项目并重试回调验证;现在你应该会得到解密成功的结果,或者一个清晰、可操作的错误信息,而不是 IllegalArgumentException 异常。

我在 WxCryptUtil.decrypt 函数中添加了强大的长度检查,以防止运行时崩溃,并在密钥/密文错误时提供精确的错误消息。
@marktech0813
Copy link
Contributor Author

请查看拉取请求。

@binarywang binarywang linked an issue Nov 12, 2025 that may be closed by this pull request
@binarywang binarywang requested a review from Copilot November 12, 2025 05:32
Copilot finished reviewing on behalf of binarywang November 12, 2025 05:34
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

此 PR 修复了企业微信 API 回调验签过程中 WxCryptUtil.decrypt 方法可能抛出的 IllegalArgumentException 异常问题。

主要改进:

  • 在数据切片前增加长度验证,避免 Arrays.copyOfRange 参数异常
  • 提供更清晰的错误消息,指出可能的根本原因(错误的密文或 EncodingAESKey)
  • 增强代码鲁棒性,防止因数据格式错误导致的运行时崩溃

…/crypto/WxCryptUtil.java

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@binarywang binarywang merged commit 28fac4e into binarywang:develop Nov 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

企业微信API回调验签错误

2 participants