利用web端接口实现QQ好友列表获取、QQ群成员获取列表的实例分析

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


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


1.获取QQ好友信息表:

 

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<

 

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<

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}]}}

目前写了完整的软件。

有想了解可加QQ好友列表获取   QQ群:675172950

你可能感兴趣的:(QQ营销软件,QQ好友列表获取,QQ群成员获取,QQ好友列表提取,获取他人QQ好友列表,QQ好友列表获取软件)