1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
| public Map<String, String> pay(PayVo payVo) { log.info("===微信支付开始==="); String openId = payVo.getOpenId(); BigDecimal money = payVo.getMoney(); String orderId = payVo.getOrderId(); Map<String, String> param = new HashMap<>(); param.put("appid", appid); param.put("body", "xxx订单" + orderId); param.put("mch_id", mch_id); param.put("nonce_str", WXPayUtil.generateNonceStr()); param.put("notify_url", "填写自己的https的回调"); param.put("openid", openId); param.put("out_trade_no", orderId); param.put("spbill_create_ip", payVo.getIp()); param.put("total_fee", String.valueOf((money.multiply(new BigDecimal(100))))); param.put("trade_type", "JSAPI"); String xml; String xmlStr; Map<String, String> result = new HashMap<>(); try { String sign = WXPayUtil.generateSignature(param, payKey); param.put("sign", sign); xml = WXPayUtil.mapToXml(param); String url = "https://" + WXPayConstants.DOMAIN_API + WXPayConstants.UNIFIEDORDER_URL_SUFFIX; xmlStr = HttpUtils.sendPost(url, xml); log.info("微信支付返回的数据为=》" + xmlStr); Map<String, String> stringStringMap = WXPayUtil.xmlToMap(xmlStr); log.info("返回转换的map数据=》" + stringStringMap); if (stringStringMap.get("return_code").equals("SUCCESS")) { result.put("appId", appid); result.put("timeStamp", WXPayUtil.getCurrentTimestamp() + ""); result.put("nonceStr", WXPayUtil.generateNonceStr()); result.put("signType", WXPayConstants.MD5); result.put("package", "prepay_id=" + stringStringMap.get("prepay_id")); result.put("paySign", WXPayUtil.generateSignature(result, payKey)); log.info("微信支付拼装数据=》" + result); } else { result.put("code", "401"); result.put("message", stringStringMap.get("PARAM_ERROR")); log.error("微信支付错误!==》订单号==>" + orderId); return result; } } catch (Exception e) { e.printStackTrace(); } return result; }
|