From 1c57799bbae519c901f25c69f4d8d6717b7eb92e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=80=9D=E5=B7=9D?= Date: Wed, 8 Dec 2021 16:17:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8E=A5=E5=8F=A3=E5=AF=86?= =?UTF-8?q?=E9=92=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common.py | 22 +++++++++++++++++++--- setting.py | 4 ++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/common.py b/common.py index f2fbdec..285c77c 100644 --- a/common.py +++ b/common.py @@ -4,11 +4,10 @@ import functools import json import requests +from flask import request from conserve_methods import conserve_data - -token = "32737167-cb63-4ce9-9397-d66169488f51" -headers = {'Authorization': token} +from setting import API_SECRET def check_status_code(func): @@ -74,6 +73,7 @@ def general_request(url, company, db, col): Returns: '保存成功' """ + headers = {'Authorization': "32737167-cb63-4ce9-9397-d66169488f51"} # 根据传入url进行请求 res = json.loads(requests.get(url, headers=headers).text) # 判断请求返回结果中的error_code @@ -92,3 +92,19 @@ def general_request(url, company, db, col): return '保存成功' else: return status + + +def verify_token(func): + """ + 校验token + """ + @functools.wraps(func) + def internal(*args, **kwargs): + try: + token = request.headers.get('token') + if token != API_SECRET: + return {"info": "接口密钥错误"}, 401 + except Exception: + return {"info": "请求异常"}, 401 + return func(*args, **kwargs) + return internal diff --git a/setting.py b/setting.py index 9ebaac2..80e0b4e 100644 --- a/setting.py +++ b/setting.py @@ -15,3 +15,7 @@ DB_TYFX = '天眼风险' DB_JYZK = '经营状况' DB_ZSCQ = '知识产权' DB_GSFZ = '公司发展' + + +# API接口密钥 +API_SECRET = "uzdq51N4!I0%HY4sCaQ!aeCSIDIVIdAM"