jmeter调用自己打的jar包
2021-05-29 23:05
标签:val encoding public ext unit digest 代码 png get 通过md5加密签名得到 sign 值,前台接口信息头需要此参数 pom文件 工具类代码 把jar包放到\apache-jmeter-5.2.1\lib\ext 里面,重启jmeter jmeter调用自己打的jar包 标签:val encoding public ext unit digest 代码 png get 原文地址:https://www.cnblogs.com/hujinhua/p/14759826.html1 打包jar包
1.1 创建 javaweb maven 项目
新建一个java文件夹
package com.util;
import org.apache.shiro.crypto.hash.Md5Hash;
import java.util.*;
public class JmeterSignUtilHjh {
public static void main(String[] args) {
Map signMap = new HashMap();
signMap.put("parameter1" , "str1");
signMap.put("parameter2" , "str2");
System.out.println("str:" + JmeterSignUtilHjh.getSignStr(signMap,"str3"));
}
public static String getSignStr(Map paramValues , String secret) {
try {
StringBuilder sb = new StringBuilder();
List paramNames = new ArrayList();
paramNames.addAll(paramValues.keySet());
Collections.sort(paramNames);
for (String paramName : paramNames) {
sb.append(paramName).append(paramValues.get(paramName));
}
sb.append(secret);
return MD5Digest(sb.toString());
} catch (Exception e) {
throw new RuntimeException("加密签名计算异常!" , e);
}
}
/**
* md5工具类
*/
private static String MD5Digest(String src){
return new Md5Hash(src).toString();
}
}
1.2 打包写好的代码
2 jmeter 引入jar包
import com.util.JmeterSignUtilHjh;
Map signMap = new HashMap ();
comp = vars.get("compname");
limit = vars.get("limit");
es=vars.get("es");
signMap.put("companyName" , comp);
signMap.put("limit" , limit);
signMap.put("useES" , es);
//sign=SignUtils.getSignStr(signMap,null);
sign=JmeterSignUtilHjh.getSignStr(signMap,"fe716cbb-a990-40d4-b7c7-7b9db338c6c8");
vars.put("sign",sign);
System.out.println("companyName:" + comp);
System.out.println("limit:" + limit);
System.out.println("es:" + es);
System.out.println("sign:" + sign);
上一篇:Java实现CURL,与把字符串结果写到json文件
下一篇:python机制详解