qq_40867305
轩轩zz
2019-02-26 13:23

调用支付JSAPI缺少参数:total_fee, 跪求大神解答

20
  • 微信公众平台
  • java
  • 微信

Map map = new HashMap<>();
String suijishu = WXPayUtil.generateNonceStr();
String dindanhao = GetRandom.getRandomStringByLength(32);
System.out.println("订单号:"+dindanhao);
map.put("appid",payhospital.getAppid());// appid
map.put("mch_id",payhospital.getMchid());// 商户号
map.put("sign_type","MD5");
map.put("nonce_str",suijishu);// 随机字符串
map.put("body","ceshizhifu");// 商品名称
map.put("notify_url","http://wxzf.yiruan01.com/zuul/user/payhospitalbyid/result"); // 回调地址
map.put("out_trade_no",dindanhao);// 订单号
map.put("spbill_create_ip","47.95.245.237");// 终端ip(调用微信支付API的机器IP)//47.95.245.237
map.put("total_fee","1");// 订单金额 现在默认写死,money
map.put("trade_type","JSAPI"); // 交易类型交易类型
map.put("openid",openid);// openid
//生成签名
//将集合M内非空参数值的参数按照参数名ASCII码从小到大排序
String paixu = GroupWeuxin.formatUrlMap(map,false,false);
// 拼接key
String SignTemp = paixu+"&key="+payhospital.getKeyy();
// MD5加密 并且转换为大写
String sign = Md5Util.getMD5String(SignTemp).toUpperCase();
map.put("sign",sign);
// 将map转换为xml
String xml = WXPayUtil.mapToXml(map);
// 判断签名是否正确
Boolean boo = WXPayUtil.isSignatureValid(xml,payhospital.getKeyy());
System.out.println("判断第一次签名是否正确:"+boo);
String url = "https://api.mch.weixin.qq.com/pay/unifiedorder";
ResponseEntity responseEntity = restTemplate.postForEntity(url,xml,String.class);
String res1 = responseEntity.getBody();
// 获取返回参数到此后台完成
Map map1 = WXPayUtil.xmlToMap(res1);

                              // 准备前台需要的参数APPID   timestamp nonceStr  package  signType  paySign
            Map<String,String> map2 = new HashMap<>();
            // 获取之前返回的prepay_id
            String prepay_id = (String)map1.get("prepay_id");

            map2.put("appId",payhospital.getAppid());
            map2.put("nonceStr",suijishu);
            map2.put("package","prepay_id="+prepay_id);
            map2.put("signType","MD5");
            map2.put("timeStamp",String.valueOf(WXPayUtil.getCurrentTimestamp()));
            //生成签名
            //将集合M内非空参数值的参数按照参数名ASCII码从小到大排序
            String paixu2 = GroupWeuxin.formatUrlMap(map2,false,false);
            // 拼接key
            String SignTemp2 = paixu2+"&key="+payhospital.getKeyy();
            // MD5加密 并且转换为大写
            String sign2 = Md5Util.getMD5String(SignTemp2).toUpperCase();
            map2.put("paySign",sign2);
            // 判断签名是否正确
            Boolean bool = WXPayUtil.isSignatureValid(map2,payhospital.getKeyy(),WXPayConstants.SignType.MD5);
            System.out.println("第二次:"+bool);

第一次成功返回prepay_id第二次签名出错,调用支付JSAPI缺少参数:total_fee
求解答!!!!!!!!!!!!!!

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答