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

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 cn.newfeifan.mall.module.pay.fuiou.reqdata.WapPreCreateDataReq;
import cn.newfeifan.mall.module.pay.fuiou.reqdata.WebPreCreateDeviceInfo;

/**
 * 类功能描述
 * WapPreCreateClient.java
 * 2.12 扫码wap/app下单
 * 
 * @author user
 * @version 0.1.0
 */
public class WapPreCreateClient {

	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/wapPreCreate");
		WapPreCreateDataReq req = new WapPreCreateDataReq();
		req.setVersion("1.0");
		req.setMchnt_cd("0002900F0370586");
		req.setRandom_str("123456");
		req.setOrder_type("ALIPAY");
		req.setMchnt_order_no("10000000014");//不能重复
		req.setOrder_amt("1");
		req.setTxn_begin_ts(DateUtils.getCurrentDateTime());
		req.setGoods_des("测试");
		req.setTerm_id("0a1b0000");
		req.setTerm_ip("192");
		req.setTrade_type("H5");
		
		// H5 支付场景信息必填！
		WebPreCreateDeviceInfo info = new WebPreCreateDeviceInfo();
		info.setType("Wap");
		info.setApp_name("淘宝");
		info.setApp_url("www.taobao.com");
		req.setReserved_device_info(JSON.toJSONString(info));
		
		req.setNotify_url("http://www.baidu.com");
		StringBuilder sb = new StringBuilder();
		sb.append(req.getMchnt_cd()).append("|").append(req.getOrder_type()).append("|")
                .append(req.getTrade_type()).append("|").append(req.getOrder_amt()).append("|")
                .append(req.getMchnt_order_no()).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);
		System.out.println("请求sign：" + sb);
		req.setSign(MD5.MD5Encode(sb.toString(), "UTF-8"));
		String res = http.newPost(JSON.toJSONString(req));
		System.out.println(res);
	}
}
