Exemple #1
0
        /// <summary>
        /// 获取解密的token字符串
        /// </summary>
        /// <returns></returns>
        private string GetDecrypTokenString(string token)
        {
            string tokenStr = "";

            //判断是否配置了加密token L.J.X 2016.05.26
            if (ConfigHelper.GetConfigValueByKey("Token_IsEncryptToken").ToInt() == 1)
            {
                token    = token.Replace("[", "+");
                tokenStr = NH.Service.Api.TokenService.DecrypToken(token);
            }
            else
            {
                tokenStr = DataConvert.ConvertBase64ToString(token);
            }
            return(tokenStr);
        }
Exemple #2
0
 /// <summary>
 /// 根据Token的Base64字符转换成对应的Token对象
 /// </summary>
 /// <param name="tokenBase64"></param>
 /// <returns></returns>
 public NH.Entity.Model.Token GetToken(string tokenBase64)
 {
     try
     {
         if (!Utils.StrIsNullOrEmpty(tokenBase64))
         {
             string   tokenString = GetDecrypTokenString(tokenBase64);
             string[] arrayToken  = tokenString.Split(new Char[] { '-' });
             if (arrayToken.Length > 0)
             {
                 string useridBase64     = Convert.ToString(arrayToken[0]);
                 long   timeStamp        = TypeConverter.StrToInt64(arrayToken[1].ToString(), 0);
                 string appKey           = Convert.ToString(arrayToken[2]);
                 bool   IsValidSecretKey = GetIsValidSecretKey(appKey);
                 int    platform         = 0;
                 if (arrayToken.Length > 3)
                 {
                     platform = TypeConverter.StrToInt(arrayToken[3]);
                 }
                 int authenticate = 0;
                 if (arrayToken.Length > 4)
                 {
                     authenticate = TypeConverter.StrToInt(arrayToken[4]);
                 }
                 NH.Entity.Model.Token token = new NH.Entity.Model.Token
                 {
                     UserID           = TypeConverter.StrToInt(DataConvert.ConvertBase64ToString(useridBase64), 0),
                     IsOverdue        = GetIsOverdue(timeStamp),
                     IsValidSecretKey = IsValidSecretKey,
                     AppKey           = appKey,
                     Platform         = (NH.Entity.EnumLibrary.Regplatform)platform,
                     Authenticate     = authenticate
                 };
                 return(token);
             }
         }
     }
     catch
     { }
     return(null);
 }