23 lines
518 B
Python
23 lines
518 B
Python
import functools
|
|
|
|
from flask import request
|
|
|
|
# 接口密钥
|
|
API_SECRET = "EZgo9ykxrYuBMYnYmmKIh"
|
|
|
|
|
|
def api_secret(func):
|
|
"""
|
|
校验接口请求密钥
|
|
"""
|
|
@functools.wraps(func)
|
|
def internal(*args, **kwargs):
|
|
try:
|
|
token = request.headers.get('secret')
|
|
if token != API_SECRET:
|
|
return {"info": "接口密钥错误"}, 401
|
|
except Exception:
|
|
return {"info": "请求异常"}, 401
|
|
return func(*args, **kwargs)
|
|
return internal
|