2018-08-21 17:20
//统一下单地址 https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_1#
Map params = new HashMap();
String nonceStr = String.valueOf(System.currentTimeMillis() / 1000);
params.put("appid", appid);
params.put("mch_id", partner);
params.put("nonce_str", nonceStr);
params.put("body", "订单");
params.put("attach", "custom json");
params.put("out_trade_no", outtradeno);
params.put("total_fee", String.valueOf(price));
String ip = IpKit.getRealIp(getRequest());
if (StrKit.isBlank(ip)) {
ip = "127.0.0.1";
}
params.put("spbill_create_ip", ip);
params.put("notify_url", notify_url);
params.put("trade_type", "APP");
String sign = PaymentKit.createSign(params, paternerKey);
params.put("sign", sign);
String xmlResult = PaymentApi.pushOrder(params);
System.out.println(xmlResult);
Map result = PaymentKit.xmlToMap(xmlResult);
String return_code = result.get("return_code");
String return_msg = result.get("return_msg");
if (StrKit.isBlank(return_code) || !"SUCCESS".equals(return_code)) {
renderJson("{\"code\":\"201\",\"data\":" + return_msg
+ "}");
return;
}
String result_code = result.get("result_code");
if (StrKit.isBlank(result_code) || !"SUCCESS".equals(result_code)) {
renderJson("{\"code\":\"201\",\"data\":" + return_msg
+ "}");
return;
}
// 以下字段在return_code 和result_code都为SUCCESS的时候有返回
String prepay_id = result.get("prepay_id");
//封装调起微信支付的参数 https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_12
Map packageParams = new HashMap();
packageParams.put("appid", appid);
packageParams.put("partnerid", partner);
packageParams.put("prepayid", prepay_id);
packageParams.put("packagevalue", "Sign=WXPay");
packageParams.put("noncestr", nonceStr);//String.valueOf(System.currentTimeMillis()));
packageParams.put("timestamp", String.valueOf(System.currentTimeMillis() / 1000));
String packageSign = PaymentKit.createSign(packageParams, paternerKey);
packageParams.put("sign", packageSign);
String jsonStr = JsonUtils.toJson(packageParams);
// System.out.println("最新返回apk的参数:"+jsonStr);
renderJson("{\"code\":\"200\",\"data\":" + jsonStr
+ "}");
return;