Beispiel #1
0
        public async Task SetAsync()
        {
            var hash = new List <HashSetDto>
            {
                new HashSetDto("1", "a"),
                new HashSetDto("2", "b"),
                new HashSetDto("3", "c")
            };
            await _cache.SetStringAsync("hashTest", "123213");

            //var result = await _dispatcher.QueryAsync(query);
            //return result.ToList();
        }
        public async Task <ApiRequestResult> SignIn([FromBody] SignInCommand command)
        {
            try
            {
                var ip     = _accessor.HttpContext?.Connection?.RemoteIpAddress?.ToString();
                var result = await _identityServices.SignInAsync(command.UserName, command.Password, UserType.Member);

                var redisExpireTime = _configuration.GetSection("redis:expiryMinutes").Value.ToString();
                var expirtime       = new DistributedCacheEntryOptions
                {
                    AbsoluteExpiration = DateTime.Now.AddMinutes(Convert.ToInt32(redisExpireTime))
                };
                await _cache.SetStringAsync(result.AccessToken, JsonConvert.SerializeObject(result), expirtime);

                var data = new { tokenHead = "Bearer", token = result.AccessToken };
                //添加登录记录
                await _userLoginRepository.AddAsync(new UserLogin
                {
                    UserId              = Guid.Parse(result.Id),
                    LoginProvider       = "ManageSystem",
                    ProviderDisplayName = "管理系统",
                    ProviderKey         = Guid.NewGuid().ToString(),
                    LoginIp             = ip
                });

                return(ApiRequestResult.Success(data, "登录成功"));
            }
            catch (Exception ex)
            {
                return(ApiRequestResult.Error("账号密码错误,请重新输入"));

                throw ex;
            }
        }
Beispiel #3
0
        /// <summary>
        /// 获取微信accesstoken, 优先从缓存获取,其次重新请求获取
        /// </summary>
        /// <returns></returns>
        public async Task <HttpRequestResult> GetAccessTokenAsync()
        {
            var accessToken = await _aSampleRedisCache.GetStringAsync(_wechatKey);

            if (!string.IsNullOrWhiteSpace(accessToken))
            {
                return(HttpRequestResult.Success(accessToken, ""));
            }
            var result = await RequestAccessTokenAsync();

            if (string.IsNullOrWhiteSpace(result.AccessToken))
            {
                return(HttpRequestResult.Error("AccessToken is null"));
            }
            await _aSampleRedisCache.SetStringAsync(_wechatKey, result.AccessToken, 120);

            return(HttpRequestResult.Success(result.AccessToken, ""));
        }