需要先切换到jmeter 的bin 目录下执行
./jmeter -n -t /Users/guoyuhuan/Desktop/withdraw_test_multiuser.jmx \
-l /Users/guoyuhuan/Desktop/jmeterlog/logs/withdraw_results.jtl \
-e -o /Users/guoyuhuan/Desktop/jmeterlog/logs/html_report
验签脚本
import javax.crypto.Mac
import javax.crypto.spec.SecretKeySpec
import java.net.URLEncoder
import java.net.URLDecoder
import org.apache.commons.codec.binary.Base64
import org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy
import org.apache.jmeter.protocol.http.control.Header
import org.apache.jmeter.protocol.http.control.HeaderManager
import org.apache.jmeter.protocol.http.util.HTTPArgument
class ParamUtils {
List<String> values = []
long timestamp
ParamUtils(long timestamp) { this.timestamp = timestamp }
void put(String k, String v) {
if (!k) return
String value = URLEncoder.encode(v, "UTF-8")
values.add(k + "=" + value)
}
List<String> sortedValues() {
Collections.sort(values)
return values
}
String getParams(String requestMethod, String requestBody, String queryString) {
if ("GET".equals(requestMethod)) {
put("signTimestamp", String.valueOf(timestamp))
} else if (["POST", "PUT", "DELETE"].contains(requestMethod)) {
if (requestBody) values.add("requestBody=" + requestBody)
put("signTimestamp", String.valueOf(timestamp))
}
return values.join("&")
}
}
if (sampler instanceof HTTPSamplerProxy) {
HTTPSamplerProxy currentSampler = sampler
def url = currentSampler.getUrl().toString()
def all_url_Path = new URL(url)
def urlPath = all_url_Path.getPath()
def apiKey = vars.get("apiKey")
def secretKey = vars.get("secretKey")
def requestMethod = currentSampler.getMethod()
long timestamp = System.currentTimeMillis()
String actualRequestBody = currentSampler.getArguments().getArgument(0).getValue()
def paramUtils = new ParamUtils(timestamp)
def paramValue = paramUtils.getParams(requestMethod, actualRequestBody, all_url_Path.getQuery())
def payload = requestMethod.toUpperCase() + "\n" + urlPath + "\n" + paramValue
Mac sha256_HMAC = Mac.getInstance("HmacSHA256")
SecretKeySpec secret_key = new SecretKeySpec(secretKey.getBytes("UTF-8"), "HmacSHA256")
sha256_HMAC.init(secret_key)
String signature = Base64.encodeBase64String(sha256_HMAC.doFinal(payload.getBytes("UTF-8")))
vars.put("signature", signature)
if (!sampler.getHeaderManager()) sampler.setHeaderManager(new HeaderManager())
sampler.getHeaderManager().clear()
sampler.getHeaderManager().add(new Header("signature", signature))
sampler.getHeaderManager().add(new Header("signTimestamp", String.valueOf(timestamp)))
sampler.getHeaderManager().add(new Header("Content-Type", "application/json"))
sampler.getHeaderManager().add(new Header("key", apiKey))
}

image.png
生成的报告可以在页面展开看看

image.png

image.png
先创建一个测试计划

image.png
创建线程组

image.png
创建csv的配置

image.png
创建http请求

image.png
http请求下创建jsr223的前置

image.png
查看结果树

image.png