webqq2.0协议研究(4)-获取好友,在线好友,最近联系人和分组

    获取好友和分组:

  地址:http://web2-b.qq.com/api/get_user_friends

     提交参数 r=%7B%22vfwebqq%22%3A%22{0}%22%7D {0}为登陆成功后返回的vfwebqq

     提交方式:post

     返回结果包含了好友分组   好友   好友信息 

     

      这里获取的好友唯一一点不足就是无法区别好友是否在线,还得专门去获取在线好友。倒是QQ空间获取好友的方式比较适用

 

   获取在线好友:
    地址:http://web2-b.qq.com/channel/get_online_buddies?clientid={0}&psessionid={1}&t={2}

    {0}登陆时生成的clientid,{1}登陆后获取的psessionid参数 {2}时间戳

   提交方式:get

 

   获取群:

   地址:http://web2-b.qq.com/api/get_group_name_list_mask

   参数:r=%7B%22vfwebqq%22%3A%22{0}%22%7D {0}为登陆后获取的vfwebqq

   提交方式:post

  

    以下给出部分代码:

    

获取好友
   
     
/// <summary>
/// 获取好友及好友分组
/// </summary>
/// <returns></returns>
public bool GetUserFriends()
{
user.Groups
= new Dictionary < int , string > ();
user.Friends
= new Dictionary < string ,Friend > ();
string url = " http://web2-b.qq.com/api/get_user_friends " ;
string data = string .Format( " r=%7B%22vfwebqq%22%3A%22{0}%22%7D " , user.Key);
string result = HttpHelper.GetHtml(url, data, true , user.Cookie,url);

Regex group
= new Regex( " ({\ " index\ " :)(?<index>[0-9]{1,2}?)(,\ " name\ " :\ " )( ?< name > . +? )(\ " }) " );
foreach (Match item in group.Matches(result))
{
user.Groups.Add(Convert.ToInt32(item.Groups[
" index " ].Value), Utils.ConvertUnicodeStringToChinese(item.Groups[ " name " ].Value));
}

Regex friend
= new Regex( " ({\ " uin\ " :)(?<uin>[0-9]{5,11}?)(,\ " categories\ " :)(?<id>[0-9]{1,2}?)(}) " );
foreach (Match item in friend.Matches(result))
{
Friend f
= new Friend();
f.Uin
= item.Groups[ " uin " ].Value;
f.GroupId
= Convert.ToInt32(item.Groups[ " id " ].Value);
user.Friends.Add(f.Uin, f);
}

Regex info
= new Regex( " ({\ " uin\ " :)(?<uin>[0-9]{5,11}?)(,\ " nick\ " :\ " )( ?< nick > . +? )(\ " ,\ " face\ " :)(?<face>.+?)(,\ " flag\ " :)(?<flag>.+?)(}) " );
foreach (Match item in info.Matches(result))
{
if (user.Friends.Keys.Contains(item.Groups[ " uin " ].Value))
{
user.Friends[item.Groups[
" uin " ].Value].Name = Utils.ConvertUnicodeStringToChinese(item.Groups[ " nick " ].Value);
user.Friends[item.Groups[
" uin " ].Value].FaceImg = item.Groups[ " face " ].Value;

}


}
return false ;
}

 

 

转载请注明原文地址:http://www.cnblogs.com/hackren/archive/2010/11/07/1870912.html

hackren

  

你可能感兴趣的:(Web)