现在公司项目是一个SDK的测试工作,我直接调用了接口,先生成并上传加密文档(json格式)文件没写进来,然后在服务器解密后返回下载文档并存储解析在当前工程目录中,然后做对比查看接口返回的数据经过加密-解密后有没有异常。。。
import os
import time
import requests
import json
from urllib3 import encode_multipart_formdata
executable =('python Daemo.py')
def sleeptime(hour, min, sec):
return hour * 3600 + min * 60 + sec;
second = sleeptime(0, 0, 10); # 间隔时间10s
while 1 == 1: # 死循环
if time.time() > 1579688855: #默认为2020年1月22日18:27分
break
time.sleep(second);
p = os.system(executable) # 执行
else :
sys.exit()
print(p) #打印执行结果 0表示 success , 1表示 fail
data = { #入参数据生成字典与下载的解码文件数据对比
"toolUserInfo":("酒仙桥"),
"toolClient": ("BEIJING")
}
response = requests.post('http://10.xxxxxxxx0:8080/getFile')
url = 'http://10.xxxxxxxx0:8080/getFile'
files = {'file': open('C:/Users/chengpengpeng/Desktop/myProject/result.txt', 'rb')}
r = requests.post(url,files=files)
print(str(r.content,encoding='utf-8'))
with open('Decrypt.json','wb') as f:
f.write(r.content)
print('解密成功')
filename = 'Decrypt.json' #解密后文件生成为‘Decrypt.json’在同目录
with open(filename,encoding='UTF-8') as file_object : # 遍历
for line in file_object:
print(line.rstrip())
tmpLine = json.loads(line.rstrip())
if tmpLine['toolUserInfo'] == data['toolUserInfo']:
print('开始对比,使用者信息正确')
else:
print('开始对比,使用者信息失败')
if tmpLine['toolClient'] == data['toolClient']:
print('使用的客户单位正确')
else:
print('使用的客户单位失败')
print('运行结束')
来源:CSDN
作者:360成先生
链接:https://blog.csdn.net/m0_38112384/article/details/104068740