package cn.newfeifan.mall.module.pay.fuiou.client;


import cn.newfeifan.mall.module.pay.fuiou.reqdata.WxPreCreateDataReq;
import cn.newfeifan.mall.module.pay.fuiou.util.DateUtils;
import cn.newfeifan.mall.module.pay.fuiou.util.FuiouHttpPoster;
import cn.newfeifan.mall.module.pay.fuiou.util.MD5;
import com.alibaba.fastjson.JSON;

/**
 * 
 *2.6 公众号或服务窗下单
 * WxPreCreateClient.java
 *
 * @history 2017年7月17日  创建WxPreCreateClient.java
 * 
 * @version 0.1.0
 */
public class WxPreCreateClient {
	
//    public static String privateKey = "4e092f20607e11e71d2214ad47a356fa";
    public static String privateKey = "b58ef4203dbe11ef3effcedc419c26ae";

	public static void main(String[] args) throws Exception {
		FuiouHttpPoster http = new FuiouHttpPoster();
		http.setCharset("utf-8");
		http.setUrl("https://aipay.fuioupay.com/aggregatePay/wxPreCreate");
		WxPreCreateDataReq req = new WxPreCreateDataReq();
		req.setTerm_id("88888888");
		req.setTerm_ip("192.168.8.8");
		req.setRandom_str(DateUtils.getCurrentDate("yyyyMMddHHmmss")
					+ "568974");
		req.setMchnt_cd("0006420F7357129");
		req.setTrade_type("JSAPI");
//		req.setOpenid("osMm86Ggu3iLCkdCO2j4Zan-fHOQ");//微信支付此字段必填
//		req.setSub_openid("221122121");//支付宝支付此字段必填
		req.setOrder_amt("1");
		req.setGoods_des("测试订单");
		req.setMchnt_order_no("16103-202407102054211-top-up");//不能重复
		req.setTxn_begin_ts(DateUtils.getCurrentDate("yyyyMMddHHmmss"));
		req.setNotify_url("https://zxgz.newfeifan.cn/fuYou/pay/order/notify");
		req.setVersion("1.0");
		StringBuilder sb = new StringBuilder();
		sb.append(req.getMchnt_cd().trim()).append("|")
		.append(req.getTrade_type().trim()).append("|")
		.append(req.getOrder_amt().trim()).append("|")
		.append(req.getMchnt_order_no().trim()).append("|")
		.append(req.getTxn_begin_ts()).append("|")
		.append(req.getGoods_des()).append("|")
		.append(req.getTerm_id()).append("|")
		.append(req.getTerm_ip()).append("|")
		.append(req.getNotify_url()).append("|")
		.append(req.getRandom_str()).append("|")
		.append(req.getVersion()).append("|")
		.append(privateKey);
		req.setSign(MD5.MD5Encode(sb.toString()));
		String res = http.newPost(JSON.toJSONString(req));
		System.out.println("=====resp=====");
		System.out.println(res);
	}
}
