import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Collections;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.jmeter.config.Arguments;
//url解码
public static String URLDecoderString(String str) {
String result = "";
if (null == str) {
return "";
}
try {
result = java.net.URLDecoder.decode(str, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return result;
}
//获取发送的data
Arguments args = sampler.getArguments();
String req_str = args.toString().replace("(","").replace(")","");
log.info("请求参数为:"+req_str);
static long timestamp = System.currentTimeMillis();
if (!(req_str.isEmpty())) {
req_str = req_str+"×tamp="+timestamp;
}else {
req_str = "timestamp="+timestamp;
}
String postDataTimeStamp = req_str;
String[] poStrings = postDataTimeStamp.split("&");
String md5BeforeString = "";
ArrayList arrayList = new ArrayList();
for (int i = 0; i < poStrings.length; i++) {
if (!poStrings[i].endsWith("=")) {
arrayList.add(poStrings[i]);
}
}
Collections.sort(arrayList);
System.out.println(arrayList);
for (int j = 0; j < arrayList.size(); j++) {
if (j == arrayList.size()-1) {
md5BeforeString = md5BeforeString + arrayList.get(j);
}else {
md5BeforeString = md5BeforeString + arrayList.get(j)+"&";
}
}
System.out.println(URLDecoderString(md5BeforeString));
log.info(URLDecoderString(md5BeforeString));
String md5String = DigestUtils.md5Hex(URLDecoderString(md5BeforeString));
log.info(md5String.toUpperCase());
vars.put("md5String",md5String.toUpperCase());
String timestampNew = String.valueOf(timestamp);
vars.put("timestamp",timestampNew);