コード例 #1
0
        public JsonResult LoginValidate(Models.WeiXinInfo userInfo)
        {
            var user = this.weUserAppService.GetWeUser(userInfo.OpenId);

            Common.JsonResultStatus rstJson = new Common.JsonResultStatus();
            rstJson.Code = 200;
            // var user = this.weUserAppService.GetWeUser("oCbECv1pwMNyAodYQtRJVvJf_Zsg");
            if (user == null)
            {
                WeUser.Dto.WeUserInputDto input = new WeUser.Dto.WeUserInputDto();
                input.HeadImgUrl = userInfo.HeadImgUrl;
                input.NickName   = userInfo.NickName;
                input.OpenId     = userInfo.OpenId;
                input.IsInit     = 1;
                weUserAppService.CreateWeUser(input);
                rstJson.Msg = "用户第一次初始化成功,即将跳转";
                // string regUrl = string.Format("/RegisterWeChat/Index?openId={0}&HeadImgUrl={1}&NickName={2}&retUrl=", userInfo.OpenId, userInfo.HeadImgUrl, userInfo.NickName, userInfo.RetUrl);
                // rstJson.RedirectUrl = regUrl;
                rstJson.RedirectUrl = userInfo.RetUrl;
                return(Json(rstJson));
            }
            else
            {
                UserPoints.Dto.UserPointsInputDto points = new UserPoints.Dto.UserPointsInputDto();
                points.Ip     = HttpContext.Request.UserHostAddress;
                points.Score  = int.Parse(Common.CommonConst.PointsScore);
                points.UserId = user.Id;
                this.userPointAppService.AddPointsScore(points);

                string encrtpt = Common.DESEncryptEx.Encrypt(string.Format("{0}|{1}|{2}|{3}|{4}", user.Id, user.PhoneNo, user.NickName, userInfo.AccessToken, userInfo.OpenId));
                Logger.Debug("当前用户Cookie" + encrtpt);
                //        FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
                //1,
                //user.NickName,
                //DateTime.Now,
                //DateTime.Now.Add(FormsAuthentication.Timeout), true, string.Format("{0}|{1}|{2}|{3}|{4}", user.Id, user.PhoneNo, user.NickName, accessToken, opentid)

                //);

                //DateTime.Now.Add(FormsAuthentication.Timeout), true, string.Format("{0}|{1}|{2}|{3}|{4}", user.Id, user.PhoneNo, user.NickName, accessToken, openId)
                //HttpCookie cookie = new HttpCookie(
                //    Common.CommonConst.AuthSaveKey,
                //    FormsAuthentication.Encrypt(ticket));
                HttpCookie cookie = new HttpCookie(
                    Common.CommonConst.AuthSaveKey,
                    encrtpt);
                Response.Cookies.Add(cookie);
                rstJson.Msg         = "用户验证成功,即将跳转";
                rstJson.RedirectUrl = userInfo.RetUrl;
                return(Json(rstJson));
            }


            //return Json(retUrl);
        }
コード例 #2
0
        public JsonResult LoginValidate(Models.WeiXinInfo userInfo)
        {
            var user = this.userAppService.GetT_UserByOpenIdAsync(userInfo.OpenId);

            Models.JsonResultStatus rstJson = new Models.JsonResultStatus();
            rstJson.Code = 200;
            // var user = this.weUserAppService.GetWeUser("oCbECv1pwMNyAodYQtRJVvJf_Zsg");
            if (user == null)
            {
                rstJson.Msg = "未绑定工资号,即将跳转到绑定页面";
                // string regUrl = string.Format("/RegisterWeChat/Index?openId={0}&HeadImgUrl={1}&NickName={2}&retUrl=", userInfo.OpenId, userInfo.HeadImgUrl, userInfo.NickName, userInfo.RetUrl);
                // rstJson.RedirectUrl = regUrl;
                rstJson.RedirectUrl = userInfo.RetUrl;
                return(Json(rstJson));
            }
            else
            {
                string encrtpt = Common.DESEncryptEx.Encrypt(string.Format("{0}|{1}|{2}", user.Id, userInfo.AccessToken, userInfo.OpenId));
                Logger.Debug("当前用户Cookie" + encrtpt);
                //        FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
                //1,
                //user.NickName,
                //DateTime.Now,
                //DateTime.Now.Add(FormsAuthentication.Timeout), true, string.Format("{0}|{1}|{2}|{3}|{4}", user.Id, user.PhoneNo, user.NickName, accessToken, opentid)

                //);

                //DateTime.Now.Add(FormsAuthentication.Timeout), true, string.Format("{0}|{1}|{2}|{3}|{4}", user.Id, user.PhoneNo, user.NickName, accessToken, openId)
                //HttpCookie cookie = new HttpCookie(
                //    Common.CommonConst.AuthSaveKey,
                //    FormsAuthentication.Encrypt(ticket));
                HttpCookie cookie = new HttpCookie(
                    Common.AbpWebConst.AuthSaveKey,
                    encrtpt);
                Response.Cookies.Add(cookie);
                rstJson.Msg         = "用户验证成功,即将跳转";
                rstJson.RedirectUrl = userInfo.RetUrl;
                return(Json(rstJson));
            }
        }