Example #1
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            //实例化一个操作类,用刚才成功获得了AccessToken的OAuth实例
                NetDimension.Weibo.Client Sina = new NetDimension.Weibo.Client(Authorize.oauth);
            if (funcNo == 1)
            {
                Sina.API.Dynamic.Statuses.Update(textBox1.Text  + DateTime.Now.ToLongTimeString());
                mainForm.lstMessage.Items.Insert(0, "发布成功." + DateTime.Now.ToString());
                this.Close();
            }
            else if (funcNo == 2)
            {
                if (pb.Image != null)
                {

                    try
                    {
                        byte[] Byte = BasicFunc.ImageToByte(pb.Image);
                        Sina.API.Dynamic.Statuses.Upload(textBox1.Text, Byte);
                        mainForm.lstMessage.Items.Insert(0, "发布成功." + DateTime.Now.ToString());
                        this.Close();
                    }
                    catch (Exception ex)
                    {
                        mainForm.lstMessage.Items.Add(ex.Message);
                    }
                }
                else
                {
                    MessageBox.Show("请选择图片!");
                }//if image
            }//if funcNo
        }
Example #2
0
 public Crawler()
 {
     sina = OAuther.getOAuth();
     if (sina == null)
     {
         return;
     }
     Console.WriteLine("=== Crawler Initlization Over ===");
 }
Example #3
0
        private void toolComment_Click(object sender, EventArgs e)
        {
            try
            {
                NetDimension.Weibo.Client Client=new NetDimension.Weibo.Client(Authorize.oauth);
                NetDimension.Weibo.Interface.Dynamic.CommentInterface comment = new NetDimension.Weibo.Interface.Dynamic.CommentInterface(Client);
                comment.Create(status.id, txtComment.Text );
                MainForm.lstMessage.Items.Insert(0, "评论成功!" + DateTime.Now.ToString());

            }
            catch (Exception ex)
            {
                MainForm.lstMessage.Items.Insert(0, ex.Message + DateTime.Now.ToString());
            }
        }
Example #4
0
 private void btnGetAllWeiBoUsers_Click(object sender, EventArgs e)
 {
     var Srv = SystemManager.GetCurrentServer();
     if (Srv != null)
     {
         var db = Srv.GetDatabase("SinaWeibo");
         var col = db.GetCollection("User");
         var oauth = new NetDimension.Weibo.OAuth(txtAppKey.Text, txtAppSrect.Text);
         bool result = oauth.ClientLogin(txtWeiBoUsr.Text, txtWeiBoPsw.Text);
         if (result) //返回true成功
         {
             var Sina = new NetDimension.Weibo.Client(oauth);
             var uid = Sina.API.Account.GetUID();
             GetUser(col, Sina, uid);
         }
     }
     MessageBox.Show("OK");
 }
Example #5
0
        //抓取官方微薄最新消息,我是it刘账号
        public ActionResult WeiBoAPI()
        {
            //sina授权的实例化
            var oauth = new NetDimension.Weibo.OAuth("3472401107", "21338ee3f6c6ff661945974ee2d0b2de", "http://127.0.0.1/NewLifeScan");
            //access token 授权
            var    result      = oauth.ClientLogin("13851488992", "851211");
            string AccessToken = oauth.AccessToken; //还是来打印下AccessToken

            var Sina = new NetDimension.Weibo.Client(oauth);
            var uid  = Sina.API.Dynamic.Account.GetUID(); //调用API中获取UID的方法
            //   var NearestNews = Sina.API.Dynamic.Statuses.UserTimeline("1897719834","刘彦玮", "", "", 1, 1, true, 0);
            var NearestNews = Sina.API.Dynamic.Statuses.FriendsTimelineIDs();

            //weibo.com/u/2709878972


            //传递数据
            ViewBag.AccessToken = AccessToken;
            ViewBag.weiboResult = uid;
            ViewBag.NearestNews = NearestNews;
            ViewBag.MentionIDs  = Sina.API.Dynamic.Statuses.MentionIDs();
            ViewBag.Mentions    = Sina.API.Dynamic.Statuses.Mentions();

            //获取朋友发的微博数据
            //测试地址:https://api.weibo.com/2/statuses/home_timeline.json?appkey=3472401107&&access_token=2.00z5kqwDTJqzmDeae65e57f77ge13E

            var HomeTimeline = Sina.API.Entity.Statuses;//获取用户发布的微薄列表

            ViewBag.User = uid;
            //  ViewBag.test = HomeTimeline.Statuses.ToList();
            ViewBag.UserTimeline = HomeTimeline;
            //from c in HomeTimeline.Statuses.ToList()
            //                   select new
            //                   {
            //                       c.User,
            //                       c.Text,
            //                       c.Source
            //                   };


            return(View());
        }
Example #6
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);
        }
