Jmeter前置脚本
1. 实现功能
-
计算接口sign签名,添加sign参数到请求中
import org.apache.commons.codec.digest.DigestUtils; import java.util.Date; import org.apache.jmeter.config.*; Arguments args = sampler.getArguments(); // 截获请求,包含url、headers 和 body 三部分 Argument arg_body = args.getArgument(0); // 获取请求body String body = arg_body.getValue(); // 获取body的值保存成字符串 log.info(body); String[] arr = body.split("&"); TreeMap params = new TreeMap(); for(String s: arr){ log.info(s); itemArr = s.split("="); params.put(itemArr[0], itemArr[1]); } secretKey = vars.get("key_secret"); params.put("app_key", vars.get("app_key")); params.put("company_id", vars.get("company_id")); params.put("language", vars.get("language")); StringBuffer orgin = new StringBuffer(secretKey); for(String key : params.keySet()){ //todo } log.info(orgin.toString()); String sign = DigestUtils.md5Hex(orgin.toString()); log.info(sign); sampler.addArgument("sign", sign); /* Map reqMap = args.getArgumentsAsMap(); for (String key : reqMap.keySet()) { log.info("key: " + key + " , and value: " + reqMap.get(key)); } */ //Arguments args = sampler.getArguments(); //vars.put("sigin", "123456789") //sampler.getDataType()
版权声明:本文为lsh127k原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。