Exemplo n.º 1
0
        public async Task <IActionResult> WxWebLogin(string code, string url, string state)
        {
            var accessTokenResult = await WebAppAutherize.GetUserAccessToken(WxAppId, WxAppSecret, code);

            //await distributedCache.SetValue(new RedisDocument<UserAccessTokenResult>
            //{
            //    ExpireTime = DateTime.Now.AddSeconds(accessTokenResult.ExpiresIn),
            //    Key = WxAppId + "_" + accessTokenResult.OpenId + "_AccessToken",
            //    SetTime = DateTime.Now,
            //    Value = accessTokenResult
            //});
            var userInfo = await WebAppAutherize.GetUserInfo(accessTokenResult.AccessToken, accessTokenResult.OpenId);

            userInfo.AppId = configuration["wx:appId"];
            var wxLoginUserId = await userAuthBusiness.WxWebLoin(userInfo);

            //将用户Id提交到Redis 缓存

            HttpContext.Session.Set(UserAuthBusiness.UserAuthFrontendKey, Encoding.UTF8.GetBytes(wxLoginUserId));
            await HttpContext.Session.CommitAsync();

            await SetAuth(wxLoginUserId);

            return(Redirect(url));
        }
Exemplo n.º 2
0
 public Task <WebAppAuthUserInfo> GetUserInfo(string accessToken, string openId) => WebAppAutherize.GetUserInfo(accessToken, openId);