tfse-app-api-v0.2/TestForAdmin/APIAuth.py

22 lines
515 B
Python
Raw Normal View History

2022-04-25 13:46:19 +08:00
import functools
from flask import request
def api_secret(func):
"""
校验接口请求密钥
"""
secret = "EZgo9ykxrYuBMYnYmmKIh" # 接口密钥
@functools.wraps(func)
def internal(*args, **kwargs):
try:
token = request.headers.get('secret')
if token != secret:
return {"info": "接口密钥错误"}, 401
except Exception:
return {"info": "请求异常"}, 401
return func(*args, **kwargs)
return internal