![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/8cc18b76c2149ba4ea6084de3abd770b.jpeg#pic_center)
封装token
from flask import *
from jwt import ExpiredSignatureError
import jwt, time
class JwtTool():
def jwt_token(self, payload):
payload['exp'] = int(time.time()) + 3600
key = current_app.config.get('SECRET_KEY')
token = jwt.encode(payload, key, algorithm='HS256')
return token
def jwt_long_token(self, payload):
payload['exp'] = int(time.time()) + 3600 * 24 * 15
key = current_app.config.get('SECRET_KEY')
token = jwt.encode(payload, key, algorithm='HS256')
return token
def jwt_payload(self, token):
key = current_app.config.get('SECRET_KEY')
try:
payload = jwt.decode(token, key, algorithms='HS256')
return payload
except ExpiredSignatureError as e:
print(e)
return 1
except Exception as e:
print(e, type(e))
return False
封装容联云和Redis
from ronglian_sms_sdk import SmsSDK
import json, redis
class RongTool():
def __init__(self):
self.rds = redis.Redis("127.0.0.1", "6379")
def sms_code(self, mobile, sms_code):
accId = "填自己的"
accToken = "填自己的"
appId = "填自己的"
sdk = SmsSDK(accId, accToken, appId)
datas = (sms_code, 5)
ser = sdk.sendMessage("1", mobile, datas)
data = json.loads(ser)
self.rds.set(str(mobile), sms_code, ex=3600 * 5)
if data['statusCode'] == '000000':
return True
return False
封装七牛云
from qiniu import Auth, put_file
class QiniuTool():
def upload(self, staticpath, staticname):
ak = "填自己的"
sk = "填自己的"
q = Auth(ak, sk)
token = q.upload_token("p7img", staticname)
ser = put_file(token, staticname, staticpath, version='v2')
if ser[0]['key'] == staticname:
return True
return False
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/ce9ba1549b804aa8474b6301f4e7292a.png#pic_center)