import org.apache.commons.codec.digest.DigestUtils; import java.io.*; import org.apache.jmeter.config.Arguments; Arguments args = sampler.getArguments(); String str1 = vars.get("body"); //String bodyStr = str1.substring(1, str1.length()).replace("(","").replace(")",""); String timestamptmp = String.valueOf(Long.valueOf("${__time(,)}")); String query_str = "body=" + str1 + "×tamp=" + timestamptmp + "&uid=" + "${mobile}" ; //&req_id=123 String sig = DigestUtils.sha256Hex(query_str).toUpperCase(); vars.put("timestamp",timestamptmp); vars.put("sig",sig); vars.put("query_str",query_str); log.info("AAAAA"+ctx.getCurrentSampler()); //log.info("KKKKKKKKKK"+query_str); //log.info("PPPPP"+bodyStr);
计算签名
import org.apache.commons.codec.digest.DigestUtils; import org.apache.jmeter.config.Arguments; Arguments args = sampler.getArguments(); String str1 = vars.get("codebody"); String timestamptmp = String.valueOf(Long.valueOf("${__time(,)}")); String query_str = "body=" + str1 + "×tamp=" + timestamptmp +"&token=" +"${Token}" + "&uid=" + "${mobile}" ; //&req_id=123 String sig = DigestUtils.sha256Hex(query_str).toUpperCase(); vars.put("timestamp",timestamptmp); vars.put("sig",sig); log.info("测试操作请求地址为"+ctx.getCurrentSampler()); log.info(query_str);
正则提取 : .*(d{6}).*