Пример #1
0
 //2.获取Token
 #region 获取Token
 /// <summary>
 /// 获取Token
 /// </summary>
 /// <param name="code">调用authorize获得的code值</param>
 /// <param name="state">成功授权后回调时会原样带回client端的状态值</param>
 /// <returns></returns>
 public string Token(string code, string state)
 {
     try
     {
         //判断client端的状态值,用于第三方应用防止CSRF攻击
         //if (State != state)
         //{
         //	return null;
         //}
         Dictionary <string, object> result = Conf.PostDictionary(TokenUrl, Conf.Sina_Client_ID, Conf.Sina_Client_Secret, Conf.Sina_Callback_URL, code);
         if (result != null && result.Count > 0)
         {
             this.Access_Token = result["access_token"].ToString();              //接口获取授权后的access token
             this.Expires_In   = long.Parse(result["expires_in"].ToString());    //access_token的生命周期,单位是秒数
             this.UID          = long.Parse(result["uid"].ToString());           //当前授权用户的UID
         }
         return(this.Access_Token);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Пример #2
0
        //4.获取用户详细信息
        #region 请求参数

        /*
         * 返回字段说明
         * 字段	            类型及范围	    说明
         * uid	            long	        被查询用户id
         * name	        string	        用户名称
         * gender	        int	            性别:1-男,2-女
         * province	    string	        省份
         * city	        string	        城市
         * platforms	    array	        开发平台
         * expertise	    array	        专长领域
         * joinTime	    datetime	    加入时间
         * lastLoginTime	datetime	    最近登录时间
         * portrait	    string	        头像
         * fansCount	    string	        粉丝数
         * favoriteCount	string	        收藏数
         * followersCount	string	        关注数
         * notice.replyCount	int	        未读评论数
         * notice.msgCount	int	            未读留言数
         * notice.fansCount	int	        新增粉丝数
         * notice.referCount	int	        未读@我数
         */

        #endregion

        #region 获取用户详细信息
        /// <summary>
        /// 获取用户详细信息
        /// </summary>
        /// <returns></returns>
        public Dictionary <string, object> GetUserDetailInfo()
        {
            try
            {
                Dictionary <string, object> result = Conf.GetDictionary(UserDetailInfoUrl, Access_Token, "json");
                string json = result["notice"].ToString();
                Dictionary <string, object> notice = JsonHelper.Deserialize <Dictionary <string, object> >(json);
                if (result != null && result.Count > 0)
                {
                    UserDetailInfo = new OSCUserDetailInfo()
                    {
                        uid            = long.Parse(result["uid"].ToString()),
                        name           = result["name"].ToString(),
                        gender         = int.Parse(result["gender"].ToString()),
                        province       = result["province"].ToString(),
                        city           = result["city"].ToString(),
                        platforms      = ((string [])result["platforms"]).ToArray <string>(),
                        expertise      = ((string[])result["expertise"]).ToArray <string>(),
                        joinTime       = result["joinTime"].ToString(),
                        lastLoginTime  = result["lastLoginTime"].ToString(),
                        portrait       = result["portrait"].ToString(),
                        fansCount      = result["fansCount"].ToString(),
                        favoriteCount  = result["favoriteCount"].ToString(),
                        followersCount = result["followersCount"].ToString(),
                        replyCount     = int.Parse(notice["replyCount"].ToString()),
                        msgCount       = int.Parse(notice["msgCount"].ToString()),
                        newFansCount   = int.Parse(notice["fansCount"].ToString()),
                        referCount     = int.Parse(notice["referCount"].ToString())
                    };
                }
                return(result);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Пример #3
0
 //3.获取用户信息
 #region 获取用户基本信息
 /// <summary>
 /// 获取用户基本信息
 /// </summary>
 /// <returns>用户基本信息</returns>
 public BaiduUserInfo GetUserInfo()
 {
     try
     {
         BaiduUserInfo model = null;
         Dictionary <string, object> result = Conf.GetDictionary(UserDetailInfoUrl, Access_Token, "json");
         if (result != null && result.Count > 0)
         {
             this.UID      = result["userid"].ToString();               //当前登录用户的数字ID
             this.UName    = result["username"].ToString();             //当前登录用户的用户名,值可能为空
             this.Portrait = result["portrait"].ToString();             //当前登录用户的头像
             model         = new BaiduUserInfo()
             {
                 userid         = result["userid"].ToString(),         //当前登录用户的数字ID
                 username       = result["username"].ToString(),       //当前登录用户的用户名,值可能为空
                 blood          = result["blood"].ToString(),          //血型
                 figure         = result["figure"].ToString(),         //体型
                 portrait       = result["portrait"].ToString(),       //当前登录用户的头像
                 birthday       = result["birthday"].ToString(),       //生日,以yyyy-mm-dd格式显示
                 marriage       = result["marriage"].ToString(),       //婚姻状况
                 sex            = result["sex"].ToString(),            //性别
                 constellation  = result["constellation"].ToString(),  //星座
                 education      = result["education"].ToString(),      //学历
                 trade          = result["trade"].ToString(),          //当前职业
                 is_bind_mobile = result["is_bind_mobile"].ToString(),
                 job            = result["job"].ToString()             //职位
             };
             this.UserInfo = model;
         }
         return(model);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }