/// <summary> /// 获取Token中的Payload /// </summary> /// <param name="req">请求</param> /// <returns></returns> public static JWTPayload GetJWTPayload(this HttpRequest req) { string token = req.GetToken(); var payload = JWTHelper.GetPayload <JWTPayload>(token); return(payload); }
/// <summary> /// 刷新Token /// 切换项目--刷新Token /// </summary> /// <param name="token"></param> /// <param name="projectId"></param> /// <returns></returns> public static string RefreshToken(this string token, string projectId = "") { if (CheckToken(token)) { var payload = JWTHelper.GetPayload <JWTPayload>(token); payload.ProjectId = projectId.IsNullOrEmpty() ? payload.ProjectId : projectId; //验证当前时间是否在有效的刷新时间段内 if (payload.Expire.AddHours(jwtOptions.RefreshExpireHours) >= DateTime.Now) { return(payload.GetToken()); } throw new BusException("登陆超时,请重新登陆"); } throw new BusException("token验证失败"); }