예제 #1
0
        public static TokenInfo GetToken(string userId)
        {
            TokenInfo existToken = null;

            try
            {
                CacheObject co = DistributedCacheManage.GetLocalCache("tokenList");
                if (co != null)
                {
                    CacheData cd = co.cacheValue.SingleOrDefault(x => (x.deleteflag == false && x.key.Split((char)1)[0] == userId));
                    if (cd != null)
                    {
                        existToken = JsonConvert.DeserializeObject <TokenInfo>(cd.value);
                        //更新时间
                        DistributedCacheManage.SetCache("tokenList", cd.key, JsonConvert.SerializeObject(existToken));
                    }
                }
            }
            catch { }
            return(existToken);
        }
예제 #2
0
        public static AuthResult ValidateToken(string token)
        {
            AuthResult result = new AuthResult()
            {
                ErrorMsg = "Token不存在或已过期"
            };
            CacheObject co = DistributedCacheManage.GetLocalCache("tokenList");

            if (co != null)
            {
                CacheData cd = co.cacheValue.Find(x => x.key == token && x.deleteflag == false);
                if (cd != null)
                {
                    result.token    = token;
                    result.User     = JsonConvert.DeserializeObject <UserInfo>(cd.value);
                    result.ErrorMsg = string.Empty;
                }
            }

            return(result);
        }