问题详情:
1、接口调用需要前提状态:登录状态(cookie)
2、接口请求需要签名,签名规则为:MD5(TokenKey+apikey+timestamp+nonc)
其中
1、TokenKey、apikey为接口构造方提供(永久不变);
2、nonc为随机数,自定义
3、timestamp 为 时间戳(百度百科)
对应解决办法:
1、登录获取cookie;
"""
import com.eviware.soapui.support.types.StringToStringMap
def cookiesList = testRunner.testCase.getTestStepByName("Login - Request 1").testRequest.response.responseHeaders["Set-Cookie"][0]
cookiesList = cookiesList[0..-29] +"IsClosePwdWeak=0"
log.info cookiesList
return cookiesList
"""
2、获取时间戳timestamp;
"""
time = (new Date().time / 1000).intValue()
log.info time
return time
"""
外部引用方法:${(Groovy Script 命名)#result} eg:${timestamp#result}
3、获取签名sign;
"""
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
"""
4、构建目标接口
原文:https://www.cnblogs.com/testwjr/p/10156461.html