コード例 #1
0
        /// <summary>
        /// 取登录账号信息
        /// </summary>
        /// <returns>取登录账号信息</returns>
        public UserInfo GetUserInfo()
        {
            UserInfo user    = new UserInfo();
            string   openid  = Request2.GetQ("openid");
            string   openkey = Request2.GetQ("openkey");

            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_token", Request2.GetQ("oauth_token")));
            param.Add(new UrlParameter("oauth_verifier", Request2.GetQ("oauth_verifier")));
            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(access_token.UrlEncode2())
                                   .Append("&")
                                   .Append(OAuthCommon.GetUrlParameter(param).UrlEncode2());

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

            user.Token  = data.GetMatchingValues("oauth_token=(.+?)&", "oauth_token=", "&").FirstOrDefault() ?? "";
            user.Secret = data.GetMatchingValues("oauth_token_secret=(.+?)&", "oauth_token_secret=", "&").FirstOrDefault() ?? "";

            param.Clear();
            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_token", user.Token));
            param.Add(new UrlParameter("oauth_version", "1.0"));
            //param.Add(new UrlParameter("scope", "create_records"));
            param.Sort(new UrlParameterCompre());

            StringBuilder sbSign2 = new StringBuilder().Append("GET&")
                                    .Append(user_info.UrlEncode2())
                                    .Append("&")
                                    .Append(OAuthCommon.GetUrlParameter(param).UrlEncode2());

            param.Add(new UrlParameter("oauth_signature", OAuthCommon.GetHMACSHA1(config.AppSecret, user.Secret, sbSign2.ToString()).UrlEncode2()));
            param.Sort(new UrlParameterCompre());
            data = HttpHelper.SendGet(new StringBuilder().Append(user_info).Append("?").Append(OAuthCommon.GetUrlParameter(param)).ToString());

            user.UserID = data.GetMatchingValues("\"uid\":\"(.+?)\"", "\"uid\":\"", "\"").FirstOrDefault() ?? "";
            user.Email  = data.GetMatchingValues("\"email\":\"(.+?)\"", "\"email\":\"", "\"").FirstOrDefault() ?? "";
            user.Name   = (data.GetMatchingValues("\"name\":\"(.+?)\"", "\"name\":\"", "\"").FirstOrDefault() ?? "").Ascii2Native();
            user.Sex    = (data.GetMatchingValues("\"gender\":\"(.+?)\"", "\"gender\":\"", "\"").FirstOrDefault() ?? "") == "0" ? 1 : 0;
            user.Header = data.GetMatchingValues("\"logo50\":\"(.+?)\"", "\"logo50\":\"", "\"").FirstOrDefault() ?? "";

            //{"uid":"45908241","name":"\u534e\u6625","gender":"0","logo50":"http:\/\/img.kaixin001.com.cn\/i\/50_0_0.gif"}
            //Msg.WriteEnd(GetFriendsInfo(user.Token, user.Secret).ToJson());
            //SendText(user.Token, user.Secret, "测试数据");
            return(user);
        }
コード例 #2
0
        /// <summary>
        /// 取登录账号信息
        /// </summary>
        /// <returns>取登录账号信息</returns>
        public UserInfo GetUserInfo()
        {
            UserInfo user    = new UserInfo();
            string   openid  = Request2.GetQ("openid");
            string   openkey = Request2.GetQ("openkey");

            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_token", Request2.GetQ("oauth_token")));
            param.Add(new UrlParameter("oauth_verifier", Request2.GetQ("oauth_verifier")));
            param.Add(new UrlParameter("oauth_version", "1.0"));
            param.Sort(new UrlParameterCompre());

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

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

            int intOTS  = data.IndexOf("oauth_token=");
            int intOTSS = data.IndexOf("&oauth_token_secret=");
            int intUser = data.IndexOf("&user_id=");

            user.Token  = data.Substring(intOTS + 12, intOTSS - (intOTS + 12));
            user.Secret = data.Substring((intOTSS + 20), intUser - (intOTSS + 20));
            user.UserID = data.Substring((intUser + 9), data.Length - (intUser + 9));

            param.Clear();
            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_token", user.Token));
            param.Add(new UrlParameter("oauth_version", "1.0"));
            param.Sort(new UrlParameterCompre());

            StringBuilder sbSign2 = new StringBuilder().Append("GET&")
                                    .Append(user_info.UrlEncode2())
                                    .Append("&")
                                    .Append(OAuthCommon.GetUrlParameter(param).UrlEncode2());

            param.Add(new UrlParameter("oauth_signature", OAuthCommon.GetHMACSHA1(config.AppSecret, user.Secret, sbSign2.ToString()).UrlEncode2()));
            param.Sort(new UrlParameterCompre());
            data = HttpHelper.SendGet(new StringBuilder().Append(user_info).Append("?").Append(OAuthCommon.GetUrlParameter(param)).ToString());

            user.Name    = data.GetMatchingValues("<name>(.+?)</name>", "<name>", "</name>").FirstOrDefault() ?? "";
            user.Header  = data.GetMatchingValues("<profile_image_url>(.+?)</profile_image_url>", "<profile_image_url>", "</profile_image_url>").FirstOrDefault() ?? "";
            user.Sex     = (data.GetMatchingValues("<gender>(.+?)</gender>", "<gender>", "</gender>").FirstOrDefault() ?? "").ToLower().Equals("m") ? 1 : 0;
            user.Address = data.GetMatchingValues("<location>(.+?)</location>", "<location>", "</location>").FirstOrDefault() ?? "";

            //Msg.Write(GetFriendsInfo(user.Token, user.Secret).ToJson());
            //SendText(user.Token, user.Secret, "测试数据2");
            return(user);
        }
コード例 #3
0
ファイル: SohuOAuth.cs プロジェクト: AdvanceEnemy/pub.class
        /// <summary>
        /// 取登录账号信息
        /// </summary>
        /// <returns>取登录账号信息</returns>
        public UserInfo GetUserInfo()
        {
            UserInfo user = new UserInfo();

            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_token", Request2.GetQ("oauth_token")));
            param.Add(new UrlParameter("oauth_verifier", Request2.GetQ("oauth_verifier")));
            param.Add(new UrlParameter("oauth_version", "1.0"));
            param.Sort(new UrlParameterCompre());

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

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

            user.Token  = data.GetMatchingValues("oauth_token=(.+?)&", "oauth_token=", "&").FirstOrDefault() ?? "";
            user.Secret = data.GetMatchingValues("oauth_token_secret=(.+?)&", "oauth_token_secret=", "&").FirstOrDefault() ?? "";

            param.Clear();
            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_token", user.Token));
            param.Add(new UrlParameter("oauth_version", "1.0"));
            param.Sort(new UrlParameterCompre());

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

            param.Add(new UrlParameter("oauth_signature", Rfc3986.Encode(OAuthCommon.GetHMACSHA1(Rfc3986.Encode(config.AppSecret), Rfc3986.Encode(user.Secret), sbSign2.ToString()))));
            param.Sort(new UrlParameterCompre());
            data = HttpHelper.SendGet(new StringBuilder().Append(user_info).Append("?").Append(OAuthCommon.GetUrlParameter(param)).ToString());

            user.UserID  = data.GetMatchingValues("\"id\":\"(.+?)\"", "\"id\":\"", "\"").FirstOrDefault() ?? "";
            user.Email   = data.GetMatchingValues("\"email\":\"(.+?)\"", "\"email\":\"", "\"").FirstOrDefault() ?? "";
            user.Name    = data.GetMatchingValues("\"screen_name\":\"(.+?)\"", "\"screen_name\":\"", "\"").FirstOrDefault() ?? "";
            user.Sex     = (data.GetMatchingValues("\"gender\":\"(.+?)\"", "\"gender\":\"", "\"").FirstOrDefault() ?? "") == "1" ? 1 : 0;
            user.Header  = data.GetMatchingValues("\"profile_image_url\":\"(.+?)\"", "\"profile_image_url\":\"", "\"").FirstOrDefault() ?? "";
            user.Address = data.GetMatchingValues("\"location\":\"(.+?)\"", "\"location\":\"", "\"").FirstOrDefault() ?? "";

            //{"id":"268563401","screen_name":"livexy","name":"","location":"上海市,徐汇区","description":"","url":"","gender":"0",
            //"profile_image_url":"http://s4.cr.itc.cn/img/t/avt_48.jpg","protected":true,"followers_count":1,"profile_background_color":"",
            //"profile_text_color":"","profile_link_color":"","profile_sidebar_fill_color":"","profile_sidebar_border_color":"","friends_count":7,
            //"created_at":"Fri Dec 02 13:26:29 +0800 2011","favourites_count":0,"utc_offset":"","time_zone":"","profile_background_image_url":"",
            //"notifications":"","geo_enabled":false,"statuses_count":0,"following":true,"verified":false,"lang":"zh_cn","contributors_enabled":false}
            //Msg.Write(GetFriendsInfo(user.Token, user.Secret).ToJson());
            //SendText(user.Token, user.Secret, "测试数据2");
            return(user);
        }
