jmeter 的beanshell使用

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"}

java 复制代码
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方法
相关推荐
运维&陈同学7 分钟前
【第三章】Python基础之列表list与随机数
linux·运维·python·云计算·运维开发·devops
TPCloud12 分钟前
快速利用c语言实现线性表(lineList)
c语言·开发语言·线性表·linelist
如意.75917 分钟前
【C++】—— map 与 set 深入浅出:设计原理与应用对比
开发语言·c++
容器( ु⁎ᴗ_ᴗ⁎)ु.。oO1 小时前
java中的定时器
java·开发语言
m0_547486661 小时前
一道C语言关于距离的期末题及答案
c语言·开发语言
蹊黎1 小时前
C++模版初阶
开发语言·c++
山川尔尔_1 小时前
JS手写-this绑定实现
开发语言·javascript·ecmascript
不去幼儿园1 小时前
【SSL-RL】自监督强化学习: 好奇心驱动探索 (CDE)算法
大数据·人工智能·python·算法·机器学习·强化学习
YYDS3141 小时前
C++各类函数评点+详解
开发语言·数据结构·c++·算法·贪心算法·动态规划
薯条不要番茄酱2 小时前
数据结构-5.二叉树
java·开发语言·数据结构