/// <summary> /// 返回字符串token /// </summary> /// <param name="user"></param> /// <returns></returns> public static string GenerateUserToken(ITokenUserInfo user) { string userToken = string.Empty; GenerateUserToken(user, out userToken); return(userToken); }
/// <summary> /// 用户对象,生成令牌 /// </summary> /// <param name="user">用户对象</param> /// <param name="UserToken">令牌</param> /// <returns>true/false</returns> public static bool GenerateUserToken(ITokenUserInfo user, out string userToken) { userToken = string.Empty; if (user != null && user.userId > 0 && !string.IsNullOrEmpty(user.nickName)) { StringBuilder sb = new StringBuilder(); sb.Append(((int)user.tokenType).ToString()); sb.Append(Separator); sb.Append(user.userId.ToString()); sb.Append(Separator); sb.Append(((int)(user.type)).ToString()); sb.Append(Separator); sb.Append(user.nickName.ToString()); sb.Append(Separator); sb.Append(user.status.ToString()); sb.Append(Separator); sb.Append(user.channelId); sb.Append(Separator); sb.Append(user.roleId.ToString()); sb.Append(Separator); sb.Append(user.roleName); sb.Append(Separator); sb.Append(user.isManage.ToString()); userToken = NiuCryptoService.EncryptToken(sb.ToString()); userToken = userToken.Replace("+", "-").Replace("/", "_").Replace("=", "*"); userToken = System.Web.HttpUtility.UrlEncode(userToken, System.Text.Encoding.UTF8); return(true); } return(false); }