/* * LoadRunner Java script. (Build: _build_number_) * * Script Description: * */ package com.trunkbow.comm.serviceTest; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Random; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import com.trunkbow.comm.service.impl.XmlSignature; import com.trunkbow.comm.util.HttpClientHelper; import lrapi.lr; public class Actions { public int init() throws Throwable { return 0; }//end of init public int action() throws Throwable { testPay(); return 0; }//end of action public int end() throws Throwable { return 0; }//end of end Log log = LogFactory.getLog(PayTest.class); public void testPay() throws Exception { Date currentTime = new Date(); SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd HH:mm:ss"); String date = formatter.format(currentTime); SimpleDateFormat orderId = new SimpleDateFormat("yyyyMMddHHmmss"); String orderTime = orderId.format(currentTime); String order=orderTime+String.valueOf(randInt(10000,99999)); String xml = "<Finance><Message id=\"0000\">" + "<CPReq id=\"CPReq\">" + "<version>6.0.1</version>" + "<instId>12345</instId>" + "<certId>13389743053847134210</certId>" //+ "<serialNo>"+lr.eval_string("{serialNo}")+"</serialNo>" + "<serialNo>"+order+"</serialNo>" + "<date>"+date+"</date>" + "<accountName></accountName>" + "<bankCardNo>"+lr.eval_string("{支付卡号}")+"</bankCardNo>" + "<bankCardType>C</bankCardType>" + "<bankCardAreaCode></bankCardAreaCode>" + "<certType></certType>" + "<certNo></certNo>" + "<mobilePhone></mobilePhone>" + "<charge></charge>" + "<amount>1</amount>" + "<useCode>K00</useCode>" + "<currency>156</currency>" + "<limitType></limitType>" + "<remark></remark>" + "<sellerName></sellerName>" + "<installmentCount></installmentCount>" + "<originalAmount></originalAmount>" + "<expiryDate></expiryDate>" + "<cvv2></cvv2>" + "<channelSystemId>0000</channelSystemId>" + "</CPReq>" + "</Message></Finance>"; XmlSignature xmlSignature = new XmlSignature(); String result = xmlSignature.sign(xml, "CPReq"); HttpClientHelper http = new HttpClientHelper(); String postUrl = "http://195.203.56.22/online/alipay.action"; String resultXml = null; lr.start_transaction("支付");//事务开始 if(postUrl.indexOf("https://") != -1){ resultXml = HttpsHelper.sendHTTPS(postUrl,result); }else{ resultXml = http.send(result, postUrl); } log.info("请求报文:" + result); if (xmlSignature.signVerification(resultXml)) { lr.end_transaction("支付",lr.PASS);//事务成功 log.info("验签通过"); } else { lr.end_transaction("支付",lr.FAIL);//事务成功 log.error("验签失败"); } log.info("返回报文:" + resultXml); } public int randInt(int min, int max) throws Exception{ Random rand = new Random(); int randomNum = rand.nextInt((max - min) + 1) + min; return randomNum; } } |