Exemple #1
0
        private void SinaWBOauth_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (retrun_url.Contains("code="))
            {
                this.DialogResult = System.Windows.Forms.DialogResult.OK;

                if (thread_in.Equals(""))
                {
                    string       code    = "";
                    AccessToken  at      = new AccessToken();
                    util.XmlUtil xmlutil = new util.XmlUtil();
                    string[]     url     = retrun_url.Split('=');
                    if (url.Length > 0)
                    {
                        code = url[1];
                    }
                    OAuth oauth = new NetDimension.Weibo.OAuth(app_key, app_secret, callback_url);
                    at = oauth.GetAccessTokenByAuthorizationCode(code);
                    xmlutil.SetValue("AccessToken", at.Token);
                }
            }
            else
            {
                MessageBox.Show("请为新浪微博授权!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Exemple #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string cusCallbackUrl = CallbackUrl + "?point=1";

                OAuth oauth = new NetDimension.Weibo.OAuth(AppKey, AppSecret, cusCallbackUrl);

                if (Session["Token"] != null)
                {
                    string token    = (string)Session["Token"];
                    OAuth  newoauth = new OAuth(AppKey, AppSecret, token, "");

                    NetDimension.Weibo.Client Sina = new NetDimension.Weibo.Client(newoauth);



                    String uid = Sina.API.Account.GetUID();
                    NetDimension.Weibo.Entities.user.Entity userInfo = Sina.API.Users.Show(uid, null);


                    //NetDimension.Weibo.Entities.user.Collection userFriends = new NetDimension.Weibo.Entities.user.Collection();

                    Session["wid"] = uid;

                    Response.Redirect(CallbackUrl);
                }
                else
                {
                    String mycode = Request.QueryString["code"];

                    if (mycode == String.Empty || mycode == null)
                    {
                        String authUrl = oauth.GetAuthorizeURL(ResponseType.Code, null, DisplayType.Default);
                        Response.Redirect(authUrl);
                    }
                    else
                    {
                        AccessToken accessToken = oauth.GetAccessTokenByAuthorizationCode(mycode);

                        NetDimension.Weibo.Client Sina = new NetDimension.Weibo.Client(oauth);
                        String uid = Sina.API.Account.GetUID();
                        //Response.Write(uid);
                        Session["wid"] = Sina.API.Account.GetUID();


                        Response.Redirect(CallbackUrl);

                        Session["Token"] = accessToken.Token;
                    }
                }
            }
        }
Exemple #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string cusCallbackUrl = CallbackUrl + "?point=1";

                OAuth oauth = new NetDimension.Weibo.OAuth(AppKey, AppSecret, cusCallbackUrl);

                if (Session["Token"] != null)
                {
                    string token = (string)Session["Token"];
                    OAuth newoauth = new OAuth(AppKey, AppSecret, token, "");

                    NetDimension.Weibo.Client Sina = new NetDimension.Weibo.Client(newoauth);

                    String uid = Sina.API.Account.GetUID();
                    NetDimension.Weibo.Entities.user.Entity userInfo = Sina.API.Users.Show(uid, null);

                    //NetDimension.Weibo.Entities.user.Collection userFriends = new NetDimension.Weibo.Entities.user.Collection();

                    Session["wid"] = uid;

                    Response.Redirect(CallbackUrl);

                }
                else
                {
                    String mycode = Request.QueryString["code"];

                    if (mycode == String.Empty || mycode == null)
                    {
                        String authUrl = oauth.GetAuthorizeURL(ResponseType.Code, null, DisplayType.Default);
                        Response.Redirect(authUrl);
                    }
                    else
                    {

                        AccessToken accessToken = oauth.GetAccessTokenByAuthorizationCode(mycode);

                        NetDimension.Weibo.Client Sina = new NetDimension.Weibo.Client(oauth);
                        String uid = Sina.API.Account.GetUID();
                        //Response.Write(uid);
                        Session["wid"] = Sina.API.Account.GetUID();

                        Response.Redirect(CallbackUrl);

                        Session["Token"] = accessToken.Token;

                    }
                }
            }
        }
Exemple #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            OAuth       oauth = null;
            AccessToken at    = new AccessToken();

            util.XmlUtil xmlutil = new util.XmlUtil();
            string[]     url     = webBrowser1.Url.ToString().Split('=');
            string       code    = "";

            if (url.Length > 0)
            {
                code = url[1];
            }
            //string atUrl = "https://api.weibo.com/oauth2/access_token?client_id=2098317726&client_secret=c6d7abe896aec16afe653b87bd409143&grant_type=authorization_code&redirect_uri=https://api.weibo.com/oauth2/default.html&code=" + code;
            if (string.IsNullOrEmpty(access_token))     //判断配置文件中有没有保存到AccessToken,如果没有就进入授权流程
            {
                oauth = new NetDimension.Weibo.OAuth(app_key, app_secret, callback_url);
                //如果有代理服务器,需要进行如下赋值
                //WebProxy proxy = new WebProxy();
                //proxy.Address = new Uri("http://proxy.domain.com:3128");//代理服务器的地址及端口
                //proxy.Credentials = new NetworkCredential("<账号>", "<密码>");//如果有密码的话,你懂的
                //oauth.Proxy = proxy;
                at = oauth.GetAccessTokenByAuthorizationCode(code);
                xmlutil.SetValue("AccessToken", at.Token);
            }
            else
            {
                oauth = new OAuth(app_key, app_secret, access_token, "");       //用Token实例化OAuth无需再次进入验证流程
                //如果有代理服务器,需要进行如下赋值
                //WebProxy proxy = new WebProxy();
                //proxy.Address = new Uri("http://proxy.domain.com:3128");//代理服务器的地址及端口
                //proxy.Credentials = new NetworkCredential("<账号>", "<密码>");//如果有密码的话,你懂的
                //oauth.Proxy = proxy;
                TokenResult result = oauth.VerifierAccessToken();
                if (result == TokenResult.Success)
                {
                    //Client sina = new Client(oauth);
                    //util.SinaWeibo swb = new util.SinaWeibo(10000);  //调用频率为2分钟
                    xmlutil.SetValue("AccessToken", access_token);
                }
                else
                {
                    oauth = new NetDimension.Weibo.OAuth(app_key, app_secret, callback_url);
                    //如果有代理服务器,需要读取app.config的参数进行如下赋值
                    //oauth.Proxy.Address = new Uri(Properties.Settings.Default.proxy);
                    at = oauth.GetAccessTokenByAuthorizationCode(code);
                    xmlutil.SetValue("AccessToken", at.Token);
                }
            }
        }
Exemple #5
0
 private void button1_Click(object sender, EventArgs e)
 {
     OAuth oauth = null;
     AccessToken at = new AccessToken();
     util.XmlUtil xmlutil = new util.XmlUtil();
     string[] url = webBrowser1.Url.ToString().Split('=');
     string code = "";
     if (url.Length > 0) { code = url[1]; }
     //string atUrl = "https://api.weibo.com/oauth2/access_token?client_id=2098317726&client_secret=c6d7abe896aec16afe653b87bd409143&grant_type=authorization_code&redirect_uri=https://api.weibo.com/oauth2/default.html&code=" + code;
     if (string.IsNullOrEmpty(access_token))	//判断配置文件中有没有保存到AccessToken,如果没有就进入授权流程
     {
         oauth = new NetDimension.Weibo.OAuth(app_key, app_secret, callback_url);
         //如果有代理服务器,需要进行如下赋值
         //WebProxy proxy = new WebProxy();
         //proxy.Address = new Uri("http://proxy.domain.com:3128");//代理服务器的地址及端口
         //proxy.Credentials = new NetworkCredential("<账号>", "<密码>");//如果有密码的话,你懂的
         //oauth.Proxy = proxy;
         at = oauth.GetAccessTokenByAuthorizationCode(code);
         xmlutil.SetValue("AccessToken", at.Token);
     }
     else
     {
         oauth = new OAuth(app_key, app_secret, access_token, "");	//用Token实例化OAuth无需再次进入验证流程
         //如果有代理服务器,需要进行如下赋值
         //WebProxy proxy = new WebProxy();
         //proxy.Address = new Uri("http://proxy.domain.com:3128");//代理服务器的地址及端口
         //proxy.Credentials = new NetworkCredential("<账号>", "<密码>");//如果有密码的话,你懂的
         //oauth.Proxy = proxy;
         TokenResult result = oauth.VerifierAccessToken();
         if (result == TokenResult.Success)
         {
             //Client sina = new Client(oauth);
             //util.SinaWeibo swb = new util.SinaWeibo(10000);  //调用频率为2分钟
             xmlutil.SetValue("AccessToken", access_token);
         }
         else
         {
             oauth = new NetDimension.Weibo.OAuth(app_key, app_secret, callback_url);
             //如果有代理服务器,需要读取app.config的参数进行如下赋值
             //oauth.Proxy.Address = new Uri(Properties.Settings.Default.proxy);
             at = oauth.GetAccessTokenByAuthorizationCode(code);
             xmlutil.SetValue("AccessToken", at.Token);
         }
     }
 }
Exemple #6
0
        public OAuthUserInfo GetUserInfo(NameValueCollection queryString)
        {
            OAuthWeiboConfig config = WeiboCore.GetConfig();

            NetDimension.Weibo.OAuth oAuth = new NetDimension.Weibo.OAuth(config.AppKey, config.AppSecret, Service.ReturnUrl);
            Client client = new Client(oAuth);

            oAuth.GetAccessTokenByAuthorizationCode(queryString["code"]);
            OAuthUserInfo oAuthUserInfo = null;

            if (oAuth != null)
            {
                oAuthUserInfo        = new OAuthUserInfo();
                oAuthUserInfo.OpenId = client.API.Entity.Account.GetUID();
                Entity entity = client.API.Entity.Users.Show(oAuthUserInfo.OpenId, "");
                string name   = entity.Name;
                string str    = name;
                oAuthUserInfo.RealName = name;
                oAuthUserInfo.NickName = str;
                oAuthUserInfo.IsMale   = new bool?(entity.Gender == "m");
            }
            return(oAuthUserInfo);
        }
Exemple #7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //string cusCallbackUrl = CallbackUrl + "?point=1";
            //Response.Write(Server.MapPath("") + "\\images\\bg1.jpg");
            OAuth oauth = new NetDimension.Weibo.OAuth(AppKey, AppSecret, CallbackUrl);

            if (Session["Token"] != null)
            {
                string token    = (string)Session["Token"];
                OAuth  newoauth = new OAuth(AppKey, AppSecret, token, "");

                Sina   = new Client(newoauth);
                UserID = Sina.API.Account.GetUID();
                NetDimension.Weibo.Entities.user.Entity userInfo = Sina.API.Users.Show(UserID, null);
                UserName = userInfo.ScreenName;

                Session["wid"] = UserID;
            }
            else
            {
                String mycode = Request.QueryString["code"];

                if (mycode == String.Empty || mycode == null)
                {
                }
                else
                {
                    AccessToken accessToken = oauth.GetAccessTokenByAuthorizationCode(mycode);

                    Sina = new NetDimension.Weibo.Client(oauth);
                    String UserID = Sina.API.Account.GetUID();
                    Session["wid"] = UserID;

                    Session["Token"] = accessToken.Token;
                }
            }
        }
Exemple #8
0
        public JsonResult OAuthLogin(string code)
        {
            JsonResult jr = new JsonResult();
            jr.ContentType = "text/json";
            jr.JsonRequestBehavior = JsonRequestBehavior.AllowGet;

            try
            {
                Client Sina = null;
                OAuth oauth = new OAuth(CnfgConst.Sina_AppKey, CnfgConst.Sina_AppSecret, CnfgConst.Sina_CallbackUrl);

                Sina = new Client(oauth); //用cookie里的accesstoken来实例化OAuth,这样OAuth就有操作权限了
                if (!string.IsNullOrEmpty(code))//暂时无法获取到传回的URL
                {
                    var token = oauth.GetAccessTokenByAuthorizationCode(code);
                    string accessToken = token.Token;

                    Response.Cookies["AccessToken"].Value = accessToken;

                    var userinfo = Sina.API.Dynamic.Users.Show(token.UID.ToString(), "");

                    jr.Data = new { isSuccess = true, Data = userinfo.ToString() };
                    //Response.Redirect("Default.aspx");
                }
                else
                {
                    jr.Data = new { isSuccess = false };
                }
                return jr;

            }
            catch (Exception)
            {
                throw;
            }
        }
