错误参数兼容

main
RogerWork 4 months ago
parent 2df3558c16
commit 8ff2692848
  1. 18
      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,

Loading…
Cancel
Save