收藏
回答

支付回调,wxPayService.parseOrderNotifyV3Result一直报null?

jar包

com.github.binarywang
weixin-java-pay
4.5.3.B


观看的接口文档

支付通知API

https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_5.shtml

JAVA代码 service层

注:数据都已经接受到了 PayNotifyForm 是通知接口传过来的参数

public void payNotify(String appid, PayNotifyForm payNotifyForm, HttpServletResponse response, HttpServletRequest request) throws Exception {
   // 自己写的创建WxPayService 对象方法 将 密钥证书等等输入
    WxPayService wxPayService = this.getWxPayService(appid);

    SignatureHeader signatureHeader = new SignatureHeader();
    signatureHeader.setTimeStamp(response.getHeader("Wechatpay-Timestamp"));
    signatureHeader.setNonce(response.getHeader("Wechatpay-Nonce"));
    signatureHeader.setSerial(response.getHeader("Wechatpay-Serial"));
    signatureHeader.setSignature(response.getHeader("Wechatpay-Signature"));

    // 这段代码一开始没有加,现在加了还是在报错 
    SignatureHeader.SignatureHeaderBuilder builder = signatureHeader.builder();
    builder.timeStamp(response.getHeader("Wechatpay-Timestamp"));
    builder.nonce(response.getHeader("Wechatpay-Nonce"));
    builder.serial(response.getHeader("Wechatpay-Serial"));
    builder.signature(response.getHeader("Wechatpay-Signature"));

    WxPayNotifyV3Result notifyV3Result = wxPayService.parseOrderNotifyV3Result(payNotifyForm.getResource().getCiphertext(), signatureHeader);
}

private WxPayService getWxPayService(String appid){
    WxPayConfig payConfig = new WxPayConfig();
    payConfig.setAppId(appid);
    payConfig.setMchId(StringUtils.trimToNull(this.properties.getMchId()));
    payConfig.setMchKey(StringUtils.trimToNull(this.properties.getMchKey()));
    payConfig.setKeyPath(StringUtils.trimToNull(this.properties.getKeyPath()));
    payConfig.setApiV3Key(StringUtils.trimToNull(this.properties.getAPIv3()));
    payConfig.setPrivateKeyPath(StringUtils.trimToNull(this.properties.getPrivateKeyPath()));
    payConfig.setPrivateCertPath(StringUtils.trimToNull(this.properties.getPrivateCertPath()));
    // 可以指定是否使用沙箱环境
    payConfig.setUseSandboxEnv(false);

    WxPayService wxPayService = new WxPayServiceImpl();
    wxPayService.setConfig(payConfig);
    return wxPayService;
}


报错代码

 wxPayService.parseOrderNotifyV3Result(payNotifyForm.getResource().getCiphertext(), signatureHeader);


报错输出

java.lang.NullPointerException: null

后台输出的一些参数

最后一次编辑于  2023-08-09
回答关注问题邀请回答
收藏

1 个回答

  • 行云
    行云
    02-21

    从response中获取header当然是空啊,应该从request中获取。

    02-21
    有用
    回复
登录 后发表内容