关闭

性能测试分享—LoadRunner篇

发表于:2014-1-02 11:55

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

 作者:weiweicao0429    来源:51Testing软件测试网采编

  最后附上我写的信用卡支付的脚本:
/*
* LoadRunner Java script. (Build: _build_number_)
*
* Script Description:
*
*/
import lrapi.lr;
import http.HttpClient4;
import http.HttpParameter;
import http.HttpResp;
import http.JsonUtil;
import http.Testcredit;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.PostMethod;
import java.util.Random;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import com.yeepay.g3.utils.common.encrypt.AES;
import com.yibao.utils.des3.RSA_Encrypt;
public class Actions
{
public  String aes;
Date d = new Date();
Testcredit tc = new Testcredit();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
HttpParameter parameter = new HttpParameter();
public int init() throws Throwable {
String url = "http://xxxxx/xxxxx/consult";
HttpClient4 client =HttpClient4.createDefault();
String data = "";
Calendar now = Calendar.getInstance();
now.setTime(d);
String dateline=format.format(now.getTime());
System.out.println(dateline);
Date date = format.parse(dateline);
String dates=date.getTime()/1000+"";
System.out.println(dates);
try {
data = AES.encryptToBase64(dates, "<aes>");
} catch (Exception e) {
e.printStackTrace();
}
parameter.add("data", data);
parameter.add("merchantaccount", "<merchant>");
HttpResp resp = new HttpResp();
try{
resp=client.doPost(url, parameter, "utf-8");
String respStr= resp.getText("utf-8");
System.out.println(respStr);
aes=AES.decryptFromBase64(respStr, "<aes>");
System.out.println("aes="+aes);
} catch (Exception e) {
e.printStackTrace();
}
client.shutdown();
return 0;
}//end of init
public int action() throws Throwable {
StringBuilder sb = new StringBuilder("");
Random rd = new Random();
for(int i=1;i<=6;i++){
int sr=rd.nextInt(9);
sb.append(String.valueOf(sr));
}
String key=sb.toString();
int rds=rd.nextInt(999999);
lr.start_transaction("pay");
lr.rendezvous("pay");
HttpClient client = new HttpClient();
PostMethod method = new PostMethod("http://xxxxxxxx/xxxxxxx/api/bankcard/credit/pay");
System.out.println(aes);
String PUBLIC_KEY=aes;
System.out.println("PUBLIC_KEY"+PUBLIC_KEY);
String encryptkey = "0123456789"+key;
String merchantAccount = "<merchant>";
//民生
String cardNo = "6XXXXXXXXXXXXXX";
String validthru = "XXXX";
String cvv2 = "XXX";
String phone = "13466745431";
String orderId = rds+"334234223"+key;
System.out.println(orderId);
Integer transtime = (int)(System.currentTimeMillis()/1000);
Integer currency = 156;
String  amount = "50";
String productcatalog = "1";
String productName = "123";
String productDesc = "小丸子";
String userIp = "123.45.45.45";
String identityId = "a";
Integer identityType = 6;
String other = "eeee";
String data = "{\"merchantaccount\":\"" + merchantAccount
+"\",\"cardno\":\"" + cardNo
+ "\",\"validthru\":\"" + validthru
+ "\",\"cvv2\":\"" + cvv2
+ "\",\"phone\":\"" + phone
+ "\",\"orderid\":\"" + orderId
+ "\",\"transtime\":" + transtime
+ ",\"currency\":" + currency
+ ",\"amount\":" + amount
+ ",\"productcatalog\":\"" + productcatalog
+ "\",\"productname\":\"" + productName
+ "\",\"productdesc\":\"" + productDesc
+ "\",\"userip\":\"" + userIp
+ "\",\"identityid\":\"" + identityId
+ "\",\"identitytype\":" + identityType
+ ",\"other\":\"" + other + "\"}";
data = AES.encryptToBase64(data, encryptkey);
try {
method.setParameter("merchantaccount", merchantAccount);
method.setParameter("data", data);
method.setParameter("encryptkey", RSA_Encrypt.encrypt(encryptkey, PUBLIC_KEY));
client.executeMethod(method);
System.out.println(method.getStatusLine());
String respStr = method.getResponseBodyAsString();
System.out.println(respStr);
String result = AES.decryptFromBase64(respStr, encryptkey);
System.out.println(result);
method.releaseConnection();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();}
lr.end_transaction("pay", lr.AUTO);
return 0;
}//end of action
public int end() throws Throwable {
return 0;
}//end of end
}
相关文章:
性能测试分享—JMeter篇
33/3<123
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

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

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

沪ICP备05003035号

沪公网安备 31010102002173号