コード例 #4
0
ファイル: QQOAuth.cs プロジェクト: AdvanceEnemy/pub.class
        /// <summary>
        /// 取登录账号信息
        /// </summary>
        /// <returns>取登录账号信息</returns>
        public UserInfo GetUserInfo()
        {
            UserInfo user    = new UserInfo();
            string   openid  = Request2.GetQ("openid");
            string   openkey = Request2.GetQ("openkey");

            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_token", Request2.GetQ("oauth_token")));
            param.Add(new UrlParameter("oauth_verifier", Request2.GetQ("oauth_verifier")));
            param.Add(new UrlParameter("oauth_version", "1.0"));
            param.Sort(new UrlParameterCompre());

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

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

            user.Token  = data.GetMatchingValues("oauth_token=(.+?)&", "oauth_token=", "&").FirstOrDefault() ?? "";
            user.Secret = data.GetMatchingValues("oauth_token_secret=(.+?)&", "oauth_token_secret=", "&").FirstOrDefault() ?? "";
            user.UserID = data.Substring(data.IndexOf("&name=") + 6);

            param.Clear();
            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_token", user.Token));
            param.Add(new UrlParameter("oauth_version", "1.0"));
            param.Add(new UrlParameter("format", "json"));
            param.Sort(new UrlParameterCompre());

            StringBuilder sbSign2 = new StringBuilder().Append("GET&")
                                    .Append(user_info.UrlEncode2())
                                    .Append("&")
                                    .Append(OAuthCommon.GetUrlParameter(param).UrlEncode2());

            param.Add(new UrlParameter("oauth_signature", OAuthCommon.GetHMACSHA1(config.AppSecret, user.Secret, sbSign2.ToString()).UrlEncode2()));
            param.Sort(new UrlParameterCompre());
            data = HttpHelper.SendGet(new StringBuilder().Append(user_info).Append("?").Append(OAuthCommon.GetUrlParameter(param)).ToString());

            user.Email   = data.GetMatchingValues("\"email\":\"(.+?)\"", "\"email\":\"", "\"").FirstOrDefault() ?? "";
            user.Name    = data.GetMatchingValues("\"nick\":\"(.+?)\"", "\"nick\":\"", "\"").FirstOrDefault() ?? "";
            user.Sex     = (data.GetMatchingValues("\"sex\":(.+?),", "\"sex\":", ",").FirstOrDefault() ?? "") == "1" ? 1 : 0;
            user.Address = data.GetMatchingValues("\"location\":\"(.+?)\"", "\"location\":\"", "\"").FirstOrDefault() ?? "";

            //{"data":{"birth_day":31,"birth_month":3,"birth_year":1984,"city_code":"9","country_code":"1","edu":null,"email":"*****@*****.**",
            //"fansnum":59,"head":"","idolnum":25,"introduction":"","isent":0,"isvip":0,"location":"未知","name":"cexo255","nick":"熊","openid":"",
            //"province_code":"31","sex":1,"tag":null,"tweetnum":40,"verifyinfo":""},"errcode":0,"msg":"ok","ret":0}
            //Msg.WriteEnd(GetFriendsInfo(user.Token, user.Secret).ToJson());
            return(user);
        }
