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;

import static cn.newfeifan.mall.module.pay.enums.DictTypeConstants.*;

/**
 * 
 *2.6 公众号或服务窗下单
 * WxPreCreateClient.java
 * 2017年7月17日  创建WxPreCreateClient.java
 * 
 * @version 0.1.0
 */
public class WxPreCreateClient {
	
	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/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("0002900F0370586");
		req.setTrade_type("FWC");
		req.setOpenid("oDax96l0bZdXqRQ2uVfn_2LV-DxM");//微信支付此字段必填
//		req.setSub_openid("221122121");//支付宝支付此字段必填
		req.setOrder_amt("1");
		req.setGoods_des("测试订单");
		req.setMchnt_order_no("201707191000000000011");//不能重复
		req.setTxn_begin_ts(DateUtils.getCurrentDate("yyyyMMddHHmmss"));
		req.setNotify_url("wwww.baidu.com");
		req.setVersion("1.0");
        String sb = req.getMchnt_cd().trim() + "|" +
                req.getTrade_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("=====resp=====");
		System.out.println(res);
	}
}
