예제 #1
0
        public void Info(Action <Tuple <Result, Person> > callback)
        {
            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }

            string url = String.Format(@"http://open.t.qq.com/api/user/info?" +
                                       "format=xml&access_token={0}&openid={1}&oauth_version=2.a" +
                                       "&oauth_consumer_key={2}",
                                       m_accountDetail.ACCESS_TOKEN, m_accountDetail.OPEN_ID,
                                       m_accountDetail.APP_KEY);

            HttpRequestWorker.Get(url, (content) =>
            {
                Result result = new Result();
                Person person = new Person();

                XDocument xml    = XDocument.Parse(content);
                XElement eleData = xml.Root.Element("data");
                if (eleData != null)
                {
                    person.Name     = eleData.Element("name").Value;
                    person.NickName = eleData.Element("nick").Value;
                    person.Birthday = new DateTime(
                        Convert.ToInt32(eleData.Element("birth_year").Value),
                        Convert.ToInt32(eleData.Element("birth_month").Value),
                        Convert.ToInt32(eleData.Element("birth_day").Value));
                    person.Experience    = Convert.ToInt32(eleData.Element("exp").Value);
                    person.Country       = String.IsNullOrEmpty(eleData.Element("country_code").Value) ? 0 : Convert.ToInt32(eleData.Element("country_code").Value);
                    person.Province      = String.IsNullOrEmpty(eleData.Element("province_code").Value) ? 0 : Convert.ToInt32(eleData.Element("province_code").Value);
                    person.City          = String.IsNullOrEmpty(eleData.Element("city_code").Value) ? 0 : Convert.ToInt32(eleData.Element("city_code").Value);
                    person.FansNum       = Convert.ToInt32(eleData.Element("fansnum").Value);
                    person.FavNum        = Convert.ToInt32(eleData.Element("favnum").Value);
                    person.IdolNum       = Convert.ToInt32(eleData.Element("idolnum").Value);
                    person.Industry      = Convert.ToInt32(eleData.Element("industry_code").Value);
                    person.Introduction  = eleData.Element("introduction").Value;
                    person.IsEnt         = Convert.ToBoolean(Convert.ToInt32(eleData.Element("isent").Value));
                    person.IsMyBlack     = Convert.ToBoolean(Convert.ToInt32(eleData.Element("ismyblack").Value));
                    person.IsMyFans      = Convert.ToBoolean(Convert.ToInt32(eleData.Element("ismyfans").Value));
                    person.IsMyIdol      = Convert.ToBoolean(Convert.ToInt32(eleData.Element("ismyidol").Value));
                    person.IsRealName    = Convert.ToBoolean(Convert.ToInt32(eleData.Element("isrealname").Value));
                    person.IsVip         = Convert.ToBoolean(Convert.ToInt32(eleData.Element("isvip").Value));
                    person.Level         = Convert.ToInt32(eleData.Element("level").Value);
                    person.MutualFansNum = Convert.ToInt32(eleData.Element("mutual_fans_num").Value);
                    person.OpenId        = eleData.Element("openid").Value;
                    person.RegTime       = new DateTime(1970, 1, 1).AddSeconds(Convert.ToInt32(eleData.Element("regtime").Value));
                    person.Sex           = (Sex)Convert.ToInt32(eleData.Element("sex").Value);
                }

                result.ErrCode = Convert.ToInt32(xml.Root.Element("errcode").Value);
                result.Msg     = xml.Root.Element("msg").Value;
                result.Ret     = Convert.ToInt32(xml.Root.Element("ret").Value);

                callback(new Tuple <Result, Person>(result, person));
            });
        }
예제 #2
0
        public void FansList(int reqNum, int index, Mode mode, Action <Tuple <Result, List <Person> > > callback, int page = 0, AutoResetEvent autoResetEvent = null)
        {
            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }

            string url = String.Format("https://open.t.qq.com/api/friends/fanslist?" +
                                       "format=xml&reqnum={0}&startindex={1}&mode={2}" +
                                       "&oauth_consumer_key={3}&access_token={4}" +
                                       "&openid={5}&oauth_version=2.a",
                                       reqNum, index, (int)mode,
                                       m_accountDetail.APP_KEY, m_accountDetail.ACCESS_TOKEN,
                                       m_accountDetail.OPEN_ID);

            HttpRequestWorker.Get(url, (content) =>
            {
                Result result            = new Result();
                List <Person> personList = new List <Person>();

                XDocument xml    = XDocument.Parse(content);
                XElement eleData = xml.Root.Element("data");
                if (eleData != null)
                {
                    int curNum  = Convert.ToInt32(eleData.Element("curnum").Value);
                    int hasNext = Convert.ToInt32(eleData.Element("hasnext").Value);
                    foreach (XElement eleInfo in eleData.Elements("info"))
                    {
                        Person person = new Person();

                        person.Name       = eleInfo.Element("name").Value;
                        person.NickName   = eleInfo.Element("nick").Value;
                        person.FansNum    = Convert.ToInt32(eleInfo.Element("fansnum").Value);
                        person.IdolNum    = Convert.ToInt32(eleInfo.Element("idolnum").Value);
                        person.IsMyFans   = bool.Parse(eleInfo.Element("isfans").Value);
                        person.IsMyIdol   = bool.Parse(eleInfo.Element("isidol").Value);
                        person.IsRealName = Convert.ToBoolean(Convert.ToInt32(eleInfo.Element("isrealname").Value));
                        person.IsVip      = Convert.ToBoolean(Convert.ToInt32(eleInfo.Element("isvip").Value));
                        person.OpenId     = eleInfo.Element("openid").Value;
                        person.Sex        = (Sex)Convert.ToInt32(eleInfo.Element("sex").Value);

                        personList.Add(person);
                    }
                }

                result.ErrCode        = Convert.ToInt32(xml.Root.Element("errcode").Value);
                result.Msg            = xml.Root.Element("msg").Value;
                result.Ret            = Convert.ToInt32(xml.Root.Element("ret").Value);
                result.Page           = page;
                result.AutoResetEvent = autoResetEvent;

                callback(new Tuple <Result, List <Person> >(result, personList));
            });
        }