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.MicroPayDataReq;
import cn.newfeifan.mall.module.pay.fuiou.util.FuiouHttpPoster;
import cn.newfeifan.mall.module.pay.fuiou.util.MD5;

/**
 * 类功能描述
 * MicroPayClient.java
 * 2.2 条码支付
 * 
 * @author user
 * @version 0.1.0
 */
public class MicroPayClient {

	public static String privateKey = "f00dac5077ea11e754e14c9541bc0170";
	
	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/micropay");
		MicroPayDataReq req = new MicroPayDataReq();
		req.setVersion("1.0");
		req.setMchnt_cd("0002900F0313432");
		req.setRandom_str("201707140000015");
		req.setOrder_type("ALIPAY");
		req.setOrder_amt("1");
		req.setMchnt_order_no("200000000000006");//不能重复
		req.setTxn_begin_ts(DateUtils.getCurrentDateTime());
		req.setGoods_des("测试");
		req.setTerm_id("88888888");
		req.setTerm_ip("192.168.8.8");
		req.setAuth_code("4545465465");
		req.setAddn_inf("hyjfservice18217072673");
		StringBuilder sb = new StringBuilder();
		sb.append(req.getMchnt_cd()).append("|").append(req.getOrder_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.getAuth_code()).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);
	}
}
