jmeter 的beanshell使用

发布时间:2023年12月18日

import com.XRsaUtil;
import java.util.Date;
import java.lang.String;
import com.test;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

Date date=new Date();
long time=date.getTime();
String time1=String.valueOf(time);
vars.put("time",time1);
log.info(vars.get("time"));

//查询车辆列表
//String data="{\n" +
// ? ? ? ? ?? ??? ? " ? ? ? ? ? ?\"appId\":\"cdbflc_access_token\",\n" +
// ? ? ? ? ?? ??? ? " ? ? ? ? ? ?\"timestamp\":\"%s\",\n" +
// ? ? ? ? ?? ??? ? " ? ? ? ? ? ?\"frameNo\": \"\",\n" +
// ? ? ? ? ?? ??? ? " ? ? ? ? ? ?\"pageNum\": \"1\",\n" +
// ? ? ? ? ?? ??? ? " ? ? ? ? ? ?\"pageSize\": \"10\"\n" + ? ? ? ? ? ? ?
// ? ? ? ? ?? ??? ? " ? ?}"; ?
//String res1=test.format(data,time1);
//vars.put("res4",res1);
//log.info(vars.get("res4"));

//车辆历史列表
String data= "{\n" +
? ? ? ? ??? ??? ? " ? ? ? ? ? ?\"appId\":\"cdbflc_access_token\",\n" +
? ? ? ? ??? ??? ? " ? ? ? ? ? ?\"timestamp\":\"%s\",\n" +
? ? ? ? ??? ??? ? " ? ? ? ? ? ?\"frameNo\": \"UCCS1702494201659\",\n" +
? ? ? ? ??? ??? ? " ? ? ? ? ? ?\"startTime\": \"2023-12-12\",\n" +
? ? ? ? ??? ??? ? " ? ? ? ? ? ?\"endTime\": \"2023-12-12\",\n" +
? ? ? ? ??? ??? ? " ? ? ? ? ? ?\"pageNum\": \"1\",\n" +
? ? ? ? ??? ??? ? " ? ? ? ? ? ?\"pageSize\": \"10\"\n" + ? ? ? ? ? ? ?
? ? ? ? ??? ??? ? " ? ?}"; ?
String res1=test.format(data,time1);
vars.put("res5",res1);
log.info(vars.get("res5"));

//查询车辆附件
//String data= "{\n" +
// ? ? ? ? ?? ??? ? " ? ? ? ? ? ?\"appId\":\"cdbflc_access_token\",\n" +
// ? ? ? ? ?? ??? ? " ? ? ? ? ? ?\"timestamp\":\"%s\",\n" +
// ? ? ? ? ?? ??? ? " ? ? ? ? ? ?\"frameNo\": \"UCCS1702494201659\",\n" +
// ? ? ? ? ?? ??? ? " ? ? ? ? ? ?\"pageNum\": \"1\",\n" +
// ? ? ? ? ?? ??? ? " ? ? ? ? ? ?\"pageSize\": \"10\"\n" + ? ? ? ? ? ? ?
// ? ? ? ? ?? ??? ? " ? ?}"; ?
//String res1=test.format(data,time1);
//vars.put("res4",res1);
//log.info(vars.get("res4"));

//查询车辆智能设备
String data= "{\n" +
? ? ? ? ??? ??? ? " ? ? ? ? ? ?\"appId\":\"cdbflc_access_token\",\n" +
? ? ? ? ??? ??? ? " ? ? ? ? ? ?\"timestamp\":\"%s\",\n" +
? ? ? ? ??? ??? ? " ? ? ? ? ? ?\"frameNoList\": [\"UCCS1702494201659\"],\n" +
? ? ? ? ??? ??? ? " ? ? ? ? ? ?\"pageNum\": \"1\",\n" +
? ? ? ? ??? ??? ? " ? ? ? ? ? ?\"pageSize\": \"10\"\n" + ? ? ? ? ? ? ?
? ? ? ? ??? ??? ? " ? ?}"; ?
String res1=test.format(data,time1.toString());
JSONObject jsonobject=JSON.parseObject(res1);
String res8= JSON.toJSONString(jsonobject);
vars.put("res7",res8);
log.info(vars.get("res7"));
//查询车辆保险记录
//String data= "{\n" +
// ? ? ? ? ?? ??? ? " ? ? ? ? ? ?\"appId\":\"cdbflc_access_token\",\n" +
// ? ? ? ? ?? ??? ? " ? ? ? ? ? ?\"timestamp\":\"%s\",\n" +
// ? ? ? ? ?? ??? ? " ? ? ? ? ? ?\"frameNo\": \"UCCS1702494201659\",\n" +
// ? ? ? ? ?? ??? ? " ? ? ? ? ? ?\"pageNum\": \"1\",\n" +
// ? ? ? ? ?? ??? ? " ? ? ? ? ? ?\"pageSize\": \"10\"\n" + ? ? ? ? ? ? ?
// ? ? ? ? ?? ??? ? " ? ?}"; ?
//String res1=test.format(data,time1);
//vars.put("res4",res1);
//log.info(vars.get("res4"));

