微信支付遇到的坑
- 微信支付完成后吊起报错签名失败,而签名参数多次重复确认后都没问题就是签名失败
public JsonResult wxPay(String ids) throws Exception {
double total = 0;
String[] orderIds = ids.split(",");
for(int i = 0;i<orderIds.length;i++) {
Order order = this.orderService.getOrderById(Integer.valueOf(orderIds[i]));
if(order != null) {
total += order.getTotalMoney();
}
}
//total = 0.01;
String attach = "{\"order_id\":\"" + ids + "\"}";
//请求预支付订单
Map<String, String> result = wxPayService.dounifiedOrder(total, attach);
Map<String, String> map = new HashMap<String, String>();
WxMD5Util md5Util = new WxMD5Util();
//返回APP端的数据
//参加调起支付的签名字段有且只能是6个,分别为appid、partnerid、prepayid、package、noncestr和timestamp,而且都必须是小写
//参加调起支付的签名字段有且只能是6个,分别为appid、partnerid、prepayid、package、noncestr和timestamp,而且都必须是小写
//参加调起支付的签名字段有且只能是6个,分别为appid、partnerid、prepayid、package、noncestr和timestamp,而且都必须是小写
map.put("appid", result.get("appid"));
map.put("partnerid", result.get("mch_id"));
map.put("prepayid", result.get("prepay_id"));
map.put("package", "Sign=WXPay");
map.put("noncestr", result.get("nonce_str"));
map.put("timestamp", String.valueOf(System.currentTimeMillis() / 1000));//单位为秒
// 这里不要使用请求预支付订单时返回的签名
map.put("sign", md5Util.getSign(map));
map.put("extdata", attach);
return new JsonResult(0, "支付成功", map);
//return map;
}
- 找了好多问题,最后都无果,最后用最笨的方式,重置了一下秘钥搞定。