'commit'
This commit is contained in:
@@ -29,15 +29,24 @@ class KlCommon:
|
||||
# 构建JWT令牌
|
||||
payload = {
|
||||
'iss': KlCommon.ak,
|
||||
'exp': expired_at,
|
||||
'nbf': not_before
|
||||
'exp': int(expired_at.timestamp()), # 转换为Unix时间戳
|
||||
'nbf': int(not_before.timestamp()) # 转换为Unix时间戳
|
||||
}
|
||||
|
||||
# 定义JWT头部
|
||||
headers = {
|
||||
'alg': 'HS256',
|
||||
'typ': 'JWT' # 添加类型声明
|
||||
}
|
||||
|
||||
# 使用HS256算法签名
|
||||
jwt_token = jwt.encode(payload, KlCommon.sk, algorithm='HS256', headers={'alg': 'HS256'})
|
||||
jwt_token = jwt.encode(payload, KlCommon.sk, algorithm='HS256', headers=headers)
|
||||
# 增强调试信息
|
||||
log.info(f"生成JWT令牌: {jwt_token[:10]}...{jwt_token[-10:]}") # 只打印部分令牌
|
||||
log.debug(f"JWT过期时间: {expired_at}")
|
||||
return jwt_token
|
||||
except Exception as e:
|
||||
log.error(f"获取JWT令牌失败: {str(e)}")
|
||||
log.error(f"获取JWT令牌失败: {str(e)}", exc_info=True)
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
|
Reference in New Issue
Block a user