/// <summary> /// 解析 /// </summary> /// <param name="jwtStr"></param> /// <returns></returns> public static TokenModelJwt SerializeJwt(string jwtStr) { var jwtHandler = new JwtSecurityTokenHandler(); TokenModelJwt tokenModelJwt = new TokenModelJwt(); // token校验 if (jwtStr.IsNotEmptyOrNull() && jwtHandler.CanReadToken(jwtStr)) { JwtSecurityToken jwtToken = jwtHandler.ReadJwtToken(jwtStr); object role; jwtToken.Payload.TryGetValue(ClaimTypes.Role, out role); tokenModelJwt = new TokenModelJwt { Uid = (jwtToken.Id).ObjToInt(), Role = role != null?role.ObjToString() : "", }; } return(tokenModelJwt); }