コード例 #1
0
        /// <summary>
        /// 获取第三方OAuth平台用户信息
        /// response result:
        /// {
        ///    "id": 1404376560,
        ///    "screen_name": "zaku",
        ///    "name": "zaku",
        ///    "province": "11",
        ///    "city": "5",
        ///    "location": "北京 朝阳区",
        ///    "description": "人生五十年,乃如梦如幻;有生斯有死,壮士复何憾。",
        ///    "url": "http://blog.sina.com.cn/zaku",
        ///    "profile_image_url": "http://tp1.sinaimg.cn/1404376560/50/0/1",
        ///    "domain": "zaku",
        ///    "gender": "m",
        ///    "followers_count": 1204,
        ///    "friends_count": 447,
        ///    "statuses_count": 2908,
        ///    "favourites_count": 0,
        ///    "created_at": "Fri Aug 28 00:00:00 +0800 2009",
        ///    "following": false,
        ///    "allow_all_act_msg": false,
        ///    "geo_enabled": true,
        ///    "verified": false,
        ///    "status": {
        ///        "created_at": "Tue May 24 18:04:53 +0800 2011",
        ///        "id": 11142488790,
        ///        "text": "我的相机到了。",
        ///        "source": "<a href="http://weibo.com" rel="nofollow">新浪微博</a>",
        ///       "favorited": false,
        ///        "truncated": false,
        ///        "in_reply_to_status_id": "",
        ///        "in_reply_to_user_id": "",
        ///        "in_reply_to_screen_name": "",
        ///        "geo": null,
        ///        "mid": "5610221544300749636",
        ///        "annotations": [],
        ///        "reposts_count": 5,
        ///        "comments_count": 8
        ///    },
        ///    "allow_all_comment": true,
        ///    "avatar_large": "http://tp1.sinaimg.cn/1404376560/180/0/1",
        ///    "verified_reason": "",
        ///    "follow_me": false,
        ///    "online_status": 0,
        ///    "bi_followers_count": 215
        ///}
        /// </summary>
        /// <returns></returns>
        public dynamic GetUserInfo()
        {
            String responseResult = this.oauth.Get(this.oauth.Option.Urls["UserInfo"], new RequestOption()
            {
                Name = "uid", Value = this.oauth.Token.OAuthId
            });
            dynamic jsonResult = DynamicHelper.FromJSON(responseResult);

            #region //格式化基础的用户信息
            this.oauth.Token.User.OAuthId  = this.oauth.Token.OAuthId;
            this.oauth.Token.User.Nickname = jsonResult.screen_name;

            IDictionary <String, String> sexMaps = new Dictionary <String, String>();
            sexMaps["f"] = "0"; //女
            sexMaps["m"] = "1"; //男
            sexMaps["n"] = "2"; //保密
            this.oauth.Token.User.Sex         = sexMaps[jsonResult.gender];
            this.oauth.Token.User.Description = jsonResult.description;
            #endregion

            //debug
            this.oauth.Token.TraceInfo = responseResult;

            return(jsonResult);
        }
コード例 #2
0
        /// <summary>
        /// 提取腾讯QQ第三方OAuth平台返回的json数据
        /// </summary>
        /// <param name="responseText"></param>
        /// <returns></returns>
        private dynamic GetResponseJsonData(String responseText)
        {
            Regex  reg      = new Regex("^callback[(](?<data>.*?)[);]+$", RegexOptions.IgnoreCase);
            Match  match    = reg.Match(responseText.Trim());
            String jsonText = match.Groups["data"].Value;

            return(DynamicHelper.FromJSON(jsonText));
        }
コード例 #3
0
        /// <summary>
        /// 获取第三方OAuth平台用户信息
        /// </summary>
        /// <returns></returns>
        public dynamic GetUserInfo()
        {
            String  responseResult = "{\"uid\":\"" + this.oauth.Token.User.OAuthId + "\",\"nick\":\"" + this.oauth.Token.User.Nickname + "\",\"sex\":" + "\"n\"}";
            dynamic resultData     = DynamicHelper.FromJSON(responseResult);

            //debug
            this.oauth.Token.TraceInfo = responseResult;

            return(resultData);
        }
