1. ${__time(yyyy-MM-dd HH:mm:ss,)}
2.
import use.GetRsaContent;
String pfxPath = "pfx";
String key_password = "111111";
String content = "{"member_id":"${member_id}","terminal_id":"${terminal_id}","member_trans_date""+":"${__time(yyyyMMddHHmmss,)}${__Random(1,1000000,)}","member_trans_id":"+ "${__time(yyyyMMddHHmmss,)}${__Random(1,1000000,)}" +","account":"${account}","real_name":"${name}","password":"${pwd}","user_id":"xy_jmeter_test","id_card":"${id_card}","login_type":"pwd","origin":"3","notify_url":""}";
log.info("content = " + content);
String data_content = new GetRsaContent().getRsaContent(pfxPath, key_password, content);
vars.put("data_content", data_content);
log.info("data_content = " + data_content);
import use.GetVerifyCode;
import org.apache.jmeter.samplers.SampleResult;
String input = new GetVerifyCode().getVerifyCode("${account}", "${receive_date}");
vars.put("input", input);
int count = 1;
vars.put("count", String.valueOf(count));
FailureMessage = "input=" + input;
import use.GetVerifyCode;
import org.apache.jmeter.samplers.SampleResult;
String input = new GetVerifyCode().getVerifyCode("${account}", "${receive_date}");
vars.put("input", input);
log.info("input=="+ input);
int count = Integer.parseInt("${count}") + 1;
vars.put("count", String.valueOf(count));
FailureMessage = "input=" + input;
3.
(.+?)
$1$
1
4. if
${__javaScript( "${input}" == "")}
5. while
${__javaScript("${count}" != "${sms_count}")}
6.
import java.sql.*;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
String response = prev.getResponseDataAsString();
//log.info("response = "+response);
String tag = vars.get("tag");
//System.out.println("tag = "+tag);
String uri = vars.get("uri");
String versions = vars.get("versions");
String case_id = vars.get("num");
String jdbc_url = vars.get("jdbc_url");
String jdbc_user = vars.get("jdbc_user");
String jdbc_pass = vars.get("jdbc_pass");
String id_name = vars.get("id_name");
String id_no = vars.get("id_no");
String Describe = vars.get("Describe");
String phone_no = vars.get("phone_no");
String bankcard_no = vars.get("bankcard_no");
String product_type = vars.get("product_type");
String txn_type = vars.get("txn_type");
String number_type = vars.get("number_type");
String trans_id = "";
String trade_no = "";
String response_success = "";
String response_data = "";
JsonParser parser = new JsonParser();
JsonObject responseObj = (JsonObject) parser.parse(response);
if(responseObj.get("success").getAsString() == "true"){
JsonObject resp_data = responseObj.getAsJsonObject("data");
trans_id = resp_data.get("trans_id").getAsString();
trade_no = resp_data.get("trade_no").getAsString();
resp_data.remove("trans_id");
resp_data.remove("trade_no");
response_data = resp_data.toString();
responseObj.remove("data");
response_success = responseObj.toString();
}else {
response_success = responseObj.toString();
}
String insert = "insert into result_history (`tag`,`case_id`, `id_name`, `id_no`, `phone_no`,`bankcard_no`,`uri`, `Describe`,`versions`,`number_type`,`product_type`,`txn_type`, `trans_id`, `trade_no`, `response_success`, `response_data`) " + "values('"+ tag +"','"+ case_id +"','"+id_name +"','"+ id_no+"','"+ phone_no+"','"+ bankcard_no+"','"+uri+"', '"+ Describe +"', '"+ versions +"', '"+ number_type +"', '"+ product_type +"', '"+ txn_type +"', '"+ trans_id +"', '"+ trade_no +"', '"+ response_success +"', '"+ response_data +"');
";
// log.info("insert = "+insert);
String drive = "com.mysql.jdbc.Driver";
Connection Mycon = null;
Statement Mystmt = null;
int insertFlag = -1;
try {
Class.forName(drive);
Mycon = DriverManager.getConnection(jdbc_url, jdbc_user, jdbc_pass);
Mystmt = Mycon.createStatement();
insertFlag = Mystmt.executeUpdate(insert);
Mystmt.close();
Mycon.close();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
// log.info("insertFlag = " + insertFlag);
7.
import java.sql.*;
String uri = "";
String versions = "";
String id_name = "";
String id_no = "";
String phone_no = "";
String bankcard_no = "";
String product_type = "";
String txn_type = "";
String Describe = "";
String number_type = "";
String history = "";
String history_success = "";
String history_trans_id = "";
String history_trade_no = "";
String tag = vars.get("tag");
String case_id = vars.get("num");
String jdbc_url = vars.get("jdbc_url");
String jdbc_user = vars.get("jdbc_user");
String jdbc_pass = vars.get("jdbc_pass");
String whereTagCause = "tag = '"+ tag + "'";
String whereCaseIdCause = "case_id = '"+ case_id + "'";
String whereCause = whereTagCause + "AND " + whereCaseIdCause;
// String query = "SELECT * From result_history Where " + whereCause + " and ( response_data LIKE '%成功%' OR response_data LIKE '%确认%' OR response_data LIKE '%拉黑%' OR response_data LIKE '%洗白%');";
String query = "SELECT * From result_history Where " + whereCause + ";";
// log.info("query = "+query);
String drive = "com.mysql.jdbc.Driver";
Connection Mycon = null;
Statement Mystmt = null;
ResultSet myResultSet = null;
try {
Class.forName(drive);
Mycon = DriverManager.getConnection(jdbc_url, jdbc_user, jdbc_pass);
Mystmt = Mycon.createStatement();
myResultSet = Mystmt.executeQuery(query);
while (myResultSet.next()){
uri = myResultSet.getString("uri");
id_name = myResultSet.getString("id_name");
id_no = myResultSet.getString("id_no");
phone_no = myResultSet.getString("phone_no");
bankcard_no = myResultSet.getString("bankcard_no");
product_type = myResultSet.getString("product_type");
txn_type = myResultSet.getString("txn_type");
Describe = myResultSet.getString("Describe");
number_type = myResultSet.getString("number_type");
versions = myResultSet.getString("versions");
history = myResultSet.getString("response_data");
history_success = myResultSet.getString("response_success");
history_trans_id = myResultSet.getString("trans_id");
history_trade_no = myResultSet.getString("trade_no");
}
myResultSet.close();
Mystmt.close();
Mycon.close();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
vars.put("uri", uri);
vars.put("versions", versions);
vars.put("id_no", id_no);
vars.put("id_name", id_name);
vars.put("phone_no", phone_no);
vars.put("bankcard_no", bankcard_no);
vars.put("product_type", product_type);
vars.put("txn_type", txn_type);
vars.put("Describe", Describe);
vars.put("number_type", number_type);
vars.put("history", history);
vars.put("history_success", history_success);
vars.put("history_trans_id", history_trans_id);
vars.put("history_trade_no", history_trade_no);
FailureMessage = "tag = " + tag+ "
case_id=" + case_id + "
id_name=" + id_name +"
uri=" + uri;
8.
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.JsonArray;
import com.google.gson.JsonNull;
import java.util.Iterator;
import java.util.Set;
import java.sql.*;
public static String compareJson(JsonObject json1, JsonObject json2,String key) {
String result = "";
Set i = json1.entrySet();
Iterator it = i.iterator();
while (it.hasNext()) {
String tmp = it.next().toString();
key = tmp.substring(0, tmp.indexOf("="));
result += compareJson(json1.get(key), json2.get(key),key);
}
return result;
}
public static String compareJson(Object json1,Object json2,String key) {
String result = "";
if ( json1 instanceof JsonObject ) {
result += compareJson((JsonObject) json1 ,(JsonObject) json2, key);
}else if ( (json1 instanceof JsonNull) && (json1 instanceof JsonArray)) {
result += compareJson((JsonArray) json1 ,(JsonArray) json2,key);
}else if(json1 instanceof String ){
result += compareJson((String) json1 ,(String) json2,key);
}else {
result += compareJson(json1.toString(), json2.toString(), key);
}
return result;
}
public static String compareJson(JsonArray json1, JsonArray json2, String key) {
String result = "";
Iterator i1= json1.iterator();
Iterator i2= json2.iterator();
while ( i1.hasNext()) {
result += compareJson(i1.next(), i2.next(),key);
}
return result;
}
public static String compareJson(String str1,String str2,String key) {
String result = "";
if (!str1.equals(str2)) {
str1= str1.replace("^","]");
str2= str2.replace("^","]");
result = key + " 不一致
当前测试返 " + str1 + "
历史数据返 " + str2 + "
";
}
return result;
}
String response = prev.getResponseDataAsString();
String history = vars.get("history");
String history_success = vars.get("history_success");
String history_trans_id = vars.get("history_trans_id");
String history_trade_no = vars.get("history_trade_no");
String failure_msg = "";
String tag = vars.get("tag");
String uri = vars.get("uri");
String versions = vars.get("versions");
String case_id = vars.get("num");
String id_name = vars.get("id_name");
String id_no = vars.get("id_no");
String jdbc_url = vars.get("jdbc_url");
String jdbc_user = vars.get("jdbc_user");
String jdbc_pass = vars.get("jdbc_pass");
String data_content_src = vars.get("data_content_src");
String trans_id = "";
String trade_no = "";
String response_success = "";
String response_data = "";
String all_history_resp = "";
String exception_msg = "";
try{
response = response.replace("\","");
response = response.replace(""{","{");
response = response.replace("}"","}");
response = response.replace(""[","[");
response = response.replace("]",","^",");
response = response.replace("]"}","^"}");
response = response.replace("]"","]");
JsonParser parser = new JsonParser();
JsonObject responseObj = (JsonObject) parser.parse(response);
JsonParser parser1 = new JsonParser();
JsonObject history_successObj = (JsonObject) parser1.parse(history_success);
JsonObject historyObj = null;
JsonObject resp_data = null;
if(history != "") {
history = history.replace("\","");
history = history.replace(""{","{");
history = history.replace("}"","}");
history = history.replace(""[","[");
history = history.replace("]",","^",");
history = history.replace("]"}","^"}");
history = history.replace("]"","]");
JsonParser parser2 = new JsonParser();
historyObj = (JsonObject) parser2.parse(history);
}
if(responseObj.get("success").getAsString() == "true"){
resp_data = responseObj.getAsJsonObject("data");
trans_id = resp_data.get("trans_id").getAsString();
trade_no = resp_data.get("trade_no").getAsString();
resp_data.remove("trans_id");
resp_data.remove("trade_no");
response_data = resp_data.toString();
responseObj.remove("data");
response_success = responseObj.toString();
}else {
response_success = responseObj.toString();
}
if(resp_data != null && historyObj != null){
if(resp_data.equals(historyObj) == false){
failure_msg = compareJson(resp_data, historyObj, null);
}
historyObj.addProperty("trans_id", history_trans_id);
historyObj.addProperty("trade_no", history_trade_no);
history_successObj.add("data", historyObj);
}else{
if(responseObj.equals(history_successObj) == false){
responseObj.remove("data");
failure_msg = compareJson(responseObj, history_successObj, null);
}
}
if(failure_msg != "" && failure_msg.length() != 0){
Failure = true;
all_history_resp = history_successObj.toString();
all_history_resp = all_history_resp.replace("^","]");
response = response.replace("^","]");
FailureMessage = "
请求明文:
" + data_content_src + "
返回数据和历史数据不匹配, 具体字段如下:
" + failure_msg + "
当前报文:
" + response + "
历史报文:
" + all_history_resp + "
" + uri + "
" + id_name + "_" + id_no;
String update = "UPDATE result_history SET current_trans_id = '"+ trans_id + "', current_trade_no = '"+ trade_no + "', current_response_success = '"+ response_success + "', current_response_data = '"+ response_data + "', FailureMessage = '"+failure_msg + "', UpdatedAt = NOW() WHERE tag = '"+ tag + "' AND case_id = '"+ case_id + "'; ";
String drive = "com.mysql.jdbc.Driver";
Connection Mycon = null;
Statement Mystmt = null;
int updateFlag = -1;
try {
Class.forName(drive);
Mycon = DriverManager.getConnection(jdbc_url, jdbc_user, jdbc_pass);
Mystmt = Mycon.createStatement();
updateFlag = Mystmt.executeUpdate(update);
Mystmt.close();
Mycon.close();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
// log.info("updateFlag = " + updateFlag);
}
}catch (Exception e){
exception_msg = e.getMessage();
// log.info("exception_msg = " + exception_msg);
}
if(exception_msg != ""){
Failure = true;
all_history_resp = history;
all_history_resp = all_history_resp.replace("^","]");
response = response.replace("^","]");
FailureMessage = "
请求明文:
" + data_content_src + "
解析返回字段出错, 错误信息如下:
" + exception_msg + "
当前报文:
" + response + "
历史报文:
" + all_history_resp + "
" + uri + "
" + id_name + "_" + id_no;
}
9.
import org.apache.jmeter.samplers.SampleResult;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
SampleResult result = ctx.getPreviousResult();
String requestHeaders = result.getRequestHeaders();
Long time = result.getTime();
log.info("time: "+ time);
log.info("RequestHeaders: "+requestHeaders);
String card= "dddd";
try{
File file = new File("D:\yace\card.txt");
if (!file.exists()){
file.createNewFile();
}
BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(new FileInputStream(file.getAbsolutePath()), "UTF-8"));
String str="";
boolean isExist=false;
while ((str=bufferedReader.readLine())!=null){
if (str.trim().equals(card)){
isExist=true;
break;
}
}
bufferedReader.close();
if (isExist){
FileOutputStream fos = new FileOutputStream(file.getAbsoluteFile(),true);
fos.write(card.getBytes());
fos.write("
".getBytes());
fos.close();
}
}catch(IOException e){
e.printStackTrace();
}
10
String requestHeaders= "trans_id: 20181214094348040610532 " +
"Content-Type: application/x-www-form-urlencoded " +
"Content-Length: 840 " +
"Host: api.xinyan-ai.com " +
"User-Agent: Apache-HttpClient/4.5.3 (Java/1.8.0_181)";
String[] array = requestHeaders.split(" ");
String trans_id = "";
for (int i = 0; i < array.length; i++) {
if(array[i].contains("trans_id")){
trans_id = array[i].substring(10);
break;
}
}
try{
File file = new File("D:\yace\card.txt");
if (!file.exists()){
file.createNewFile();
}
FileOutputStream fos = new FileOutputStream(file.getAbsoluteFile(),true);//true表示在文件末尾追加
fos.write(trans_id.getBytes());
fos.write(" ".getBytes());
fos.close();
}catch(IOException e){
e.printStackTrace();
}
}
11
import org.apache.jmeter.samplers.SampleResult;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
SampleResult result = ctx.getPreviousResult();
String requestHeaders = result.getRequestHeaders();
Long time = result.getTime();
String trans_id = vars.get("trans_id");
String saveFile = vars.get("saveFile");
String timeout = vars.get("timeout");
if(time > Long.parseLong(timeout)){
try{
File file = new File(saveFile);
if (!file.exists()){
file.createNewFile();
}
FileOutputStream fos = new FileOutputStream(file.getAbsoluteFile(),true);
fos.write((time.toString()+",").getBytes());
fos.write(trans_id.getBytes());
fos.write("
".getBytes());
fos.close();
}catch(IOException e){
e.printStackTrace();
}
}