import itsdangerous #产生一个token def create_token(data): salt = '$$%&&$$%^&&' t = itsdangerous.TimedJSONWebSignatureSerializer(salt, expires_in=60) # 产生一个token res = t.dumps(data) token = res.decode() print('产生的token是', token) return token create_token({"username": "nana"})
#对比token def check_token(token): t = itsdangerous.TimedJSONWebSignatureSerializer('$$%&&$$%^&&') res = t.loads(token) return res print(check_token('eyJhbGciOiJIUzUxMiIsImlhdCI6MTU1ODk0MzIzNywiZXhwIjoxNTU4OTQzMjk3fQ.eyJ1c2VybmFtZSI6Im5hbmEifQ.d3JcPTgXvs34qVra3zb-kQo8YI8FYT0YoSYEJCC6rNPoWNBGLV_8uDmvwg2HBxjKg7-dpruVXikevnTS1hzyfw'))