コード例 #4
0
        /// <summary>
        /// 解析访问令牌
        /// </summary>
        /// <param name="responseResult"></param>
        protected override void ParseAccessToken(String responseResult)
        {
            //解析新浪微博授权令牌数据
            dynamic resultData = DynamicHelper.FromJSON(responseResult);

            this.Token.AccessToken = resultData.access_token;
            this.Token.ExpiresIn   = (int)resultData.expires_in;
            this.Token.OAuthId     = resultData.uid;

            //debug
            this.Token.TraceInfo = responseResult;
        }
コード例 #5
0
        /// <summary>
        /// 解析访问令牌
        /// response result:
        /// {
        ///   "w2_expires_in": 1800,
        ///   "taobao_user_id": "1826171524",
        ///   "taobao_user_nick": "sanxia_330",
        ///   "w1_expires_in": 86400,
        ///   "re_expires_in": 86400,
        ///   "r2_expires_in": 86400,
        ///   "expires_in": 86400,
        ///   "token_type": "Bearer",
        ///   "refresh_token": "6200522427d9e19e6029540fcc151dfh16c46b3de3a463b1826171524",
        ///   "access_token": "6201522a5dca536dfff594c7fa04bdfh3c4616011106a061826171524",
        ///   "r1_expires_in": 86400
        /// }
        /// </summary>
        /// <param name="responseResult"></param>
        protected override void ParseAccessToken(String responseResult)
        {
            //解析新浪微博授权令牌数据
            dynamic resultData = DynamicHelper.FromJSON(responseResult);

            this.Token.AccessToken  = resultData.access_token;
            this.Token.ExpiresIn    = (int)resultData.expires_in;
            this.Token.RefreshToken = resultData.refresh_token;
            this.Token.ReExpiresIn  = (int)resultData.re_expires_in;
            this.Token.OAuthId      = resultData.taobao_user_id;

            this.Token.User.OAuthId  = resultData.taobao_user_id;
            this.Token.User.Nickname = resultData.taobao_user_nick;

            //debug
            this.Token.TraceInfo = responseResult;
        }
コード例 #6
0
        /// <summary>
        /// 获取第三方OAuth平台用户信息
        /// response result:
        ///{
        ///"ret":0,
        ///"msg":"",
        ///"nickname":"Peter",
        ///"figureurl":"http://qzapp.qlogo.cn/qzapp/111111/942FEA70050EEAFBD4DCE2C1FC775E56/30",
        ///"figureurl_1":"http://qzapp.qlogo.cn/qzapp/111111/942FEA70050EEAFBD4DCE2C1FC775E56/50",
        ///"figureurl_2":"http://qzapp.qlogo.cn/qzapp/111111/942FEA70050EEAFBD4DCE2C1FC775E56/100",
        ///"figureurl_qq_1":"http://q.qlogo.cn/qqapp/100312990/DE1931D5330620DBD07FB4A5422917B6/40",
        ///"figureurl_qq_2":"http://q.qlogo.cn/qqapp/100312990/DE1931D5330620DBD07FB4A5422917B6/100",
        ///"gender":"男",
        ///"is_yellow_vip":"1",
        ///"vip":"1",
        ///"yellow_vip_level":"7",
        ///"level":"7",
        ///"is_yellow_year_vip":"1"
        ///}
        /// </summary>
        /// <returns></returns>
        public dynamic GetUserInfo()
        {
            String  responseResult = this.oauth.Get(this.oauth.Option.Urls["UserInfo"]);
            dynamic jsonResult     = DynamicHelper.FromJSON(responseResult);

            #region //格式化基础的用户信息
            this.oauth.Token.User.OAuthId  = this.oauth.Token.OAuthId;
            this.oauth.Token.User.Nickname = jsonResult.nickname;

            IDictionary <String, String> sexMaps = new Dictionary <String, String>();
            sexMaps["女"] = "0"; //女
            sexMaps["男"] = "1"; //男
            this.oauth.Token.User.Sex         = sexMaps[jsonResult.gender];
            this.oauth.Token.User.Description = jsonResult.description;
            #endregion

            //debug
            this.oauth.Token.TraceInfo = responseResult;

            return(jsonResult);
        }