0
点赞
收藏
分享

微信扫一扫

jwt python 编码 解码

天天天蓝loveyou 2022-01-17 阅读 56

代码示例

import jwt

# jwt密钥
JWT_SECRET = '04147af1e42c20c3b50bdc111774346e'

# 编码
def encode(payload):
    return jwt.encode(payload, JWT_SECRET, algorithm='HS256')

# 解码
def decode(string):
    return jwt.decode(string, JWT_SECRET, algorithms=['HS256'])

# jwt 内数据(可自定义,一般放用户信息)
payload = {
    "nickname": "管理员",
    "userName": "admin",
    "exp": 9743118683,
    "userId": "2"
}

print(encode(payload))

举报

相关推荐

0 条评论