1)发信息给群
抓包:
POST http://d.web2.qq.com/channel/send_qun_msg2 HTTP/1.1
Referer: http://d.web2.qq.com/proxy.html
格式:
r={“group_uin”:【gid】,”content”:”[\"【Msg】\",[\"font\",{\"name\":\"Arial\",\"size\":\"10\",\"style\":[0,0,0],\”color\”:\”000000\”}]]”, “msg_id”:【msg_id】,”clientid”:”【clientid】”,”psessionid”:”【psessionid】”}&clientid=【clientid】&psessionid=【psessionid】
// 发信到群,参数:该群的gid
string WebQQ_group_send(string eMsg,string gid)
{
size_t found,found2;
string gMsg = eMsg;
gMsg = RPLChar(gMsg,"\r\n","\\\\n");
// 提取QQ登录信息:
char buf[1024];
string clientid,psessionid;
ifstream QQLoginfile("D:\\SparkHo\\QQLogin.txt");
if(!QQLoginfile)
{
QQLoginfile.close();
clientid = "";
psessionid = "";
}
else
{
QQLoginfile.getline(buf,1024);
string QQLogin = (string) buf;
QQLoginfile.close();
found = QQLogin.find("ClientID");
found2 = QQLogin.find(";",found+9,1);
clientid = QQLogin.substr(found+9,found2-found-9);
found = QQLogin.find("psessionid");
found2 = QQLogin.find(";",found+11,1);
psessionid = QQLogin.substr(found+11,found2-found-11);
}
// msg_id,随机生成
int iMsg;
/* initialize random seed: */
srand ( time(NULL) );
/* generate secret number: */
iMsg = rand() % 10000000 + 73200001;
sprintf(buf, "%d", iMsg);
string msg_id = (string)buf;
// 初始化libcurl
CURLcode return_code;
return_code = curl_global_init(CURL_GLOBAL_WIN32);
if (CURLE_OK != return_code) return "";
// 获取easy handle
CURL *easy_handle = curl_easy_init();
if (NULL == easy_handle)
{
curl_global_cleanup();
return "";
}
string buffer;
string post_url = "http://d.web2.qq.com/channel/send_qun_msg2";
string referer_url = "http://d.web2.qq.com/proxy.html";
string base = "{\"group_uin\":"+gid+",\"content\":\"[\\\""+G2U(gMsg.c_str());
base = base + "\\\",[\\\"font\\\",{\\\"name\\\":\\\""+G2U("微软雅黑")+"\\\",\\\"size\\\":\\\"12\\\",\\\"style\\\":[0,0,0],\\\"color\\\":\\\"ff6600\\\"}]]\",\"msg_id\":"+msg_id;
base = base + ",\"clientid\":\""+clientid+"\",\"psessionid\":\""+psessionid+"\"}";
string urlencode = curl_easy_escape(easy_handle,base.c_str(),0);
string fields = "r=" + urlencode + "&clientid=" + clientid + "&psessionid=" + psessionid;
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();
return buffer;
}
2)发信息给好友
抓包:
POST http://d.web2.qq.com/channel/send_buddy_msg2 HTTP/1.1
Referer: http://d.web2.qq.com/proxy.html
格式:
r={“to”:【uin】,”face”:537,”content”:”[\"【Msg】\",[\"font\",{\"name\":\"Arial\",\"size\":\"10\",\"style\":[0,0,0],\”color\”:\”000000\”}]]”,”msg_id”:【msg_id】,”clientid”:”【clientid】”,”psessionid”:”【psessionid】”}&clientid=【clientid】&psessionid=【psessionid】
// 给好友发信,参数:好友的uin
string WebQQ_buddy_send(string eMsg,string uin)
{
// 对eMsg加工
eMsg = RPLChar(eMsg,"\r\n","\\\\n");
eMsg = RPLChar(eMsg,"\t"," ");
// 提取QQ登录信息:
char buf[1024];
size_t found,found2;
string clientid,psessionid;
ifstream QQLoginfile("D:\\SparkHo\\QQLogin.txt");
if(!QQLoginfile)
{
QQLoginfile.close();
clientid = "";
psessionid = "";
}
else
{
QQLoginfile.getline(buf,1024);
string QQLogin = (string) buf;
QQLoginfile.close();
found = QQLogin.find("ClientID");
found2 = QQLogin.find(";",found+9,1);
clientid = QQLogin.substr(found+9,found2-found-9);
found = QQLogin.find("psessionid");
found2 = QQLogin.find(";",found+11,1);
psessionid = QQLogin.substr(found+11,found2-found-11);
}
// msg_id,随机生成
int iMsg;
/* initialize random seed: */
srand ( time(NULL) );
/* generate secret number: */
iMsg = rand() % 10000000 + 73200001;
sprintf(buf, "%d", iMsg);
string msg_id = (string)buf;
// 初始化libcurl
CURLcode return_code;
return_code = curl_global_init(CURL_GLOBAL_WIN32);
if (CURLE_OK != return_code) return "";
// 获取easy handle
CURL *easy_handle = curl_easy_init();
if (NULL == easy_handle)
{
curl_global_cleanup();
return "";
}
string buffer;
string post_url = "http://d.web2.qq.com/channel/send_buddy_msg2";
string referer_url = "http://d.web2.qq.com/proxy.html";
string base = "{\"to\":"+uin+",\"face\":537,\"content\":\"[[\\\"cface\\\",\\\"F93025D75BE708CA420BFD4448F862E8.GIF\\\"],\\\"\\\\n"+strUTF8(eMsg.c_str());
base = base + "\\\",[\\\"font\\\",{\\\"name\\\":\\\"Arial\\\",\\\"size\\\":\\\"10\\\",\\\"style\\\":[0,0,0],\\\"color\\\":\\\"000000\\\"}]]\",\"msg_id\":"+msg_id;
base = base + ",\"clientid\":\""+clientid+"\",\"psessionid\":\""+psessionid+"\"}";
string urlencode = curl_easy_escape(easy_handle,base.c_str(),0);
string fields = "r=" + urlencode + "&clientid=" + clientid + "&psessionid=" + psessionid;
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();
return buffer;
}
附:
// 通过好友“昵称”,查找好友的uin
string WebQQ_buddy_uin(string Buddyname)
{
// 提取QQ好友信息:
size_t found,found2,found3;
string BuddyJson;
string uin = "";
ifstream in("D:\\SparkHo\\QQBuddy.txt");
if(!in)
in.close();
else
{
in.seekg(0,ios::end);
size_t len = in.tellg();
in.seekg(0,ios::beg);
char* buf = new char[len];
in.read(buf,len);
BuddyJson = (string)buf;
in.close();
if(buf) delete[] buf;
// 文本格式: ..."nick":"Spark.Ho","uin":3112962973}...
found = BuddyJson.find(strUTF8(Buddyname.c_str()));
found2 = BuddyJson.find("uin",found+1,3);
found3 = BuddyJson.find("}",found2+1,1);
uin = BuddyJson.substr(found2+5,found3-found2-5);
}
return uin;
}
3)发信息给群成员,原理差不多,稍微复杂点,略。