微信公众号支付签名验证错误

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_27786919/article/details/82906831

 微信公众号支付签名验证错误有两种可能

1.参数不正确

   可以使用官方工具检测,看看生成的签名和官方工具生成的签名是否相同,如果相同还是提示签名不正确则可能是第二种情况

2.sign_type不一致

最新微信支付提供的SDK代码中,统一下单接口sign_type是置为 HMAC-SHA256 而不是使用默认的 MD5,而公众号内发起支付的签名只能使用 MD5,正是这种不一致导致了签名验证错误,将统一下单的签名类型改成MD5即可。

可以看最新sdk代码,沙箱环境是MD5,而真正使用却是HMAC-SHA256 ,将其修改为MD5即可。

  public WXPay(final WXPayConfig config, final String notifyUrl, final boolean autoReport, final boolean useSandbox) throws Exception {
        this.config = config;
        this.notifyUrl = notifyUrl;
        this.autoReport = autoReport;
        this.useSandbox = useSandbox;
        if (useSandbox) {
            this.signType = SignType.MD5; // 沙箱环境
        }
        else {
            this.signType = SignType.HMAC-SHA256;
        }
        this.wxPayRequest = new WXPayRequest(config);
    }

猜你喜欢

转载自blog.csdn.net/qq_27786919/article/details/82906831
今日推荐