Exemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            this.returnUrl = WEBRequest.GetQueryString("ReturnUrl");
            LoginType      = ThirdLoginSDK.GetLoginType(CookieHelper.GetCookie("WXLoginType"));
            code           = WEBRequest.GetQueryString("code");

            if (this.returnUrl.IsEmpty())
            {
                this.returnUrl = "/Member/my_account.aspx";
            }
            ThirdLoginSDK shareSdk = new ThirdLoginSDK();
            UserBLL       userbll  = new UserBLL();

            //初始化SDK
            shareSdk.InitSDK(LoginType);

            //根据code获取第三方用户信息
            ThirdLoginSDK.ThirdUserInfo mUserInfo = shareSdk.GetCacheUserInfo();
            string strUId = shareSdk.GetCacheUId();

            SqlParameter[]    paramData = new SqlParameter[] { new SqlParameter("@ThirdPartyId", strUId) };
            UserBasicInfoInfo model     = userbll.WXGetUserBasicInfo("ThirdPartyId=@ThirdPartyId", paramData);

            if (model != null)
            {
                //当已存在时直接登录,并跳转
                WXRegister.UserLogin(model);
                Response.Redirect(this.returnUrl);
                return;
            }
            else
            {
                //用第三登录信息注册一新帐号
                Guid userid          = Guid.NewGuid();
                var  userbasicEntity = WXRegister.AddUserInfo(userid, "tuandai_weixin", "", "", "", mUserInfo.NickName, mUserInfo.HeadImg, mUserInfo.UId, (int)LoginType);
                if (userbasicEntity != null)
                {
                    model = userbll.GetUserBasicInfoModelById(userid);
                    WXRegister.UserLogin(model);
                    Response.Redirect(this.returnUrl);
                    return;
                }
            }

            Response.Redirect("/user/Login.aspx?ReturnUrl=" + this.returnUrl);
        }