Example #1
0
        /// <summary>
        /// 验证令牌,生成用户
        /// </summary>
        /// <param name="strUserToken">令牌</param>
        /// <param name="user">返回用户对象</param>
        /// <returns>true/false</returns>
        public static bool ValidateUserToken(string userToken, out TokenUserInfo user)
        {
            user = null;
            try
            {
                string[] userInfoArray = null;
                if (!string.IsNullOrEmpty(userToken))
                {
                    userToken = System.Web.HttpUtility.UrlDecode(userToken, System.Text.Encoding.UTF8);

                    userToken = userToken.Replace("-", "+").Replace("_", "/").Replace("*", "=");

                    userToken     = NiuCryptoService.DecryptToken(userToken);
                    userInfoArray = userToken.Split(Separator);

                    if (userInfoArray.Length == 9)
                    {
                        user = new TokenUserInfo()
                        {
                            userId    = ObjectConvert.ChangeType <long>(userInfoArray[1], 0),
                            nickName  = userInfoArray[3],
                            tokenType = (tokenType)ObjectConvert.ChangeType <long>(userInfoArray[0], 0),
                            type      = (userType)ObjectConvert.ChangeType <int>(userInfoArray[2], 0),
                            status    = ObjectConvert.ChangeType <int>(userInfoArray[4], 0),
                            channelId = ObjectConvert.ChangeType <int>(userInfoArray[5], 0),
                            roleId    = ObjectConvert.ChangeType <int>(userInfoArray[6], 0),
                            roleName  = userInfoArray[7],
                            isManage  = ObjectConvert.ChangeType <int>(userInfoArray[8], 0)
                        };
                    }
                }
            }
            catch (Exception ex)
            {
                logRecord.WriteSingleLog("ValidateUserToken.log", string.Format("error:{0}", ex.Message));
            }

            return(true);
        }