Skip to content

查询客诉列表验签问题:Last unit does not have enough valid bits #371

@copysunday

Description

@copysunday

错误描述

线上调用查询客诉列表偶发这个错误,而且无法重现,找客服永远是机器人:
java.lang.IllegalArgumentException: Last unit does not have enough valid bits
at java.util.Base64$Decoder.decode0(Base64.java:734)
at java.util.Base64$Decoder.decode(Base64.java:526)
at java.util.Base64$Decoder.decode(Base64.java:549)
at com.wechat.pay.java.core.cipher.AbstractVerifier.verify(AbstractVerifier.java:39)
at com.wechat.pay.java.core.cipher.AbstractVerifier.verify(AbstractVerifier.java:60)
at com.wechat.pay.java.core.auth.WechatPay2Validator.validate(WechatPay2Validator.java:61)
at com.wechat.pay.java.core.http.AbstractHttpClient.validateResponse(AbstractHttpClient.java:86)
at com.wechat.pay.java.core.http.AbstractHttpClient.execute(AbstractHttpClient.java:45)

weixin get request. url=https://api.mch.weixin.qq.com/v3/merchant-service/complaints-v2?end_date=2025-05-30&offset=0&begin_date=2025-05-29&limit=50
 

重现bug的步骤

无法重现,一样的参数打到同样的机器都是正常的

预期行为

1

导致错误的代码片段

protected boolean verify(X509Certificate certificate, String message, String signature) {
    try {
      Signature sign = Signature.getInstance(algorithmName);
      sign.initVerify(certificate);
      sign.update(message.getBytes(StandardCharsets.UTF_8));
      return sign.verify(Base64.getDecoder().decode(signature));
    } catch (SignatureException e) {
      return false;
    } catch (InvalidKeyException e) {
      throw new IllegalArgumentException("verify uses an illegal certificate.", e);
    } catch (NoSuchAlgorithmException e) {
      throw new UnsupportedOperationException(
          "The current Java environment does not support " + algorithmName, e);
    }
  }

操作系统

linux

Java 版本

Java 8

wechatpay-java 版本

0.2.12

其他信息

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions