Skip to content

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

Closed
@bozer666

Description

我从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);
    }
  }

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

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions