1. Search for servers that support the qq http protocol.
People may be confused by some counterfeits. They may think that QQ's HTTP Server communicates based on 80 ports (for example, 218.17.209.23: 80, the HTTP-based server should be: http://tqq.tencent.com: 8000, a server that communicates through port 8000.
Because the HTTP server of QQ does not support the GET method in the HTTP protocol, it supports the POST method. Therefore, if we want to transmit parameters to the HTTP protocol of QQ, we must use the POST method.
2. C # and DELPHI implement http post communication.
C #:
In C #, The System. Web space provides an object called WebClient. With this object, C # can directly send WEB client requests to the server. To submit the POST method to the server, you must use its UploadData () method. First, convert the request information to byte (because POST submits the stream data of characters) and use it as the UploadData () parameter. Use UploadData () for data submission, and finally return the POST feedback. As follows:
WebClient _ client = new WebClient ();
String postValues = "VER = 1.0 & CMD = Query_Stat & SEQ = 12321 & UIN = 29501213 & TN = 50 & UN = 0 ";
Byte [] byteArray = System. Text. Encoding. ASCII. GetBytes (postValues );
Byte [] pageData = _ client. UploadData (Host, "POST", byteArray );
In this way, we use C # To submit an http post method.
When the value is passed in and returned, it is based on the UTF-8, C # display Chinese is very often.
3. Implement logon for QQ users.
In QQ communication, users must log on before sending information to each other. QQ login is very important. The user we see is online, not the user's QQ has been connected to the server, but regularly sent a message to the server, proving that they are still connected to the line, if it exceeds the time limit, QQ considers the user to be offline.
In the logon protocol, the QQ password is encrypted with the standard MD5, while C # is self-contained, but cannot be used directly. It must be processed before being converted to the standard MD5, the processing code is as follows:
Public static string MD5 (string toCryString)
{
MD5CryptoServiceProvider hashmd5;
Hashmd5 = new MD5CryptoServiceProvider ();
Return BitConverter. toString (hashmd5.ComputeHash (Encoding. default. getBytes (toCryString ))). replace ("-",""). toLower (); // asp is in lower case and all characters are reduced to write
}
After learning about how QQ encrypts user passwords, we began to parse QQ's HTTP logon protocol. We passed the Protocol as a POST parameter to the server, the server returns the corresponding information to the client:
Incoming protocol:
VER = 1.1 & CMD = Login & SEQ = & UIN = & PS = & M5 = 1 & LC = 9326B87B234E7235
VER is used to describe the version of the QQ protocol, CMD is the command to describe the protocol, Login is the Login of QQ, SEQ is a mark set by him to prevent repeated sending, generally, we can place a section of the current time value. (C #: DateTime. now. ticks. toString (). substring () DELPHI: CopyStr (inttostr (GetTickCount (),). UIN indicates the QQ number, PS, is the value of the MD5 encrypted password.
Response Protocol:
VER = 1.1 & CMD = Login & SEQ = 11281 & UIN = & RES = 0 & RS = 0 & HI = 60 & LI = 300 (successful)
If RES is 0, a success is returned. If RS is 0, the logon is successful.
VER = 1.1 & CMD = Login & SEQ = 11422 & UIN = 315103947 & RES = 0 & RS = 1 & RA = Logon Failed
If RS is set to 1, the logon fails. Then, a prompt is displayed, indicating the cause.
4. Obtain the QQ list.
If you add your friends, your friends will be put into your QQ friends list, to obtain the QQ list, we must send the protocol to the QQ server to obtain the Friends List (I will not repeat the known parameters ):
VER = 1.1 & CMD = List & SEQ = & UIN = & TN = 160 & UN = 0
If the server receives the Protocol successfully, return:
VER = 1.1 & CMD = LIST & SEQ = 43661 & UIN = 29501213 & RES = 0 & FN = 1 & SN = 24 & UN = 561256,1943497 ,....
Your friend's QQ number is next to UN, and each number is separated. Then we only need to get the code after UN and list it as OK. C # You can use string. Split (,) to put values into the list for processing, while DELPHI can use Split () to put values into TStrings for processing.
5. Obtain the QQ friends online list
Obtaining the QQ friends online list is similar to obtaining the friends list. The only difference is that Query_Stat is used for different commands. The Protocol is as follows:
VER = 1.1 & CMD = Query_Stat & SEQ = & UIN = & TN = 50 & UN = 0
If the server receives the Protocol successfully, return:
VER = 1.1 & CMD = QUERY_STAT & SEQ =-1 & UIN = 29501213 & RES = 0 & FC = 141,270,270, & FN = 1 & SN = 3 & ST = 10, 10, 10, & amp; UN =
The FC is the ID of the QQ image. For example, the ID of the header image is, and the first image is 91.bmp. The algorithm is ID/3 + 1. ST is the status of QQ users, 10 is online, 20 is offline, and 30 is busy. UN is the QQ number of online users, and NK is the QQ nickname of online users. ST, UN, NK, and data separated by commas correspond to each other.
6. Obtain QQ user information.
If you want to see the QQ user's real name, MAIL, age, personal instructions, and other information, you must send a friend information to the server:
VER = 1.1 & CMD = GetInfo & SEQ = & UIN = & LV = 2 & UN =
UN is the QQ number for viewing user information.
If the server receives the Protocol successfully, return:
VER = 1.1 & CMD = GETINFO & SEQ = 12707 & UIN = 415103947 & RES = 0 & AD = Kunming, Yunnan & AG = 0 & EM = Microprogramer@hotmail.com & FC = 270 & HP = msger.org (under construction ...) & JB = programmer & LV = 2 & PC = 650000 & PH = 0871-6466529 & PR = the network is the media % 252c relationship. This % 252c information is mainly for customers of finance % 252c. % 0d % 0a & PV = Yunnan Province & RN = Liu X & SC = social University & SX = 0 & UN = 24259132 & NK = Weicheng
The contact address of an AD user. AG indicates the user's age, EM indicates the user's MAIL, FC indicates the user's profile picture, HP indicates the user's website, JB indicates the user's occupation, and PC indicates the user's zip code, PH indicates the user's contact number, PR indicates the user's profile, PV indicates the user's province, RN indicates the user's real name, SC indicates the user's graduation institution, SX indicates the user's gender, and UN indicates the user's QQ number, NK is the nickname of the user QQ.
7. Add QQ friends.
To add a friend, you need to send the AddToList command to the server. The specific command is as follows:
VER = 1.1 & CMD = AddToList & SEQ = & UIN = & UN =