コード例 #5
0
        /// <summary>
        /// 取登录账号信息
        /// </summary>
        /// <returns>取登录账号信息</returns>
        public UserInfo GetUserInfo()
        {
            UserInfo user = new UserInfo();

            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_token", Request2.GetQ("oauth_token")));
            param.Add(new UrlParameter("oauth_verifier", Request2.GetQ("oauth_verifier")));
            param.Add(new UrlParameter("oauth_version", "1.0"));
            param.Sort(new UrlParameterCompre());

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

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

            user.Token  = data.GetMatchingValues("oauth_token=(.+?)&", "oauth_token=", "&").FirstOrDefault() ?? "";
            user.Secret = data.GetMatchingValues("oauth_token_secret=(.+?)&", "oauth_token_secret=", "&").FirstOrDefault() ?? "";

            param.Clear();
            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_token", user.Token));
            param.Add(new UrlParameter("oauth_version", "1.0"));
            param.Sort(new UrlParameterCompre());

            StringBuilder sbSign2 = new StringBuilder().Append("GET&")
                                    .Append(user_info.UrlEncode2())
                                    .Append("&")
                                    .Append(OAuthCommon.GetUrlParameter(param).UrlEncode2());

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

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

            user.UserID  = data.GetMatchingValues("\"id\":\"(.+?)\"", "\"id\":\"", "\"").FirstOrDefault() ?? "";
            user.Email   = data.GetMatchingValues("\"email\":\"(.+?)\"", "\"email\":\"", "\"").FirstOrDefault() ?? "";
            user.Name    = data.GetMatchingValues("\"name\":\"(.+?)\"", "\"name\":\"", "\"").FirstOrDefault() ?? "";
            user.Sex     = (data.GetMatchingValues("\"gender\":\"(.+?)\"", "\"gender\":\"", "\"").FirstOrDefault() ?? "") == "1" ? 1 : 0;
            user.Header  = data.GetMatchingValues("\"profile_image_url\":\"(.+?)\"", "\"profile_image_url\":\"", "\"").FirstOrDefault() ?? "";
            user.Address = data.GetMatchingValues("\"location\":\"(.+?)\"", "\"location\":\"", "\"").FirstOrDefault() ?? "";

            //{"status":null,"following":false,"blocking":false,"followed_by":false,"name":"cexo255","location":"上海市,徐汇区",
            //"id":"959281886828269520","description":"","email":"*****@*****.**","gender":"0","verified":false,"url":"","screen_name":"cexo255",
            //"profile_image_url":"http://oimagea3.ydstatic.com/image?w=48&h=48&url=http%3A%2F%2Fimg1.cache.netease.com%2Ft%2Fimg%2Fdefault80.png",
            //"created_at":"Wed Apr 21 13:19:53 +0800 2010","darenRec":null,"favourites_count":"0","followers_count":"0","friends_count":"0",
            //"geo_enable":false,"icorp":"0","realName":null,"statuses_count":"0","sysTag":null,"userTag":null,"in_groups":[]}
            //Msg.Write(GetFriendsInfo(user.Token, user.Secret).ToJson());
            //SendText(user.Token, user.Secret, "测试数据2");
            return(user);
        }