diff --git a/dspt_api/views.py b/dspt_api/views.py index 320cbf1..261a754 100644 --- a/dspt_api/views.py +++ b/dspt_api/views.py @@ -195,6 +195,16 @@ def send_request(request): response = requests.Session().send(req) print('response', response.content) + # 处理xml数据 + handled_data = '' + response_data = '' + if resp_format == 'json': + response_data = response.text + handled_data = json.loads(response.text) + if resp_format == 'xml': + response_data = format_xml(re.sub(r'>\n?\s+?<', r'>\n<', response.text)) + handled_data = HandleXmlResp(response.text).format_xml() + # 记录Redis if redis_conn.exists(redis_key_api): redis_conn.delete(redis_key_api) @@ -203,7 +213,8 @@ def send_request(request): 'member_type': member_type, 'format': resp_format, 'params': params, - 'response_data': response.text + 'response_data': response.text, + 'handled_data': handled_data, } print(data) redis_conn.set(redis_key_api, json.dumps(data), 10 * 60 * 60) @@ -218,17 +229,8 @@ def send_request(request): } print(db_data) EcRequestLog.objects.create(**db_data) - # 处理xml数据 - handled_data = '' - _data = '' - if resp_format == 'json': - _data = response.text - handled_data = json.loads(response.text) - if resp_format == 'xml': - _data = format_xml(re.sub(r'>\n?\s+?<', r'>\n<', response.text)) - print('---format_xml-----', _data) - handled_data = HandleXmlResp(response.text).format_xml() - return JsonResponse({'format': resp_format, 'data': _data, 'handled': json.dumps(handled_data)}) + + return JsonResponse({'format': resp_format, 'data': response_data, 'handled': json.dumps(handled_data)}) # 对外接口,用于收集用户选择的数据,例如场次,卖品等,以便后续接口直接调用