Esempio n. 1
0
        public async Task <AuthenticateResultModel> AuthenticateLogin([FromBody] AuthenticateInput input)
        {
            var openId = string.Empty;

#if DEBUG
            openId = "testopenid";
#else
            Console.WriteLine(WxOpenAppId);
            var jsonResult = await SnsApi.JsCode2JsonAsync(WxOpenAppId, WxOpenAppSecret, input.Code);

            if (jsonResult.errcode == ReturnCode.请求成功)
            {
                openId = jsonResult.openid;
            }
#endif
            Console.WriteLine(openId);
            var dto = await _userAppService.Authorize(openId, input.HeadId);

            IdentityUser login = new IdentityUser
            {
                RememberMe = true,
                UserId     = dto.Id.ToString(),
                Name       = dto.NickName,
            };

            var accessToken =
                CreateAccessToken(CreateJwtClaims(login.CreateIdentity(JwtBearerDefaults.AuthenticationScheme)));

            return(new AuthenticateResultModel
            {
                AccessToken = accessToken,
                ExpireInSeconds = (int)TimeSpan.FromDays(30).TotalSeconds,
                UserId = dto.Id.ToString()
            });
        }