From 8ff2692848a2e1e2091782f394b6b9720ba7cdfa Mon Sep 17 00:00:00 2001 From: RogerWork Date: Mon, 29 Jul 2024 15:40:57 +0800 Subject: [PATCH] =?UTF-8?q?=E9=94=99=E8=AF=AF=E5=8F=82=E6=95=B0=E5=85=BC?= =?UTF-8?q?=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dspt_api/views.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/dspt_api/views.py b/dspt_api/views.py index 48b7d65..dcb3c4c 100644 --- a/dspt_api/views.py +++ b/dspt_api/views.py @@ -75,9 +75,15 @@ def handle_request(_request): member_type = req.get('member_type') api = req.get('api') params = json.loads(req.get('params')) - base_url = EcEnv.objects.filter(Q(code=env) & Q(type=member_type)).values('host').first()['host'] + try: + base_url = EcEnv.objects.filter(Q(code=env) & Q(type=member_type)).values('host').first()['host'] + except Exception as e: + return False, e pid = params.get('pid') - key = EcChannel.objects.filter(Q(pid=pid) & Q(env=env)).values('channel_key').first()['channel_key'] + try: + key = EcChannel.objects.filter(Q(pid=pid) & Q(env=env)).values('channel_key').first()['channel_key'] + except Exception as e: + return False, e sign = Sign(key) req_params = sign.add_sig(params) req_obj = prepare_request(base_url, api, req_params) @@ -128,6 +134,8 @@ def general_api_url(request): params 请求参数 """ req_obj, sig = handle_request(request) + if req_obj is False: + return JsonResponse({'url': '请检查foramt、pid参数', 'sig': ''}) return JsonResponse({'url': req_obj.url, 'sig': sig}) @@ -147,9 +155,11 @@ def send_request(request): web_req = json.loads(request.body) api = web_req.get('api') redis_key_api = f'dspt_api_{user_ip}_{api}' - redis_key_user_data = f'dspt_api_{user_ip}_{api}_data' + # redis_key_user_data = f'dspt_api_{user_ip}_{api}_data' # 发送请求 req, sig = handle_request(request) + if req is False: + return JsonResponse({'url': '请检查foramt、pid参数', 'sig': ''}) response = requests.Session().send(req) print('response', response) # 记录Redis @@ -162,7 +172,7 @@ def send_request(request): } print(data) redis_conn.set(redis_key_api, json.dumps(data), 10 * 60 * 60) - redis_conn.delete(redis_key_user_data) + # redis_conn.delete(redis_key_user_data) # 插入数据 db_data = { 'ip': user_ip,