webQQ获得群列表、好友列表

本文来源于:http://hi.baidu.com/5457090/item/9746ca53536bf2968d12ed56
转载请注明出处






当开放API成为历史潮流不可阻挡之时,腾讯亦只能与时俱进,但腾讯为了保持江湖的垄断地位,不会随意公开像QQ号这样的客户资源,于是乎,你能通过webQQ查询到的,也只能是用户或群的昵称,绝非QQ号码或群号。

抓包发现:webQQ每次成功登陆后,接下来一般会去获取"好友列表"和"群列表"。而断线重连的时候,通常不需要。
你每次登录webQQ,腾讯服务器便会自动分配给你和你的QQ好友一个临时的uin;分配给群的,便是gid和gcode。
所谓“好友列表”便是好友的uin和昵称对应起来的信息列表。而所谓的“群列表”,则是临时的群名称和群gid、群gcode的对应列表。

1。获取好友信息表:
POSThttp://s.web2.qq.com/api/get_user_friends2HTTP/1.1
Referer:http://s.web2.qq.com/proxy.html
POST数据:一个json数据结构:
r={"h":"hello","vfwebqq":"【vfwebqq】"}
如果成功,会返回一个json数据结构:
{"retcode":0,"result":{"friends":[{"flag":0,"uin":3112962973,"categories":0}],"marknames":[],"categories":[{"index":1,"sort":1,"name":"朋友"},{"index":2,"sort":2,"name":"家人"},{"index":3,"sort":3,"name":"同学"}],"vipinfo":[{"vip_level":0,"u":3112962973,"is_vip":0}],"info":[{"face":0,"flag":524288,"nick":"Spark.Ho","uin":3112962973}]}}
我们把返回的数据,存放在一个指定的txt文件中,供其后操作的调用。

C++ (with libcurl)源程序
string WebQQ_buddy()
{
 // 提取QQ登录信息:
 char buf[1024];
 string vfwebqq;
 size_t found,found2;
 ifstream QQLoginfile("D:\\SparkHo\\QQLogin.txt"); 
 if(!QQLoginfile)
 {
  QQLoginfile.close();
  vfwebqq = "";
 }
 else
 {
  QQLoginfile.getline(buf,1024);
  string QQLogin = (string) buf;
  QQLoginfile.close();
  found  = QQLogin.find("vfwebqq");
  found2 = QQLogin.find(";",found+8,1);
  vfwebqq = QQLogin.substr(found+8,found2-found-8);
 }
 // 初始化libcurl
 CURLcode return_code;
 return_code = curl_global_init(CURL_GLOBAL_WIN32);
 if (CURLE_OK != return_code) return NULL;
 // 获取easy handle
 CURL *easy_handle = curl_easy_init();
 if (NULL == easy_handle)
 {  
  curl_global_cleanup();
  return “”;
 }
 string buffer;
 string post_url = "http://s.web2.qq.com/api/get_user_friends2";
 string referer_url = "http://s.web2.qq.com/proxy.html";
 string base = "{\"h\":\"hello\",\"vfwebqq\":\""+vfwebqq+"\"}";
 string urlencode = curl_easy_escape(easy_handle,base.c_str(),0);
 string fields = "r=" + urlencode;
  // 设置easy handle属性
 curl_easy_setopt(easy_handle, CURLOPT_URL, post_url.c_str());
 curl_easy_setopt(easy_handle, CURLOPT_REFERER, referer_url.c_str());
 curl_easy_setopt(easy_handle, CURLOPT_POST, 1);
 curl_easy_setopt(easy_handle, CURLOPT_POSTFIELDS, fields.c_str());
 curl_easy_setopt(easy_handle, CURLOPT_WRITEFUNCTION, writer);
 curl_easy_setopt(easy_handle, CURLOPT_WRITEDATA, &buffer);
 //提交第一步保存的cookie 
    curl_easy_setopt(easy_handle, CURLOPT_COOKIEFILE,"D:\\SparkHo\\cookie_login.txt");
 // 执行数据请求
 curl_easy_perform(easy_handle); 
 // 释放资源
 curl_easy_cleanup(easy_handle);
 curl_global_cleanup();

 // 更新QQ好友列表信息:
 fstream QQBuddywrite("D:\\SparkHo\\QQBuddy.txt",ios::out|ios::trunc);
 QQBuddywrite<<buffer.c_str();
 QQBuddywrite.close();

 return buffer;
}

