py jwt

import jwt,time
# 将上面生成的 jwt 进行解析认证
def jwts(jwt_token):

    try:
        payload = jwt.decode(jwt_token,"xinhai0574", options={'verify_exp': False})
        if payload:
            return payload
        else:
            raise jwt.InvalidTokenError
    except jwt.ExpiredSignatureError:
        return 'Token过期'

    except jwt.InvalidTokenError:
        return '无效Token'


def create_token():
    payload = {
         "exp": int(time.time()) + 30,
         "userName": "施庆生",
          'type': 4
    }
    token = jwt.encode(payload, 'xinhai0574', algorithm='HS256')
    return token

评论

刷新

友情链接