java 微信支付验签失败遇到的坑

微信支付遇到的坑

  1. 微信支付完成后吊起报错签名失败,而签名参数多次重复确认后都没问题就是签名失败
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;
    }



  1. 找了好多问题,最后都无果,最后用最笨的方式,重置了一下秘钥搞定。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值