package com.allinpay.demo.trx.qpay;

import com.allinpay.demo.AIPGException;
import com.allinpay.demo.DemoConfig;
import com.allinpay.demo.util.HttpUtil;
import com.allinpay.demo.util.DemoUtil;
import com.allinpay.demo.xml.XmlParser;
import com.allinpay.demo.xstruct.common.AipgReq;
import com.allinpay.demo.xstruct.common.AipgRsp;
import com.allinpay.demo.xstruct.common.InfoReq;
import com.allinpay.demo.xstruct.common.InfoRsp;
import com.allinpay.demo.xstruct.quickpay.FAGRA;
import com.allinpay.demo.xstruct.quickpay.FAGRARET;
import com.allinpay.demo.xstruct.quickpay.PROTOCOLREQ;
import com.allinpay.demo.xstruct.quickpay.PROTOCOLRSP;

/**
 * @Description  快捷签约短信发起
 * @Author meixf@allinpay.com
 * @Date 2018年5月24日
 **/
public class Tranx310006 {

	public static void main(String args[]){
		InfoReq inforeq = DemoUtil.makeReq("310006");

		PROTOCOLREQ fagra = new PROTOCOLREQ();
		fagra.setMERCHANT_ID(DemoConfig.merchantid);
		fagra.setSUBMIT_TIME(DemoUtil.getNow());
		fagra.setBACKURL("GET:http://stg3-lps-web.360shuke.com/static/testpackage/html/one_key_bind_card_continue.html?redirectUrl=bind_authen_input.html&backFlag=1");
		/* fagra.setACCOUNT_TYPE("00"); */
		fagra.setACCOUNT_PROP("0");
		fagra.setBANK_CODE("0308");
		fagra.setSIGN_MODE("3");
		fagra.setID_TYPE("0");
		 fagra.setACCOUNT_NO("6214850201238224"); 
		fagra.setNOTIFYURL("https://stg222-gws-lcs-web.daikuan.360.cn/notify/allinpay/cardbind/result");
		fagra.setID("445224199104190312");
		fagra.setACCOUNT_NAME("林维雄");
		/* fagra.setACCOUNT_NO("6214850201238224"); */
		 fagra.setTEL("13226665872"); 
		AipgReq req = new AipgReq();
		req.setINFO(inforeq);
		req.addTrx(fagra);
		try{
			//step1 对象转xml
			String xml = XmlParser.toXml(req);
			//step2 加签
			String signedXml = DemoUtil.buildSignedXml(xml.replaceAll("\\s+", ""));
			System.out.println( "*******************6666666*********");
			System.out.println(signedXml);
			//step3 发往通联
			String url = DemoConfig.url;
			System.out.println("============================请求报文============================");
			System.out.println(signedXml);
			String respText = HttpUtil.post(signedXml, url);
			System.out.println("============================响应报文============================");
			System.out.println(respText);
			//step4 验签
			if(!DemoUtil.verifyXml(respText)){
				System.out.println("====================================================>验签失败");
				return;
			}
			System.out.println("====================================================>验签成功");
			//step5 xml转对象
			AipgRsp rsp = XmlParser.parseRsp(respText);
			InfoRsp infoRsp = rsp.getINFO();
			System.out.println(infoRsp.getRET_CODE());
			System.out.println(infoRsp.getERR_MSG());
			if("0000".equals(infoRsp.getRET_CODE())){
				PROTOCOLRSP fr = (PROTOCOLRSP)rsp.trxObj();
				System.out.println(fr.getRET_CODE());
				System.out.println(fr.getERR_MSG());
			}
		}catch(AIPGException e){
			e.printStackTrace();
		}
	}
}
