Exemple #1
0
        public OAuthUserInfo GetUserInfo(System.Collections.Specialized.NameValueCollection queryString)
        {
            var config = WeiboCore.GetConfig();
            var oatuth = new NetDimension.Weibo.OAuth(config.AppKey, config.AppSecret, ReturnUrl);

            NetDimension.Weibo.Client client = new NetDimension.Weibo.Client(oatuth);
            var code        = queryString["code"];
            var accessToken = oatuth.GetAccessTokenByAuthorizationCode(code);

            OAuthUserInfo userInfo = null;

            if (oatuth != null)
            {
                userInfo        = new OAuthUserInfo();
                userInfo.OpenId = client.API.Entity.Account.GetUID();
                var user = client.API.Entity.Users.Show(userInfo.OpenId);
                userInfo.NickName = userInfo.RealName = user.Name;
                userInfo.IsMale   = user.Gender == "m";
            }
            return(userInfo);
        }
Exemple #2
0
        protected void ReceiveThirdRequest()
        {
            if (Request.QueryString["code"] != null && Request.QueryString["code"] != "" && Request.QueryString["state"] != null)
            {
                //QQ回调
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(Path.GetFullPath(Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "App_Data/ThirdLogin.xml")));
                XmlNode node = xmlDoc.SelectSingleNode("//ThirdLogin//QQ//AppID");
                XmlNode node1 = xmlDoc.SelectSingleNode("//ThirdLogin//QQ//Key");
                //获取Access Token
                System.Net.HttpWebRequest req = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create("https://graph.qq.com/oauth2.0/token?grant_type=authorization_code&client_id=" + node.InnerText + "&client_secret=" + node1.InnerText
                    + "&code=" + Request.QueryString["code"] + "&redirect_uri=" + AppConfig.HomeUrl() + "Passport/ThirdLogin.aspx");
                System.Net.HttpWebResponse res = (System.Net.HttpWebResponse)req.GetResponse();
                Encoding encoding = Encoding.UTF8;
                StreamReader reader = new StreamReader(res.GetResponseStream(), encoding);
                string ret = reader.ReadToEnd();
                string code = "";
                int timespan = 0;
                try
                {
                    code = ret.Split(new char[] { '&' })[0].Split(new char[] { '=' })[1];
                    timespan = int.Parse(ret.Split(new char[] { '&' })[1].Split(new char[] { '=' })[1]);
                }
                catch(Exception ex)
                {
                    LogManagement.getInstance().WriteException(ex, "WebForMain.ThirdLogin", Request.UserHostAddress);
                    ShowError("系统故障,请联系管理员");
                }
                //获取OpenID
                req = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create("https://graph.qq.com/oauth2.0/me?access_token=" + code);
                res = (System.Net.HttpWebResponse)req.GetResponse();
                reader = new StreamReader(res.GetResponseStream(), encoding);
                ret = reader.ReadToEnd();
                string openid = "";
                try
                {
                    openid = ret.Split(new char[] { '"' })[7];
                }
                catch
                {
                    ShowError("系统故障,请联系管理员");
                }
                //获取用户信息
                req = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(@"https://graph.qq.com/user/get_user_info?access_token=" +code+

            "&oauth_consumer_key=" + node.InnerXml +

            "&openid=" + openid);
                res = (System.Net.HttpWebResponse)req.GetResponse();
                reader = new StreamReader(res.GetResponseStream(), encoding);
                ret = reader.ReadToEnd();

                try
                {
                    ViewState["nickname"] = ret.Split(new char[] { ':',',' })[7].Replace(@"""","").Trim();
                    ViewState["photo"] = ret.Split(new string[] { @""":", "," }, StringSplitOptions.None)[19].Replace(@"""", "").Replace(@"\", "").Trim();
                    if (USR_CustomerBll.GetInstance().CheckNickName(ViewState["nickname"].ToString().Trim()).SysNo != AppConst.IntNull)
                    {
                        newname.Style["display"] = "";
                    }
                }
                catch
                {
                    ShowError("系统故障,请联系管理员");
                }

                USR_CustomerMod m_customer = USR_CustomerBll.GetInstance().GetUserByThirdID(openid);
                if (m_customer != null && m_customer.SysNo != AppConst.IntNull)
                {
                    SetSession(m_customer);
                    m_customer.LastLoginTime = DateTime.Now;
                    USR_CustomerBll.GetInstance().Update(m_customer);
                    if (Request.QueryString["url"] != null && Request.QueryString["url"] != "")
                    {
                        Response.Redirect(Request.QueryString["url"]);
                    }
                    else
                    {
                        Response.Redirect("../Qin/View/" + m_customer.SysNo);
                    }
                    return;
                }

                ViewState["openid"] = openid;
                ViewState["expire"] = timespan;
                ViewState["code"] = code;
                ViewState["type"] = "qq";
            }

            else if (Request.QueryString["code"] != null && Request.QueryString["code"] != "")
            {
                //新浪微博回调
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(Path.GetFullPath(Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "App_Data/ThirdLogin.xml")));
                XmlNode node = xmlDoc.SelectSingleNode("//ThirdLogin//WeiBo//AppID");
                XmlNode node1 = xmlDoc.SelectSingleNode("//ThirdLogin//WeiBo//Key");
                var oauth = new NetDimension.Weibo.OAuth(node.InnerText, node1.InnerText, AppConfig.HomeUrl() + "Passport/ThirdLogin.aspx");

                var accessToken = oauth.GetAccessTokenByAuthorizationCode(Request.QueryString["code"]);
                var uid = "";
                if (!string.IsNullOrEmpty(accessToken.Token))
                {
                    var Sina = new NetDimension.Weibo.Client(oauth);
                    uid = Sina.API.Account.GetUID(); //调用API中获取UID的方法
                    var userinfo = Sina.API.Users.Show(uid: uid);
                    Response.Write(userinfo);
                }

                USR_CustomerMod m_customer = USR_CustomerBll.GetInstance().GetUserByThirdID(uid);
                if (m_customer != null && m_customer.SysNo != AppConst.IntNull)
                {
                    SetSession(m_customer);
                    m_customer.LastLoginTime = DateTime.Now;
                    USR_CustomerBll.GetInstance().Update(m_customer);
                    if (Request.QueryString["url"] != null && Request.QueryString["url"] != "")
                    {
                        Response.Redirect(Request.QueryString["url"]);
                    }
                    else
                    {
                        Response.Redirect("../Qin/View/" + m_customer.SysNo);
                    }
                    return;
                }

                ViewState["openid"] = uid;
                ViewState["code"] = Request.QueryString["code"];
                ViewState["type"] = "weibo";
            }
        }
Exemple #3
0
        public ReturnValue<USR_CustomerMaintain> WeiboLogin(string code)
        {
            //新浪微博回调
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(Container.ConfigService.GetAppSetting<string>("ThirdLoginFilePath", ""));
            XmlNode node = xmlDoc.SelectSingleNode("//ThirdLogin//WeiBo//AppID");
            XmlNode node1 = xmlDoc.SelectSingleNode("//ThirdLogin//WeiBo//Key");
            var oauth = new NetDimension.Weibo.OAuth(node.InnerText, node1.InnerText, Container.ConfigService.GetAppSetting<string>("HomeUrl", "") + "Passport/ThirdLogin.aspx");

            var accessToken = oauth.GetAccessTokenByAuthorizationCode(code);
            var uid = "";
            if (!string.IsNullOrEmpty(accessToken.Token))
            {
                var Sina = new NetDimension.Weibo.Client(oauth);
                uid = Sina.API.Account.GetUID(); //调用API中获取UID的方法
            }

            USR_CustomerMod m_customer = USR_CustomerBll.GetInstance().GetUserByThirdID(uid);
            if (m_customer != null && m_customer.SysNo != AppConst.IntNull)
            {
                m_customer.LastLoginTime = DateTime.Now;
                USR_CustomerBll.GetInstance().Update(m_customer);

                USR_CustomerMaintain ret = new USR_CustomerMaintain();
                m_customer.MemberwiseCopy(ret);
                return ReturnValue<USR_CustomerMaintain>.Get200OK(ret);
            }

            USR_ThirdLoginMod m_third = new USR_ThirdLoginMod();
            m_third.OpenID = uid;
            m_third.AccessKey = code;
            m_third.ThirdType = (int)AppEnum.ThirdLoginType.weibo;
            USR_CustomerMod m_user = new USR_CustomerMod();
            try
            {
                m_user.Email = "";
                m_user.FateType = (int)AppEnum.FateType.astro;
                m_user.GradeSysNo = AppConst.OriginalGrade; ;
                m_user.NickName = uid;
                m_user.Password = "";
                m_user.RegTime = DateTime.Now;
                m_user.Point = AppConst.OriginalPoint;
                m_user.Photo = AppConst.OriginalPhoto;
                m_user.LastLoginTime = DateTime.Now;
                if (Container.ConfigService.GetAppSetting<string>("RegisterEmailCheck", "false").ToLower() == "true")
                {
                    m_user.Status = (int)AppEnum.State.prepare;
                }
                else
                {
                    m_user.Status = (int)AppEnum.State.normal;
                }

                m_user.Credit = 0;
                m_user.Birth = AppConst.DateTimeNull;
                m_user.IsShowBirth = 1;
                m_user.IsStar = 0;
                m_user.BestAnswer = 0;
                m_user.TotalAnswer = 0;
                m_user.TotalQuest = 0;
                m_user.HomeTown = AppConst.IntNull;
                m_user.Intro = AppConst.OriginalIntro;
                m_user.Signature = AppConst.OriginalSign;
                m_user.Exp = 0;
                m_user.TotalReply = 0;

                m_user.SysNo = USR_CustomerBll.GetInstance().Add(m_user);

                m_third.CustomerSysNo = m_user.SysNo;
                USR_ThirdLoginBll.GetInstance().Add(m_third);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

            USR_CustomerMaintain rett = new USR_CustomerMaintain();
            m_customer.MemberwiseCopy(rett);
            return ReturnValue<USR_CustomerMaintain>.Get200OK(rett);
        }
        public ReturnValue <USR_CustomerMaintain> WeiboLogin(string code)
        {
            //新浪微博回调
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(Container.ConfigService.GetAppSetting <string>("ThirdLoginFilePath", ""));
            XmlNode node  = xmlDoc.SelectSingleNode("//ThirdLogin//WeiBo//AppID");
            XmlNode node1 = xmlDoc.SelectSingleNode("//ThirdLogin//WeiBo//Key");
            var     oauth = new NetDimension.Weibo.OAuth(node.InnerText, node1.InnerText, Container.ConfigService.GetAppSetting <string>("HomeUrl", "") + "Passport/ThirdLogin.aspx");

            var accessToken = oauth.GetAccessTokenByAuthorizationCode(code);
            var uid         = "";

            if (!string.IsNullOrEmpty(accessToken.Token))
            {
                var Sina = new NetDimension.Weibo.Client(oauth);
                uid = Sina.API.Account.GetUID(); //调用API中获取UID的方法
            }

            USR_CustomerMod m_customer = USR_CustomerBll.GetInstance().GetUserByThirdID(uid);

            if (m_customer != null && m_customer.SysNo != AppConst.IntNull)
            {
                m_customer.LastLoginTime = DateTime.Now;
                USR_CustomerBll.GetInstance().Update(m_customer);

                USR_CustomerMaintain ret = new USR_CustomerMaintain();
                m_customer.MemberwiseCopy(ret);
                return(ReturnValue <USR_CustomerMaintain> .Get200OK(ret));
            }

            USR_ThirdLoginMod m_third = new USR_ThirdLoginMod();

            m_third.OpenID    = uid;
            m_third.AccessKey = code;
            m_third.ThirdType = (int)AppEnum.ThirdLoginType.weibo;
            USR_CustomerMod m_user = new USR_CustomerMod();

            try
            {
                m_user.Email         = "";
                m_user.FateType      = (int)AppEnum.FateType.astro;
                m_user.GradeSysNo    = AppConst.OriginalGrade;;
                m_user.NickName      = uid;
                m_user.Password      = "";
                m_user.RegTime       = DateTime.Now;
                m_user.Point         = AppConst.OriginalPoint;
                m_user.Photo         = AppConst.OriginalPhoto;
                m_user.LastLoginTime = DateTime.Now;
                if (Container.ConfigService.GetAppSetting <string>("RegisterEmailCheck", "false").ToLower() == "true")
                {
                    m_user.Status = (int)AppEnum.State.prepare;
                }
                else
                {
                    m_user.Status = (int)AppEnum.State.normal;
                }

                m_user.Credit      = 0;
                m_user.Birth       = AppConst.DateTimeNull;
                m_user.IsShowBirth = 1;
                m_user.IsStar      = 0;
                m_user.BestAnswer  = 0;
                m_user.TotalAnswer = 0;
                m_user.TotalQuest  = 0;
                m_user.HomeTown    = AppConst.IntNull;
                m_user.Intro       = AppConst.OriginalIntro;
                m_user.Signature   = AppConst.OriginalSign;
                m_user.Exp         = 0;
                m_user.TotalReply  = 0;

                m_user.SysNo = USR_CustomerBll.GetInstance().Add(m_user);

                m_third.CustomerSysNo = m_user.SysNo;
                USR_ThirdLoginBll.GetInstance().Add(m_third);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

            USR_CustomerMaintain rett = new USR_CustomerMaintain();

            m_customer.MemberwiseCopy(rett);
            return(ReturnValue <USR_CustomerMaintain> .Get200OK(rett));
        }
Exemple #5
0
        public ActionResult WeiboCallback()
        {
            if (Request.Params["code"] != null)
            {
                var authAode = Request.Params["code"];
                var oauth = new NetDimension.Weibo.OAuth(Config.WeiboAppkey, Config.WeiboAppSecret, callback_weibo_url);
                var weiboClient = new NetDimension.Weibo.Client(oauth);
                var accessToken = oauth.GetAccessTokenByAuthorizationCode(authAode);
                if (!string.IsNullOrEmpty(accessToken.Token))
                {
                    var openId = weiboClient.API.Entity.Account.GetUID();

                    var asd = weiboClient.API.Entity.Users.Show(openId);

                    //var cmd = new UserWeiboLogin(openId, asd.Name, this.GetUserIPAddress());
                    //this.CommandBus.Send(cmd);

                    //var loginUser = IoC.Resolve<IUserQuery>().GetUserByOpenID(openId, OpenAuthType.WEIBO);

                    //if (loginUser.IsLocked) return Redirect("~/index");
                    //else
                    //{
                    //    //暂存用户信息
                    //    var verifyHash = KeepCurrentUserInfoInTmpAndReturnHash(loginUser);
                    //    //判断用户是否开了双重身份验证
                    //    var code = 1 | (loginUser.IsOpenLoginGA ? 2 : 0) | (loginUser.IsOpenLoginSMS ? 4 : 0);
                    //    if (code > 1)
                    //    {
                    //        return Json(new { Code = 2, ReturnUrl = string.Empty, Hash = verifyHash });
                    //    }
                    //    else
                    //    {
                    //        this.CurrentUserPassTwoFactoryVerify();
                    //        return Json(new { Code = 1, ReturnUrl = string.Empty });
                    //    }
                    //}
                }
            }
            return Redirect("~/index");
        }
Exemple #6
0
        protected void ReceiveThirdRequest()
        {
            if (Request.QueryString["code"] != null && Request.QueryString["code"] != "" && Request.QueryString["state"] != null)
            {
                //QQ回调
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(Path.GetFullPath(Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "App_Data/ThirdLogin.xml")));
                XmlNode node  = xmlDoc.SelectSingleNode("//ThirdLogin//QQ//AppID");
                XmlNode node1 = xmlDoc.SelectSingleNode("//ThirdLogin//QQ//Key");
                //获取Access Token
                System.Net.HttpWebRequest req = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create("https://graph.qq.com/oauth2.0/token?grant_type=authorization_code&client_id=" + node.InnerText + "&client_secret=" + node1.InnerText
                                                                                                            + "&code=" + Request.QueryString["code"] + "&redirect_uri=" + AppConfig.HomeUrl() + "Passport/ThirdLogin.aspx");
                System.Net.HttpWebResponse res = (System.Net.HttpWebResponse)req.GetResponse();
                Encoding     encoding          = Encoding.UTF8;
                StreamReader reader            = new StreamReader(res.GetResponseStream(), encoding);
                string       ret      = reader.ReadToEnd();
                string       code     = "";
                int          timespan = 0;
                try
                {
                    code     = ret.Split(new char[] { '&' })[0].Split(new char[] { '=' })[1];
                    timespan = int.Parse(ret.Split(new char[] { '&' })[1].Split(new char[] { '=' })[1]);
                }
                catch (Exception ex)
                {
                    LogManagement.getInstance().WriteException(ex, "WebForMain.ThirdLogin", Request.UserHostAddress);
                    ShowError("系统故障,请联系管理员");
                }
                //获取OpenID
                req    = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create("https://graph.qq.com/oauth2.0/me?access_token=" + code);
                res    = (System.Net.HttpWebResponse)req.GetResponse();
                reader = new StreamReader(res.GetResponseStream(), encoding);
                ret    = reader.ReadToEnd();
                string openid = "";
                try
                {
                    openid = ret.Split(new char[] { '"' })[7];
                }
                catch
                {
                    ShowError("系统故障,请联系管理员");
                }
                //获取用户信息
                req = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(@"https://graph.qq.com/user/get_user_info?access_token=" + code +

                                                                                  "&oauth_consumer_key=" + node.InnerXml +

                                                                                  "&openid=" + openid);
                res    = (System.Net.HttpWebResponse)req.GetResponse();
                reader = new StreamReader(res.GetResponseStream(), encoding);
                ret    = reader.ReadToEnd();

                try
                {
                    ViewState["nickname"] = ret.Split(new char[] { ':', ',' })[7].Replace(@"""", "").Trim();
                    ViewState["photo"]    = ret.Split(new string[] { @""":", "," }, StringSplitOptions.None)[19].Replace(@"""", "").Replace(@"\", "").Trim();
                    if (USR_CustomerBll.GetInstance().CheckNickName(ViewState["nickname"].ToString().Trim()).SysNo != AppConst.IntNull)
                    {
                        newname.Style["display"] = "";
                    }
                }
                catch
                {
                    ShowError("系统故障,请联系管理员");
                }


                USR_CustomerMod m_customer = USR_CustomerBll.GetInstance().GetUserByThirdID(openid);
                if (m_customer != null && m_customer.SysNo != AppConst.IntNull)
                {
                    SetSession(m_customer);
                    m_customer.LastLoginTime = DateTime.Now;
                    USR_CustomerBll.GetInstance().Update(m_customer);
                    if (Request.QueryString["url"] != null && Request.QueryString["url"] != "")
                    {
                        Response.Redirect(Request.QueryString["url"]);
                    }
                    else
                    {
                        Response.Redirect("../Qin/View/" + m_customer.SysNo);
                    }
                    return;
                }

                ViewState["openid"] = openid;
                ViewState["expire"] = timespan;
                ViewState["code"]   = code;
                ViewState["type"]   = "qq";
            }

            else if (Request.QueryString["code"] != null && Request.QueryString["code"] != "")
            {
                //新浪微博回调
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(Path.GetFullPath(Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "App_Data/ThirdLogin.xml")));
                XmlNode node  = xmlDoc.SelectSingleNode("//ThirdLogin//WeiBo//AppID");
                XmlNode node1 = xmlDoc.SelectSingleNode("//ThirdLogin//WeiBo//Key");
                var     oauth = new NetDimension.Weibo.OAuth(node.InnerText, node1.InnerText, AppConfig.HomeUrl() + "Passport/ThirdLogin.aspx");

                var accessToken = oauth.GetAccessTokenByAuthorizationCode(Request.QueryString["code"]);
                var uid         = "";
                if (!string.IsNullOrEmpty(accessToken.Token))
                {
                    var Sina = new NetDimension.Weibo.Client(oauth);
                    uid = Sina.API.Account.GetUID(); //调用API中获取UID的方法
                    var userinfo = Sina.API.Users.Show(uid: uid);
                    Response.Write(userinfo);
                }

                USR_CustomerMod m_customer = USR_CustomerBll.GetInstance().GetUserByThirdID(uid);
                if (m_customer != null && m_customer.SysNo != AppConst.IntNull)
                {
                    SetSession(m_customer);
                    m_customer.LastLoginTime = DateTime.Now;
                    USR_CustomerBll.GetInstance().Update(m_customer);
                    if (Request.QueryString["url"] != null && Request.QueryString["url"] != "")
                    {
                        Response.Redirect(Request.QueryString["url"]);
                    }
                    else
                    {
                        Response.Redirect("../Qin/View/" + m_customer.SysNo);
                    }
                    return;
                }

                ViewState["openid"] = uid;
                ViewState["code"]   = Request.QueryString["code"];
                ViewState["type"]   = "weibo";
            }
        }