2。获取群信息表:
POSThttp://s.web2.qq.com/api/get_group_name_list_mask2HTTP/1.1
Referer:http://s.web2.qq.com/proxy.html
POST数据:一个json数据结构:
r={"vfwebqq":"【vfwebqq】"}
如果成功,会返回一个json数据结构:
{"retcode":0,"result":{"gmasklist":[],"gnamelist":[{"flag":17825793,"name":"Spark.Ho操盘","gid":2444491359,"code":2485575464}],"gmarklist":[]}}
我们把返回的数据,存放在一个指定的txt文件中,供其后操作的调用。

C++ (with libcurl)源程序
string WebQQ_group()
{
 // 提取QQ登录信息:
 char buf[1024];
 string vfwebqq;
 size_t found,found2;
 ifstream QQLoginfile("D:\\SparkHo\\QQLogin.txt"); 
 if(!QQLoginfile)
 {
  QQLoginfile.close();
  vfwebqq = "";
 }
 else
 {
  QQLoginfile.getline(buf,1024);
  string QQLogin = (string) buf;
  QQLoginfile.close();

  found  = QQLogin.find("vfwebqq");
  found2 = QQLogin.find(";",found+8,1);
  vfwebqq = QQLogin.substr(found+8,found2-found-8);
 }
 // 初始化libcurl
 CURLcode return_code;
 return_code = curl_global_init(CURL_GLOBAL_WIN32);
 if (CURLE_OK != return_code) return NULL;
 // 获取easy handle
 CURL *easy_handle = curl_easy_init();
 if (NULL == easy_handle)
 {  
  curl_global_cleanup();
  return “”;
 }
 string buffer;
 string post_url = "http://s.web2.qq.com/api/get_group_name_list_mask2";
 string referer_url = "http://s.web2.qq.com/proxy.html";
 string base = "{\"vfwebqq\":\""+vfwebqq+"\"}";
 string urlencode = curl_easy_escape(easy_handle,base.c_str(),0);
 string fields = "r=" + urlencode;
 // 设置easy handle属性
 curl_easy_setopt(easy_handle, CURLOPT_URL, post_url.c_str());
 curl_easy_setopt(easy_handle, CURLOPT_REFERER, referer_url.c_str());
 curl_easy_setopt(easy_handle, CURLOPT_POST, 1);
 curl_easy_setopt(easy_handle, CURLOPT_POSTFIELDS, fields.c_str());
 curl_easy_setopt(easy_handle, CURLOPT_WRITEFUNCTION, writer);
 curl_easy_setopt(easy_handle, CURLOPT_WRITEDATA, &buffer);
 //提交第一步保存的cookie 
    curl_easy_setopt(easy_handle, CURLOPT_COOKIEFILE,"D:\\SparkHo\\cookie_login.txt");
 // 执行数据请求
 curl_easy_perform(easy_handle); 
 // 释放资源
 curl_easy_cleanup(easy_handle);
 curl_global_cleanup();

 // 更新QQ群列表信息:
 fstream QQGroupwrite("D:\\SparkHo\\QQGroup.txt",ios::out|ios::trunc);
 QQGroupwrite<<buffer.c_str();
 QQGroupwrite.close();
     
 return buffer;
}

3。获取群成员信息表:
GET http://s.web2.qq.com/api/get_group_info_ext2?gcode=【gcode】&vfwebqq=【vfwebqq】 HTTP/1.1
Referer:http://s.web2.qq.com/proxy.html
POST数据:一个json数据结构:
r={"vfwebqq":"【vfwebqq】"}
如果成功,会返回一个json数据结构:
{"retcode":0,"result":{"stats":[{"client_type":1,"uin":1664604219,"stat":30},。。。,{"client_type":41,"uin":2393982134,"stat":10}],
"minfo":[{"nick":"David","province":"","gender":"male","uin":2010255454,"country":"","city":""}, 。。。,{"nick":"﹏落败的唯美丶","province":"山东","gender":"female","uin":3386757496,"country":"中国","city":"青岛"}],
"ginfo":{"face":0,"memo":"飞狐下载\nhttp://dl.dbank.com/c0pmgrt8wa\n\r\n通达信":"顺势而为","code":2485575464,"createtime":1260641721,"flag":17825793,"level":0,"name":"Spark.Ho操盘","gid":2444491359,"owner":3112962973,
"members":[{"muin":2010255454,"mflag":132},,,,,{"muin":3386757496,"mflag":0}],"option":2},
"cards":[{"muin":3112962973,"card":"Spark.Ho"},。。。,{"muin":2393982134,"card":"SP预警"}],
"vipinfo":[{"vip_level":0,"u":4157281859,"is_vip":0},。。。,{"vip_level":0,"u":3489781961,"is_vip":0}]}}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值