Ejemplo n.º 1
0
        /// <summary>
        /// 取授权登录URL
        /// </summary>
        /// <returns>登录URL</returns>
        public string GetAuthUrl()
        {
            List <UrlParameter> param = new List <UrlParameter>();

            param.Add(new UrlParameter("oauth_consumer_key", config.AppKey));
            param.Add(new UrlParameter("oauth_nonce", OAuthCommon.GetGUID32()));
            param.Add(new UrlParameter("oauth_signature_method", "HMAC-SHA1"));
            param.Add(new UrlParameter("oauth_timestamp", OAuthCommon.GetTimestamp()));
            param.Add(new UrlParameter("oauth_version", "1.0"));
            param.Sort(new UrlParameterCompre());

            StringBuilder sbSign = new StringBuilder().Append("GET&")
                                   .Append(request_token.UrlEncode2())
                                   .Append("&")
                                   .Append(OAuthCommon.GetUrlParameter(param).UrlEncode2());

            param.Add(new UrlParameter("oauth_signature", OAuthCommon.GetHMACSHA1(config.AppSecret, "", sbSign.ToString()).UrlEncode2()));
            param.Sort(new UrlParameterCompre());
            string data = HttpHelper.SendGet(new StringBuilder().Append(request_token).Append("?").Append(OAuthCommon.GetUrlParameter(param)).ToString());

            int    intOTS             = data.IndexOf("oauth_token=");
            int    intOTSS            = data.IndexOf("&oauth_token_secret=");
            string oauth_token        = data.Substring(intOTS + 12, intOTSS - (intOTS + 12));
            string oauth_token_secret = data.Substring((intOTSS + 20), data.Length - (intOTSS + 20));

            Session2.Set("oauth_token", oauth_token);
            Session2.Set("oauth_token_secret", oauth_token_secret);
            return(authorize + "?oauth_token=" + oauth_token + "&oauth_callback=" + config.RedirectUrl);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 取授权登录URL
        /// </summary>
        /// <returns>登录URL</returns>
        public string GetAuthUrl()
        {
            //http://wiki.open.kaixin001.com/index.php?id=OAuth%e6%96%87%e6%a1%a3
            List <UrlParameter> param = new List <UrlParameter>();

            param.Add(new UrlParameter("oauth_callback", config.RedirectUrl.UrlEncode2()));
            param.Add(new UrlParameter("oauth_consumer_key", config.AppKey));
            param.Add(new UrlParameter("oauth_nonce", OAuthCommon.GetGUID32()));
            param.Add(new UrlParameter("oauth_signature_method", "HMAC-SHA1"));
            param.Add(new UrlParameter("oauth_timestamp", OAuthCommon.GetTimestamp()));
            param.Add(new UrlParameter("oauth_version", "1.0"));
            param.Add(new UrlParameter("scope", "create_records"));
            param.Sort(new UrlParameterCompre());

            StringBuilder sbSign = new StringBuilder().Append("GET&")
                                   .Append(request_token.UrlEncode2())
                                   .Append("&")
                                   .Append(OAuthCommon.GetUrlParameter(param).UrlEncode2());

            param.Add(new UrlParameter("oauth_signature", OAuthCommon.GetHMACSHA1(config.AppSecret, "", sbSign.ToString()).UrlEncode2()));
            param.Sort(new UrlParameterCompre());

            string data = HttpHelper.SendGet(new StringBuilder().Append(request_token).Append("?").Append(OAuthCommon.GetUrlParameter(param)).ToString());

            string token       = data.GetMatchingValues("oauth_token=(.+?)&", "oauth_token=", "&").FirstOrDefault() ?? "";
            string tokenSecret = data.GetMatchingValues("oauth_token_secret=(.+?)&", "oauth_token_secret=", "&").FirstOrDefault() ?? "";

            Session2.Set("oauth_token", token);
            Session2.Set("oauth_token_secret", tokenSecret);
            return(authorize + "?oauth_token=" + token);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 取授权登录URL
        /// </summary>
        /// <returns>登录URL</returns>
        public string GetAuthUrl()
        {
            List <UrlParameter> param = new List <UrlParameter>();

            param.Add(new UrlParameter("oauth_consumer_key", config.AppKey));
            param.Add(new UrlParameter("oauth_nonce", OAuthCommon.GetGUID32()));
            param.Add(new UrlParameter("oauth_signature_method", "HMAC-SHA1"));
            param.Add(new UrlParameter("oauth_timestamp", OAuthCommon.GetTimestamp()));
            param.Add(new UrlParameter("oauth_version", "1.0"));
            param.Sort(new UrlParameterCompre());

            StringBuilder sbSign = new StringBuilder().Append("GET&")
                                   .Append(Rfc3986.Encode(request_token))
                                   .Append("&")
                                   .Append(Rfc3986.Encode(OAuthCommon.GetUrlParameter(param)));

            param.Add(new UrlParameter("oauth_signature", Rfc3986.Encode(OAuthCommon.GetHMACSHA1(Rfc3986.Encode(config.AppSecret), "", sbSign.ToString()))));
            param.Sort(new UrlParameterCompre());
            string data = HttpHelper.SendGet(new StringBuilder().Append(request_token).Append("?").Append(OAuthCommon.GetUrlParameter(param)).ToString()) + "&";

            string token       = data.GetMatchingValues("oauth_token=(.+?)&", "oauth_token=", "&").FirstOrDefault() ?? "";
            string tokenSecret = data.GetMatchingValues("oauth_token_secret=(.+?)&", "oauth_token_secret=", "&").FirstOrDefault() ?? "";

            Session2.Set("oauth_token", token);
            Session2.Set("oauth_token_secret", tokenSecret);
            return(authorize + "?oauth_token=" + token + "&oauth_callback=" + config.RedirectUrl);
        }