【测试环境】
hashlib 内置库
requsts 2.25.1 # pip install requests
python 3.9.5
【代码实现】
import requests
import hashlib
import jsonpath
class ActionInterfaceTest(object):
def __init__(self):
self.chdAccount1 = 'apitest'
self.session = requests.session()
self.host = 'http://host:port/AccMgrt.aspx'
# 创建子账户
def create_chdaccount(self,min_num,max_num):
for time in range(min_num,max_num):
chdAccount = self.chdAccount1+str(time) #
paramString = 'AccountID=xntest01&Action=ReqCreateAccount&BrokderID=0000&ChdAccountID=%s&ChdPassword=123456&MonitorID=jk337&UserId=superadmin&'
'UserKey=d89e615214cc4550b10e897dfd8d8912'%chdAccount
md5 = hashlib.md5()
md5.update(paramString.encode('utf-8'))
result = md5.hexdigest()
url_params= {
'Action': 'ReqCreateAccount',
'UserId' : 'superadmin',
'AccountID': 'xntest01',
'BrokderID':'0000',
'MonitorID': 'jk337',
'ChdAccountID': chdAccount,
'ChdPassword': '123456',
'Sign' : result
}
response = self.session.get(url=self.host,params=url_params)
print(response.json())
self.session.close()