引用几个记录:
https://blog.csdn.net/stilll123456/article/details/80830004
https://segmentfault.com/q/1010000014935905
从微信支付官方下载SDK,并调用 unifiedOrder 方法,一直报 “沙箱验证签名失败,请确认沙箱签名key是否正确
”,始终百思不得其解。
最后自行调用了 requestWithoutCert 方法,才得以通过。以下为实现步骤
WXPayConstants wxPayCon =new WXPayConstants(); PayModelByWx model =new PayModelByWx(); model.setAppid(config.getAppID()); model.setAuth_code(qrcode);//条形码读取结果 model.setSign_type("MD5"); model.setTotal_fee("301");//注意支付金额,要与验收示例中保持一致 model.setMch_id(config.getMchID()); model.setBody("****"); model.setDevice_info("收银台"); model.setOut_trade_no("2020072710595900000012");//自行生成订单号 model.setTrade_type("NATIVE"); model.setNotify_url("http://www.weixin.qq.com/wxpay/pay.php");//回调地址 UUID uuid = UUID.randomUUID(); String str = uuid.toString(); // 去掉"-"符号 String temp = str.substring(0, 8) + str.substring(9, 13) + str.substring(14, 18) + str.substring(19, 23) + str.substring(24); model.setNonce_str(temp);//随机字符 Map<String, String> wxmodel = beanToMap(model); //沙盒模式调试步骤:(注意,沙盒模式下,金额只允许使用验收示例中的数字) //1.根据正常字符数据生成带sign的xml数据 String oldwxxml = payUtil.generateSignedXml(wxmodel,this.config.getKey()); //2.用第1点的sign 调用retrieveSandboxSignKey方法,生成沙盒key String sandboxkey = wxPay.retrieveSandboxSignKey(this.config,this.wxPay,temp,payUtil.xmlToMap(oldwxxml).get("sign")); //3.使用沙盒key再次生成带签名的xml数据 String wxxml = payUtil.generateSignedXml(wxmodel,sandboxkey);
var msgxml = wxPay.requestWithoutCert( WXPayConstants.SANDBOX_UNIFIEDORDER_URL_SUFFIX ,payUtil.xmlToMap(wxxml),this.config.getHttpConnectTimeoutMs(),this.config.getHttpReadTimeoutMs()); Map<String,String> resoutmap = payUtil.xmlToMap(msgxml);return resoutmap;