Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

weixin-java-pay 3.8.0支付回调验签失败 #1671

Closed
bozer666 opened this issue Jul 16, 2020 · 4 comments
Closed

weixin-java-pay 3.8.0支付回调验签失败 #1671

bozer666 opened this issue Jul 16, 2020 · 4 comments

Comments

@bozer666
Copy link

bozer666 commented Jul 16, 2020

我从3.7.0升到3.8.0发现支付回调验签失败,原因就是从回调报文里取到的signType为null导致sign不对

报文为

String xmlData = "<xml><appid><![CDATA[wx5c142********]]></appid>\n" +
                "<bank_type><![CDATA[OTHERS]]></bank_type>\n" +
                "<cash_fee><![CDATA[2000]]></cash_fee>\n" +
                "<fee_type><![CDATA[CNY]]></fee_type>\n" +
                "<is_subscribe><![CDATA[Y]]></is_subscribe>\n" +
                "<mch_id><![CDATA[158*****]]></mch_id>\n" +
                "<nonce_str><![CDATA[1594782996522]]></nonce_str>\n" +
                "<openid><![CDATA[oE4SP*************]]></openid>\n" +
                "<out_trade_no><![CDATA[2020**********]]></out_trade_no>\n" +
                "<result_code><![CDATA[SUCCESS]]></result_code>\n" +
                "<return_code><![CDATA[SUCCESS]]></return_code>\n" +
                "<sign><![CDATA[474CB1037F020276A242F7AC0410D7BB0F3CEB34AEA97F89EEB67B659649FF84]]></sign>\n" +
                "<time_end><![CDATA[20200715111648]]></time_end>\n" +
                "<total_fee>2000</total_fee>\n" +
                "<trade_type><![CDATA[JSAPI]]></trade_type>\n" +
                "<transaction_id><![CDATA[4200000592************]]></transaction_id>\n" +
                "</xml>";
  • 3.7.0
@Override
  public WxPayOrderNotifyResult parseOrderNotifyResult(String xmlData) throws WxPayException {
    try {
      log.debug("微信支付异步通知请求参数:{}", xmlData);
      WxPayOrderNotifyResult result = WxPayOrderNotifyResult.fromXML(xmlData);
      log.debug("微信支付异步通知请求解析后的对象:{}", result);
      // 这里的signType 不是应该取 微信传过来的signType么?
      **result.checkResult(this, this.getConfig().getSignType(), false);**
      return result;
    } catch (WxPayException e) {
      throw e;
    } catch (Exception e) {
      throw new WxPayException("发生异常!", e);
    }
  }
  • 3.8.0
@Override
  public WxPayOrderNotifyResult parseOrderNotifyResult(String xmlData) throws WxPayException {
    try {
      log.debug("微信支付异步通知请求参数:{}", xmlData);
      WxPayOrderNotifyResult result = WxPayOrderNotifyResult.fromXML(xmlData);
      log.debug("微信支付异步通知请求解析后的对象:{}", result);
      **result.checkResult(this, result.getSignType(), false);**
      return result;
    } catch (WxPayException e) {
      throw e;
    } catch (Exception e) {
      throw new WxPayException("发生异常!", e);
    }
  }

此处如果只从报文里面取是不是不太合适,报文里面是可能没有的,和公众号文档写的不太一样,改成从报文取不到就从配置文件取会不会好点

@bozer666
Copy link
Author

@binarywang 麻烦看一下,谢谢

@binarywang
Copy link
Owner

binarywang commented Jul 16, 2020

其实还有另一个方法,传入signType的,建议使用这个.
最新代码参考:
https://github.com/Wechat-Group/WxJava/blob/develop/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java

@bozer666
Copy link
Author

bozer666 commented Jul 16, 2020

这样的话是可以解决,那我现在只能回退到3.7.0或者重写这个方法了

改成从报文取不到就从配置文件取会不会好一点

@Override
    public WxPayOrderNotifyResult parseOrderNotifyResult(String xmlData) throws WxPayException {
        try {
            log.debug("微信支付异步通知请求参数:{}", xmlData);
            WxPayOrderNotifyResult result = WxPayOrderNotifyResult.fromXML(xmlData);
            log.debug("微信支付异步通知请求解析后的对象:{}", result);
            result.checkResult(this, result.getSignType() != null ? result.getSignType() : this.getConfig().getSignType(), false);
            return result;
        } catch (WxPayException e) {
            throw e;
        } catch (Exception e) {
            throw new WxPayException("发生异常!", e);
        }
    }

@binarywang
Copy link
Owner

这样的话是可以解决,那我现在只能回退到3.7.0或者重写这个方法了

改成从报文取不到就从配置文件取会不会好一点

@Override
    public WxPayOrderNotifyResult parseOrderNotifyResult(String xmlData) throws WxPayException {
        try {
            log.debug("微信支付异步通知请求参数:{}", xmlData);
            WxPayOrderNotifyResult result = WxPayOrderNotifyResult.fromXML(xmlData);
            log.debug("微信支付异步通知请求解析后的对象:{}", result);
            result.checkResult(this, result.getSignType() != null ? result.getSignType() : this.getConfig().getSignType(), false);
            return result;
        } catch (WxPayException e) {
            throw e;
        } catch (Exception e) {
            throw new WxPayException("发生异常!", e);
        }
    }

你用最新测试版即可,不用回退到老版本的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants