Loadrunner的java脚本

发表于:2015-10-28 10:39

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:W&L    来源:51Testing软件测试网采编

/*
* 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;
}
}
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号