Example #7
0
        private void btnGetFollowers_Click(object sender, EventArgs e)
        {
            var Srv = SystemManager.GetCurrentServer();
            if (Srv != null)
            {
                var db = Srv.GetDatabase("SinaWeibo");
                var oauth = new NetDimension.Weibo.OAuth(txtAppKey.Text, txtAppSrect.Text);
                bool result = oauth.ClientLogin(txtWeiBoUsr.Text, txtWeiBoPsw.Text);
                if (result) //返回true成功
                {
                    var Sina = new NetDimension.Weibo.Client(oauth);
                    var uid = Sina.API.Account.GetUID();
                    var col = db.GetCollection(txtSupperStarID.Text + txtSupperStarName.Text + "(Followers)");
                    int UserCount;
                    int TotalCount;
                    UserCount = 0;
                    TotalCount = 0;

                    NetDimension.Weibo.Entities.user.Collection followers;
                    do
                    {
                        followers = Sina.API.Friendships.Followers(txtSupperStarID.Text, "", 150, UserCount, true);
                        if (TotalCount == 0)
                        {
                            TotalCount = followers.TotalNumber;
                        }
                        foreach (var follow in followers.Users)
                        {
                            col.Insert(follow);
                            UserCount++;
                        }
                    } while (UserCount < TotalCount);
                    MessageBox.Show("OK");
                }
            }
            else {
                MessageBox.Show("MongoDB Not Found");
            }
        }
Example #8
0
        //抓取官方微薄最新消息,sensitive账号
        public ActionResult WeiBoAPI1()
        {
            //sina授权的实例化
            var oauth = new NetDimension.Weibo.OAuth("2371575470", "4b03b21f941c30c091e995f63d7e5103", "http://127.0.0.1/NewLifeScan/home/WeiBoAPI");
            //access token 授权
            var    result      = oauth.ClientLogin("*****@*****.**", "weiZIPP1");
            string AccessToken = oauth.AccessToken; //还是来打印下AccessToken

            var Sina = new NetDimension.Weibo.Client(oauth);
            var uid  = Sina.API.Dynamic.Account.GetUID(); //调用API中获取UID的方法
            //   var NearestNews = Sina.API.Dynamic.Statuses.UserTimeline("1897719834","刘彦玮", "", "", 1, 1, true, 0);
            var NearestNews = Sina.API.Dynamic.Statuses.FriendsTimelineIDs();

            //weibo.com/u/2709878972


            //传递数据
            ViewBag.AccessToken  = AccessToken;
            ViewBag.weiboResult  = uid;
            ViewBag.NearestNews  = NearestNews;
            ViewBag.MentionIDs   = Sina.API.Dynamic.Statuses.MentionIDs();
            ViewBag.Mentions     = Sina.API.Dynamic.Statuses.Mentions();
            ViewBag.UserTimeline = Sina.API.Dynamic.Statuses.UserTimeline();//获取用户发布的微薄列表
            var UserTimeline = Sina.API.Dynamic.Statuses.UserTimeline();


            var TILELINE = Sina.API.Entity.Statuses.UserTimeline();

            ViewBag.firstText = TILELINE.Statuses.First().Text;

            //据说通过审核后可以使用功能,坐等
            //参考网址http://open.weibo.com/qa/index.php?qa=17410&qa_1=statuses-user_timeline%E5%8D%87%E7%BA%A7%E5%90%8E%E5%8F%AA%E8%83%BD%E8%AF%B7%E6%B1%82%E5%BD%93%E5%89%8D%E6%8E%88%E6%9D%83%E7%94%A8%E6%88%B7%E4%BF%A1%E6%81%AF
            //    var lifescanWeibo = Sina.API.Entity.Statuses.UserTimeline("2642246987");
            //   ViewBag.lifescanWeibo = lifescanWeibo.Statuses.FirstOrDefault().Text;

            ViewBag.test = "";

            return(View());
        }
Example #9
0
 public Crawler()
 {
     sina = OAuther.getOAuth();
     if (sina == null) return;
     Console.WriteLine("=== Crawler Initlization Over ===");
 }
Example #10
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";
            }
        }
Example #11
0
 private void btnGetMyFriendsAndFollowers_Click(object sender, EventArgs e)
 {
     var Srv = SystemManager.GetCurrentServer();
     if (Srv != null)
     {
         var db = Srv.GetDatabase("SinaWeibo");
         var oauth = new NetDimension.Weibo.OAuth(txtAppKey.Text, txtAppSrect.Text);
         bool result = oauth.ClientLogin(txtWeiBoUsr.Text, txtWeiBoPsw.Text);
         if (result) //返回true成功
         {
             var Sina = new NetDimension.Weibo.Client(oauth);
             var uid = Sina.API.Account.GetUID();
             var friends = Sina.API.Friendships.Friends(uid);
             foreach (var friend in friends.Users)
             {
                 var col = db.GetCollection("MyFriends");
                 col.Insert(friend);
             }
             var followers = Sina.API.Friendships.Followers(uid);
             foreach (var follow in followers.Users)
             {
                 var col = db.GetCollection("MyFollowers");
                 col.Insert(follow);
             }
         }
     }
     MessageBox.Show("OK");
 }
Example #12
0
        public ReturnValue<USR_CustomerMaintain> WeiboLoginAlt(string token, long expires)
        {
            //新浪微博回调
            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 uid = "";
            if (!string.IsNullOrEmpty(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 = token;
            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);
        }
Example #13
0
        public ReturnValue <USR_CustomerMaintain> WeiboLoginAlt(string token, long expires)
        {
            //新浪微博回调
            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     uid   = "";

            if (!string.IsNullOrEmpty(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 = token;
            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));
        }
Example #14
0
 public frmChat(NetDimension.Weibo.OAuth oauth)
 {
     InitializeComponent();
     this.oauth = oauth;
     Sina       = new NetDimension.Weibo.Client(oauth);
 }
Example #15
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");
        }
Example #16
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";
            }
        }
Example #17
0
 public frmChat(NetDimension.Weibo.OAuth oauth)
 {
     InitializeComponent();
     this.oauth = oauth;
     Sina = new NetDimension.Weibo.Client(oauth);
 }