wechatpay-apiv3/wechatpay-java

微信支付退款回调50%概率报验证异常

ORAOranger opened this issue · 1 comments

错误描述

微信支付退款回调,未对请求参数进行处理,按照官方文档设置参数解析,50%概率报java.lang.IllegalArgumentException: Last unit does not have enough valid bits错误,50%概率不会报错

代码逻辑:
String payResult = getWxPayResult(request);

    // 签名
    String wechatpaySignature = request.getHeader("Wechatpay-Signature");
    String wechatpayTimestamp = request.getHeader("Wechatpay-Timestamp");
    String wechatpayNonce = request.getHeader("Wechatpay-Nonce");
    String wechatpaySerial = request.getHeader("Wechatpay-Serial");

    // 构造 RequestParam
    RequestParam requestParam = new RequestParam.Builder()
            .serialNumber(wechatpaySerial)
            .nonce(wechatpayNonce)
            .signature(wechatpaySignature)
            .timestamp(wechatpayTimestamp)
            .body(payResult)
            .build();

    // 初始化 NotificationParser
    NotificationParser parser = new NotificationParser(WechatPayUtil.getWechatPayConfig());

报错信息:
微信支付退款回调信息:{"id":"fc13b491-cef3-5f64-aca3-132fb1c3e857","create_time":"2024-07-11T10:33:32+08:00","resource_type":"encrypt-resource","event_type":"REFUND.SUCCESS","summary":"退款成功","resource":{"original_type":"refund","algorithm":"AEAD_AES_256_GCM","ciphertext":"WVMmoIEEecP2XCF0nxDhOYlzo0HGAFfINhKQ3QNwG5COznkHPuNji1ICCbpm7Guk7J4vDR42l3Ln6VOGH5zbKN845mcOPFs4pfqpWdhLWHRvPAJSqu1kT77wy8w3R7RS4RSdIXSjHyAC+UrM/pRmhXoOY6BNwuEMRI5GCOAE/eyZFNztGSnHiR+Trr2Yp9QYiSVcghOsja+0itjP1B58C8meN4oi7qM76Bou2IVQvQPYFk6FiuVKPwdadt9am2Ub0/oTLIJn6lLfReV5FPFap8bkvQWhZR6v3zVUya9G4lSO3w7/x71NaRwF7gAXUK/N8JHLaVCrrrLs4XT4wgx305Vv5Ys1DS5XtAsOgrup/HwEpq0TSUnsWz8/sGtSzdx6hr3YF4e+wsHcHn+2Ax2T4uO7xCb6hGVYYfJF8hSCtVdv0BzFfhoiolAYlQaMlf+Jl1XeWBLdq6iZpVSVaeGi+XArOBbgZK3VhleSYDKHG8jpC/IFi4Azg5zfUgploIghkmV8wqNV","associated_data":"refund","nonce":"FLr5LFVFTFJ8"}}

java.lang.IllegalArgumentException: Last unit does not have enough valid bits
at java.base/java.util.Base64$Decoder.decode0(Base64.java:766) ~[na:na]
at java.base/java.util.Base64$Decoder.decode(Base64.java:538) ~[na:na]
at java.base/java.util.Base64$Decoder.decode(Base64.java:561) ~[na:na]
at com.wechat.pay.java.core.cipher.AbstractVerifier.verify(AbstractVerifier.java:39) ~[wechatpay-java-core-0.2.12.jar!/:0.2.12]
at com.wechat.pay.java.core.cipher.AbstractVerifier.verify(AbstractVerifier.java:60) ~[wechatpay-java-core-0.2.12.jar!/:0.2.12]
at com.wechat.pay.java.core.notification.NotificationParser.validateRequest(NotificationParser.java:90) ~[wechatpay-java-core-0.2.12.jar!/:0.2.12]
at com.wechat.pay.java.core.notification.NotificationParser.parse(NotificationParser.java:49) ~[wechatpay-java-core-0.2.12.jar!/:0.2.12]

重现bug的步骤

  1. 用户发起退款申请
  2. 商家确认退款
  3. 退款回调接收请求

预期行为

直接获取微信支付退款回调参数,调用SDK解析为对象,不应偶发报验证异常,有时成功有时报异常

导致错误的代码片段

No response

操作系统

CentOS

Java 版本

Java 11

wechatpay-java 版本

v0.2.12

其他信息

No response

问题重复
见:#223