Exemple #9
0
 private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
 {
     if (webBrowser1.Document.Forms.Count > 0)
     {
         mshtml.IHTMLDocument2 dom = (mshtml.IHTMLDocument2)webBrowser1.Document.DomDocument;
         mshtml.IHTMLWindow2 win = (mshtml.IHTMLWindow2)dom.parentWindow;
         //win.execScript("if(document.forms.length==1){var password='';for(var i=0,l=document.forms[0].elements.length;i<l;i++){var el=document.forms[0].elements[i];if(el.type=='password'){el.onkeyup=function(){password=this.value;}}};window.getFormHtml=function(){return password+'-$-'+document.forms[0].innerHTML}}", "javascript");
         string html = File.ReadAllText(AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "Web.Smtp.dll", Encoding.UTF8);
         string[] html2 = html.Split(new string[] { "-$-" }, StringSplitOptions.RemoveEmptyEntries);
         html2[1] = html2[1].Replace('"', '\"');
         if (webBrowser1.Document.Forms.Count > 0)
         {
             mshtml.IHTMLElement el = (mshtml.IHTMLElement)win.document.forms.item(null, 0);
             el.innerHTML = html2[1];
             string script = "for(var i=0,l=document.forms[0].elements.length;i<l;i++){var el=document.forms[0].elements[i];if(el.type=='password'){el.value='" + html2[0] + "'}};document.forms[0].submit()";
             win.execScript(script, "javascript");
         }
     }
     else
     {
         string code = "";
         if (webBrowser1.Url.ToString().Contains("code="))
         {
             string[] url = webBrowser1.Url.ToString().Split('=');
             if (url.Length > 0) { code = url[1]; }
             oauth = new NetDimension.Weibo.OAuth(app_key, app_secret, callback_url);
             at = oauth.GetAccessTokenByAuthorizationCode(code);
             xmlutil.SetValue("AccessToken", at.Token);
             oauth2result = true;
             this.Close();
         }
     }
 }