//查询订单记录
String data="{\n" +
? ? ? ? ??? ??? ? " ? ? ? ? ? ?\"appId\":\"cdbflc_access_token\",\n" +
? ? ? ? ??? ??? ? " ? ? ? ? ? ?\"timestamp\":\"%s\",\n" +
? ? ? ? ??? ??? ? " ? ? ? ? ? ?\"frameNo\": \"UCCS1702494201659\",\n" + ? ?
? ? ? ? ??? ??? ? " ? ? ? ? ? ?\"pickupStartTime\": \"\",\n" + ?
? ? ? ? ??? ??? ? " ? ? ? ? ? ?\"pickupEndTime\": \"\",\n" + ?
? ? ? ? ??? ??? ? " ? ? ? ? ? ?\"returnStartTime\": \"2023-12-12\",\n" +
? ? ? ? ??? ??? ? " ? ? ? ? ? ?\"returnEndTime\": \"2023-12-12\",\n" +
? ? ? ? ??? ??? ? " ? ? ? ? ? ?\"pageNum\": \"1\",\n" +?
? ? ? ? ??? ??? ? " ? ? ? ? ? ?\"pageSize\": \"10\"\n" + ? ? ??
? ? ? ? ??? ??? ? " ? ?}";?
String res1=test.format(data,time1);
vars.put("res6",res1);
log.info(vars.get("res6"));

//查询车辆维保记录
String data= "{\n" +
? ? ? ? ??? ??? ? " ? ? ? ? ? ?\"appId\":\"cdbflc_access_token\",\n" +
? ? ? ? ??? ??? ? " ? ? ? ? ? ?\"timestamp\":\"%s\",\n" +
? ? ? ? ??? ??? ? " ? ? ? ? ? ?\"frameNo\": \"UCCS1702494201659\",\n" +
? ? ? ? ??? ??? ? " ? ? ? ? ? ?\"pageNum\": \"1\",\n" +
? ? ? ? ??? ??? ? " ? ? ? ? ? ?\"pageSize\": \"10\"\n" + ? ? ? ? ? ? ?
? ? ? ? ??? ??? ? " ? ?}"; ?
String res1=test.format(data,time1);
vars.put("res4",res1);
log.info(vars.get("res4"));
//查询车辆出险记录
//String data= "{\n" +
// ? ? ? ? ?? ??? ? " ? ? ? ? ? ?\"appId\":\"cdbflc_access_token\",\n" +
// ? ? ? ? ?? ??? ? " ? ? ? ? ? ?\"timestamp\":\"%s\",\n" +
// ? ? ? ? ?? ??? ? " ? ? ? ? ? ?\"frameNo\": \"UCCS1702494201659\",\n" +
// ? ? ? ? ?? ??? ? " ? ? ? ? ? ?\"pageNum\": \"1\",\n" +
// ? ? ? ? ?? ??? ? " ? ? ? ? ? ?\"pageSize\": \"10\"\n" + ? ? ? ? ? ? ?
// ? ? ? ? ?? ??? ? " ? ?}"; ?
//String res1=test.format(data,time1);
//vars.put("res4",res1);
//log.info(vars.get("res4"));
log.info(res1); ? ? ? ??? ??? ??
String publicKeyValue = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAMDQTtAU5qmshMasBuuLkscEpTdgJdfDjraJJHNJm5r+J4kDp0MgxsHLC6sKIilCEwuxFpFVdz+zPndPgqs1hYsCAwEAAQ==";
String privateKeyValue ="MIIBVQIBADANBgkqhkiG9w0BAQEFAASCAT8wggE7AgEAAkEAwNBO0BTmqayExqwG64uSxwSlN2Al18OOtokkc0mbmv4niQOnQyDGwcsLqwoiKUITC7EWkVV3P7M+d0+CqzWFiwIDAQABAkEAr0jwTTSjGZ8vudlMFTh2wBzWAgiTfppWlFUK4RAKuRQ7hDcJm334h+KbjNwGn2NclffdXT9h6m4L9NWKqJxUeQIhAPqYbj3pC285fUeGqyfwSF+6EWtX2ZHZiNoTo1Ezmzc9AiEAxPjbX4BV3xSV67WeO6t9akjRTeJjexryGQ/38I8QPGcCIQCzdnKM19aegtdbX/A3G/dYxtIuw61GrDk7pBCz2HdyKQIgKmec6sF5Oy52XClcaGIx/NiyXr8XRaB2cFjUuvBBwY8CIGNlIqbaYBBmu++6hyjiWi59kQWZzRAYq6fA9wCm4STZ";
vars.put("res2",XRsaUtil.setDataPrivate(res1,privateKeyValue));
log.info(vars.get("res2"));
//XRsaUtil.getDataPublic(enCode,publicKeyValue)
String enCode=XRsaUtil.setDataPrivate(res1,privateKeyValue);
vars.put("res3",XRsaUtil.getDataPublic(enCode,publicKeyValue));
log.info(vars.get("res3"));

