签名关键点为MD5加密,先构建加密方式;test steps 中添加 Groovy Script ,其内容如下:
"""
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException
public static String md5Password(String password) {
try {
MessageDigest digest = MessageDigest.getInstance("md5");
byte[] result = digest.digest(password.getBytes());
StringBuffer buffer = new StringBuffer();
for (byte b : result) {
int number = b & 0xff;
String str = Integer.toHexString(number);
if (str.length() == 1) {
buffer.append("0");
}
buffer.append(str);
}
return buffer.toString();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
return "";
}
}
def apiKey = context.expand( ‘${Properties#apiKey}‘ )
def tokenKey = context.expand( ‘${Properties#TokenKey}‘ )
def nonc = context.expand( ‘${Properties#nonc}‘ )
def timestamp = context.expand( ‘${time#result}‘ )
md5_data= md5Password(tokenKey+apiKey+timestamp+nonc) //按照开发人员提供的签名组成规则,组成签名
log.info md5_data
return md5_data
"""