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


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

/**
 * 
 * 2.1 统一下单
 * PreCreateClient.java
 *  2017年7月17日  创建PreCreateClient.java
 * 
 * @version 0.1.0
 */
public class PreCreateClient {
	
    public static String privateKey = "4e092f20607e11e71d2214ad47a356fa";
    
	public static void main(String[] args) throws Exception {
		FuiouHttpPoster http = new FuiouHttpPoster();
		http.setCharset("utf-8");
		http.setUrl("http://192.168.8.45:45002/aggregatePay/preCreate");
		PreCreateDataReq  req = new PreCreateDataReq();
		req.setTerm_id("88888888");
		req.setTerm_ip("192.168.8.8");
		req.setRandom_str("20170714000006");//随机字符串
		req.setMchnt_cd("0002900F0370586");
		req.setOrder_type("QQ");
		req.setOrder_amt("1");
		req.setGoods_des("测试订单1");
		req.setMchnt_order_no("2017082910000000890003");//不能重复
		req.setTxn_begin_ts(DateUtils.getCurrentDateTime());//交易开始时间
		req.setNotify_url("wwww.baidu.com");
		req.setVersion("1.0");
        String sb = req.getMchnt_cd().trim() + "|" +
                req.getOrder_type().trim() + "|" +
                req.getOrder_amt().trim() + "|" +
                req.getMchnt_order_no().trim() + "|" +
                req.getTxn_begin_ts() + "|" +
                req.getGoods_des() + "|" +
                req.getTerm_id() + "|" +
                req.getTerm_ip() + "|" +
                req.getNotify_url() + "|" +
                req.getRandom_str() + "|" +
                req.getVersion() + "|" +
                privateKey;
		req.setSign(MD5.MD5Encode(sb));
		String res = http.newPost(JSON.toJSONString(req));
		System.out.println(res);
		
	}
}
