1.环境准备
1.1本地安装的python3.9无法使用,只能安装python2.7,如何在二者之间自由切换使用,请参考https://www.cnblogs.com/zhongguiyao/p/9737304.html
1.2下载Jython Standalone,下载地址:https://search.maven.org/artifact/org.python/jython-standalone/2.7.2/jar。下载之后将jar包放在jmeter的\lib\ext下,重启jmeter.
2.线程组->添加->取样器->JSR223 Sampler,选择语言,通过python实现MD5加密(时间+自定义字符串)
import time
import hashlib
api_key = "&Guest-Bugmaster"
now_time = time.time()
print(now_time)
client_time = str(now_time).split('.')[0]
print(client_time)
md5 = hashlib.md5()
sign_str = client_time + api_key
sign_bytes_utf8 = sign_str.encode(encoding='utf-8')
md5.update(sign_bytes_utf8)
sign_md5 = md5.hexdigest()
vars.put("client_time",client_time)
vars.put("sign_md5",sign_md5)
3.线程组->添加->取样器->http请求,将python生成的client_time,sign_md5,放在请求里,查看结果树
参考:http://t.zoukankan.com/mengyu-p-13323957.html