Exemplo n.º 1
0
        public async Task <CommonResult> MpLogin([FromBody] LoginReq req)
        {
            //已登录直接跳过
            if (HttpContext.IsAuthenticated())
            {
                return(new CommonResult());
            }
            //微信获取session_key
            var session = await WeixinRemote.GetSessionKey(req.Code);

            if (session?.ErrCode != 0)
            {
                return(CommonResult.CreateError(1, ""));
            }
            //数据库中获取微信校验过的身份,没有则新增
            var user = new User {
                OpenId = session.OpenId, UnionId = session.UnionId
            };
            var userDao = new UserDao();

            user = userDao.GetLoginUser(user);
            //写入cookie中
            await SetCookie(user);

            return(new CommonResult());
        }