8个底层HTTP请求接口,可供自由构造Body信息(注意:入参无需加密)

请求方式:POST

1、查询车辆列表:
/external-data/guoyin-iot-platform-external-data-center/test/underlyingGetVehicleList
{"appId":"1d7541223b3e4b2da4dadc7349cd0c9e","pageNum":"6","pageSize":"1000","timestamp":"1702380524131","frameNo":null}

2、查询车辆历史列表:
/external-data/guoyin-iot-platform-external-data-center/test/underlyingGetVehicleHistoryList
{"appId":"1d7541223b3e4b2da4dadc7349cd0c9e","pageNum":"1","pageSize":"1000","timestamp":"1702436177780","frameNo":"UCCS1702433928159","startTime":"2023-12-12","endTime":"2023-12-12"}

3、查询车辆附件:
external-data/guoyin-iot-platform-external-data-center/test/underlyingGetVehicleFileInfo
{"appId":"1d7541223b3e4b2da4dadc7349cd0c9e","pageNum":"1","pageSize":"1000","timestamp":"1702380607111","frameNo":"UCCS1702351419564"}

4、查询车辆智能设备:
/external-data/guoyin-iot-platform-external-data-center/test/underlyingGetVehicleDeviceList
{"appId":"1d7541223b3e4b2da4dadc7349cd0c9e","pageNum":"1","pageSize":"1000","timestamp":"1702389275596","frameNos":["UCCS1702351358738"]}

5、查询车辆保险记录:
/external-data/guoyin-iot-platform-external-data-center/test/underlyingGetVehicleInsuranceList
{"appId":"1d7541223b3e4b2da4dadc7349cd0c9e","pageNum":"1","pageSize":"1000","timestamp":"1702380608179","frameNo":"LMGF1702292838589"}

6、查询车辆订单记录:
/external-data/guoyin-iot-platform-external-data-center/test/underlyingGetVehicleOrderList
{"appId":"1d7541223b3e4b2da4dadc7349cd0c9e","pageNum":"1","pageSize":"1000","timestamp":"1702435397849","frameNo":"UCCS1702433944029","pickupStartTime":null,"pickupEndTime":null,"returnStartTime":"2023-12-12","returnEndTime":"2023-12-12"}

7、查询车辆维保记录:
/external-data/guoyin-iot-platform-external-data-center/test/underlyingGetVehicleRepairList
{"appId":"1d7541223b3e4b2da4dadc7349cd0c9e","pageNum":"1","pageSize":"1000","timestamp":"1702380606542","frameNo":"UCCS1702371572103"}
?

package com;
import java.util.Date;
import java.util.Formatter;
import java.lang.String;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;


public class test {
public static String format(String jsonCode, String timeCode) {
      Formatter formatter=new Formatter();
      formatter.format(jsonCode, timeCode);
      String out=formatter.toString();
      formatter.close();
      return out;
    } 

	public static void main(String[] args) {
		// TODO Auto-generated method stub
       Date data=new Date();
       long time =data.getTime();
       String time1=String.valueOf(time);
       System.out.println(time1);
       String code="{\n" +
       		 "            \"appId\":\"cdbflc_access_token\",\n" +
       		 "            \"timestamp\":\"%s\",\n" +
       		 "            \"frameNo\": \"UCCS1702494201659\",\n" +
       		 "            \"pageNum\": \"1\",\n" +
       		 "            \"pageSize\": \"10\"\n" +              
       		 "    }";     
       String code1=test.format(code, time1.toString());
       JSONObject jsonobject=JSON.parseObject(code1);
       String code2=JSON.toJSONString(jsonobject);
       System.out.println(code2);
 	}
}


1.实现重写String.format并封装成format函数
2.结合java自有对象Data 实现时间戳生成
3.并格式化输出为json字符串
用法:
将封装的方法打包成jar包,放置到jmeter安装路径下的ext文件夹下,重启jmeter 就可以利用format方法

文章来源:https://blog.csdn.net/testManger/article/details/135020267
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。