def create_secret_key():
"""Flask项目生成secret_key"""
key = os.urandom(66)
return base64.b64encode(key)
def to_md5_hex(content):
"""转化为md5摘要"""
return hashlib.md5(content.encode()).hexdigest()
def random_mobile_code(length=6):
"""生成随机短信验证码"""
return ''.join(random.choices('0123456789', k=length))
def send_code_by_luosimao(tel, message):
"""第三方平台发送手机验证码"""
resp = requests.post(url="http://sms-api.luosimao.com/v1/send.json",
auth=("api", "key-50ba1f06ff0621d335b777a4edd1c0ff"),
data={
"mobile": tel,
"message": message,
}, timeout=3, verify=False)
result = json.loads(resp.content)
return result
# 生成token
# 方法一
token = uuid.uuid1().hex
# 方法二
payload = {
'exp': datetime.datetime.utcnow() + datetime.timedelta(days=1),
'data': {'userid': user.userid}
}
token = jwt.encode(payload, SECRET_KEY, algorithm='HS256').decode()
网友评论