/**
* 官微-分期支付接口(h5页面支付)
*
* @param request
* @param response
*/
@SuppressWarnings("unchecked")
@ResponseBody
@RequestMapping(value = "/wxWapPrePayH5", method = RequestMethod.POST)
public Map wxWapPrePayH5(HttpServletRequest request, HttpServletResponse response) throws ApplicationException {
logger.info("wxWapPrePay start");
Map resultMap = new HashMap();
String number = request.getParameter("number");
String count = request.getParameter("count");
// 获取合同分期
ContDto contDto = contBaseService.getContractByNumber(number);
if (null == contDto) {
resultMap.put("success", false);
resultMap.put("code", "1");
resultMap.put("body", null);
resultMap.put("msg", "合同分期不存在");
return resultMap;
}
String price = String.valueOf(contDto.installmentEachAmount);
int price100 = new BigDecimal(price).multiply(new BigDecimal(100)).intValue();
if (price100 <= 0) {
resultMap.put("success", false);
resultMap.put("code", "2");
resultMap.put("body", null);
resultMap.put("msg", "还款金额错误");
return resultMap;
}
// 设置回调地址
String notify_url = "回调地址";
//用合同编号+期数+随机时间戳,生成唯一订单号
String numberCount = number + count + "_" +System.currentTimeMillis();
SortedMap parameters = new TreeMap();
parameters.put("appid", ConfigUtil.WAP_APPID);
parameters.put("mch_id", ConfigUtil.WAP_MCH_ID);
parameters.put("nonce_str", PayCommonUtil.CreateNoncestr());
parameters.put("body", "分期账单-还款支付");
parameters.put("out_trade_no", numberCount); // 订单号
parameters.put("fee_type", "CNY");
parameters.put("total_fee", String.valueOf(price100));
parameters.put("spbill_create_ip", CommonUtil.getIpAddress(request));
parameters.put("notify_url", notify_url);
parameters.put("trade_type", "MWEB");
// openid需要获取
// String openid = request.getParameter("openid");
// parameters.put("openid", openid);
parameters.put("scene_info",
"{'h5_info':{'type':'Wap','wap_url':'http://www.lizhenauto.com','wap_name':'利真延保'}}");
// 设置签名
// parameters.put("referer","http://www.lizhenauto.com");
logger.info("得到的集合是-----------" + parameters.toString());
String sign = PayCommonUtil.createWapSign("UTF-8", parameters);
parameters.put("sign", sign);
// 封装请求参数结束
String requestXML = PayCommonUtil.getRequestXml(parameters);
logger.info("requestXML:" + requestXML);
// 调用统一下单接口
String result = PayCommonUtil.httpsRequest(ConfigUtil.UNIFIED_ORDER_URL, "POST", requestXML);
logger.info("\n" + result);
String mweb_url = null;
try {
/** 统一下单接口返回正常的prepay_id,再按签名规范重新生成签名后,将数据传输给APP。参与签名的字段名为appId,partnerId,prepayId,nonceStr,timeStamp,package。注意:package的值格式为Sign=WXPay **/
Map map = XMLUtil.doXMLParse(result);
String resultCode = map.get("result_code");
if ("FAIL".equals(resultCode)) {
if ("201 合同编号重复".equals(map.get("err_code_des"))) {
resultMap.put("success", false);
resultMap.put("code", "201");
resultMap.put("body", null);
resultMap.put("msg", "合同编号重复");
return resultMap;
}
}
logger.info(" map " + map.toString());
String returnCode = map.get("return_code");
if (returnCode.equals("SUCCESS") && resultCode.equals("SUCCESS")) {
mweb_url = map.get("mweb_url");
} else {
resultMap.put("success", false);
resultMap.put("code", "200");// 请求成功
resultMap.put("body", null);
resultMap.put("msg", "微信支付失败");
return resultMap;
}
resultMap.put("success", true);
resultMap.put("code", "200");// 请求成功
resultMap.put("body", mweb_url);
resultMap.put("msg", "微信支付成功,等待支付");
} catch (JDOMException e) {
resultMap.put("success", false);
resultMap.put("code", "500");// 请求失败
resultMap.put("body", null);
resultMap.put("msg", "微信支付失败,请重试");
logger.error(e.toString());
} catch (IOException e) {
resultMap.put("success", false);
resultMap.put("code", "500");// 请求失败
resultMap.put("body", null);
resultMap.put("msg", "微信支付失败,请重试");
logger.error(e.toString());
}
return resultMap;
}