You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
927 B

import json
from lib.xml_to_dict import xml_to_dict
from lib.gzip_base64 import ungzip_base64_dh2cmc
from lib.redis_util import redis_set_key
from lib.db import Result
def req(name, req_data, result_xml, case_id=None):
print('-' * 100 + '\n' + f'请求{name}接口')
print('请求参数', json.dumps(req_data))
# 处理返回数据格式
if 'xml' not in result_xml:
print(f"-- gzip加密结果 --\n{result_xml}")
result_xml = ungzip_base64_dh2cmc(result_xml)
result_dict = xml_to_dict(result_xml)
result_json = json.dumps(result_dict, ensure_ascii=False)
print("-- Json结果 --\n", result_json)
# 返回结果写缓存
redis_set_key(f'xml_{name}', json.dumps(result_dict))
# 记录测试结果
result = Result()
result.save((name, 'test', case_id, json.dumps(req_data), result_xml, result_json, None, None, None, None, None, None))
return result_json