You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

14 lines
438 B

from datetime import datetime, timedelta
import jwt
def generate_jwt_token(user):
payload = {
'user_id': user.id,
'exp': datetime.utcnow() + timedelta(days=14), # 令牌有效期为两周
'iat': datetime.utcnow()
}
token = jwt.encode(payload, 'django-insecure-#ru&o+c%h83_gp_wo=z#wub(#4vn4)xz*c2!24i1ft!+v^_unm', algorithm='HS256') # 'your_secret_key' 替换为你自己的密钥
return token