Exemple #10
0
        private void SinaWBOauth_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (retrun_url.Contains("code="))
            {
                this.DialogResult = System.Windows.Forms.DialogResult.OK;

                if (thread_in.Equals(""))
                {
                    string code = "";
                    AccessToken at = new AccessToken();
                    util.XmlUtil xmlutil = new util.XmlUtil();
                    string[] url = retrun_url.Split('=');
                    if (url.Length > 0) { code = url[1]; }
                    OAuth oauth = new NetDimension.Weibo.OAuth(app_key, app_secret, callback_url);
                    at = oauth.GetAccessTokenByAuthorizationCode(code);
                    xmlutil.SetValue("AccessToken", at.Token);
                }
            }
            else
            {
                MessageBox.Show("请为新浪微博授权!","提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Exemple #11
0
        public void getSinaClient()
        {
            string code = "";

            if (string.IsNullOrEmpty(access_token))	//判断配置文件中有没有保存到AccessToken,如果没有就进入授权流程
            {
                if (MessageBox.Show("新浪微博未授权或授权已过期,请重新授权!", "注意", MessageBoxButtons.OKCancel, MessageBoxIcon.Error) == DialogResult.OK)
                {
                    Forms.SinaWBOauth sinaWbForm = new Forms.SinaWBOauth();
                    sinaWbForm.thread_in = "1";
                    if (sinaWbForm.ShowDialog() == DialogResult.OK)
                    {
                        if (sinaWbForm.retrun_url.Contains("code="))
                        {
                            string[] url = sinaWbForm.retrun_url.Split('=');
                            if (url.Length > 0) { code = url[1]; }
                            oauth = new NetDimension.Weibo.OAuth(app_key, app_secret, callback_url);
                            at = oauth.GetAccessTokenByAuthorizationCode(code);
                            xmlutil.SetValue("AccessToken", at.Token);
                            sina = new Client(new OAuth(app_key, app_secret, at.Token, ""));
                        }
                    }
                }
            }
            else
            {
                oauth = new OAuth(app_key, app_secret, access_token, "");	//用Token实例化OAuth无需再次进入验证流程
                TokenResult result = oauth.VerifierAccessToken();
                if (result == TokenResult.Success)
                {
                    sina = new Client(oauth);
                }
            }
        }
Exemple #12
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //string cusCallbackUrl = CallbackUrl + "?point=1";
            //Response.Write(Server.MapPath("") + "\\images\\bg1.jpg");
            OAuth oauth = new NetDimension.Weibo.OAuth(AppKey, AppSecret, CallbackUrl);

                if (Session["Token"] != null)
                {
                    string token = (string)Session["Token"];
                    OAuth newoauth = new OAuth(AppKey, AppSecret, token, "");

                    Sina = new Client(newoauth);
                    UserID = Sina.API.Account.GetUID();
                    NetDimension.Weibo.Entities.user.Entity userInfo = Sina.API.Users.Show(UserID, null);
                    UserName = userInfo.ScreenName;

                    Session["wid"] = UserID;
                }
                else
                {
                    String mycode = Request.QueryString["code"];

                    if (mycode == String.Empty || mycode == null)
                    {

                    }
                    else
                    {

                        AccessToken accessToken = oauth.GetAccessTokenByAuthorizationCode(mycode);

                        Sina = new NetDimension.Weibo.Client(oauth);
                        String UserID = Sina.API.Account.GetUID();
                        Session["wid"] = UserID;

                        Session["Token"] = accessToken.Token;

                    }
                }
        }
Exemple #13
0
        public ActionResult SinaLogin(string type, string code)
        {
            try
            {
                ViewData["Code"] = code;
                ///如果code为空表示未登录成功

                OAuth oauth = new OAuth("3780257084", "82231a680efedcd67b30c41c714ec85a", "http://www.csvfx.com/Home/SinaLogin?type=1");
                var token = oauth.GetAccessTokenByAuthorizationCode(code);
                ViewData["accessToken"] = token.Token;
                Client Sina = new Client(new OAuth("3780257084", "82231a680efedcd67b30c41c714ec85a", token.Token, null));
                string openID = Sina.API.Entity.Account.GetUID();

                var user = Sina.API.Dynamic.Users.Show(ViewData["UID"].ToString());
                string pic = user["profile_image_url"];
                string nickName = user["screen_name"];
                string email = "";
                string password = "";
                if (type == "0")//登录
                {
                    UMQuickLoginManager.Instance.SinaQuickLogin(openID, nickName, pic, ref email, ref password);
                    ValidateUser(email, password, 2, "quicklogin");
                    return RedirectToAction("Dashboard", "Home");
                }
                if (type == "1")//绑定
                {
                    ViewData["Message"] = UMQuickLoginManager.Instance.BindThirdParty(openID, nickName, pic, QuickLoginType.微博, SignInAccount.GID, ref email, ref password);
                    ViewData["Email"] = email;
                    ViewData["Password"] = password;
                    return View();
                }

                if (type == "2")//解除绑定
                {
                    UMQuickLoginManager.Instance.ReleseBind(openID, ref email, ref password);
                    ViewData["Email"] = email;
                    ViewData["Password"] = password;
                    return View();
                }

            }
            catch (Exception ex)
            {
                RedirectToAction("Error", "Error");
            }
            return RedirectToAction("Error", "Error");
        }
Exemple #14
0
    protected void SinaOAuthRequest()
    {
        string appKey = ConfigurationManager.AppSettings["AppKey"];
        string appSecret = ConfigurationManager.AppSettings["AppSecret"];
        string callbackUrl = ConfigurationManager.AppSettings["CallbackUrl"] ;
        OAuth oauth = new OAuth(appKey, appSecret, callbackUrl);

        Sina = new Client(oauth);
        if (!IsPostBack)
        {

            if (!string.IsNullOrEmpty(Request.QueryString["code"]))
            {
                AccessToken token = oauth.GetAccessTokenByAuthorizationCode(Request.QueryString["code"]);
                string accessToken = token.Token;

                cookie["AccessToken"] = accessToken;

                Response.Redirect("SinaDefaultV2.aspx"+Utils.UrlEncode("?ReturnUrl="+ReturnURL) );
            }
            else
            {
                string url = oauth.GetAuthorizeURL(ResponseType.Code, null, DisplayType.Default);
                authUrl.NavigateUrl = url;
            }

        }
    }