Qq open API

Source: Internet
Author: User

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, processingCodeAs 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 =

FCIS the ID of the QQ image. For example, the ID of the image is, and the first image used is 91.bmp.AlgorithmID/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 =ProgramStaff & Lv = 2 & PC = 650000 & pH = 0871-6466529 & pr = the network is the media % 252c relationship. This % 252c information is financial % 252c customer-oriented. % 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 =

UN adds the user's QQ number for us.

If the server receives the Protocol successfully, return:

Ver = 1.1 & cmd = addtolist & seq = 13666 & uin = 415103947 & res = 0 & Cd = 0 & UN = 24259132

CD indicates the identity authentication status of the added QQ account. If CD is set to 0, it indicates "allow anyone to list me as a friend", and if CD is set to 1, it indicates "you need to recognize your ID card to list me as a friend ", if CD is 3, "no one is allowed to list me as a friend ". If the value of CD is 0, after the information is returned, the user directly adds it as a friend. If the value of CD is 1, a response should be sent and added as a friend.

8. The response is added as a friend.

The response is added as a friend by both parties: 1. If you send a request and add a friend as a friend, if the other party needs verification, you must send a response to add a friend as a friend. 2. If the other party sends a friend request to you, you can add a friend response. One is to add a friend, and the other is to pass verification, the first is to reject a friend. We want to send a command to the server:

Ver = 1.1 & cmd = ack_addtolist & seq = & uin = & UN = & Cd = & rs =

CD is the response status, and CD is 0, which indicates "Verification passed ". If the value of CD is 1, it indicates that "the peer is rejected as a friend ". If CD is set to 2, "add a friend to the requester" is displayed ". RS is the reason for your request.

If the server receives the Protocol successfully, return:

Ver = 1.1 & cmd = ack_addtolist & seq = 1130 & uin = 415103947 & res = 0 &

9. delete a friend.

It is easy to delete friends. If you send the delfromlist command to the server, you can delete users:

Ver = 1.1 & cmd = delfromlist & seq = & uin = & UN =

UN indicates the QQ number of the user to be deleted.

If the server receives the Protocol successfully, return:

Ver = 1.1 & cmd = delfromlist & seq = 24514 & uin = 415103947 & res = 0 &

10. Change the current user status.
You can set QQ to the online or invisible status. We can send change_stat to the server to change the current status. The specific command is as follows:

Ver = 1.1 & cmd = change_stat & seq = & uin = & St =

St is the status to be changed, 10 is online, 20 is offline, and 30 is busy.

If the server receives the Protocol successfully, return:

Ver = 1.1 & cmd = change_stat & seq = 17512 & uin = 415103947 & res = 0 &

11. log out
To log out, send the logout command to the server. The specific command is as follows:

Ver = 1.1 & cmd = logout & seq = & uin =

If the server receives the Protocol successfully, return:

Ver = 1.1 & cmd = logout & seq = 15803 & uin = 415103947 & res = 0

12. Get a friend QQ message

To receive messages from friends, send the getmsgex command to the server. The specific command is as follows:

Ver = 1.1 & cmd = getmsgex & seq = & uin =

If the server receives the Protocol successfully, return:

Ver = 1.1 & cmd = getmsgex & seq = 56661 & uin = 29501213 & res = 0 & Mn = 3 & mt = 99,9, 9, & UN = 24259132,24259132, 24259132, & Mg = 30, asdfasdfasdfasdf, asdfasdfasdf ,&

Mt indicates the message type, 99 indicates the system message, and 9 indicates the user message. "UN" indicates the user who sent the message, "mg" indicates the message sent, and "mg" indicates some specific system meanings. For example, when MT is 99 and Mg is 30, if the value of UN is 24259132, the user 4259132 is in a busy state. You can refresh the friends list based on the message to Improve the efficiency.

13. send messages to friends QQ

To send a message to a friend, send the cltmsg command to the server. The specific command is as follows:

Ver = 1.1 & cmd = cltmsg & seq = & uin = & UN = & Mg =

UN indicates the QQ number of the user who sent the message, and Mg indicates the message sent to the user.

If the server receives the Protocol successfully, return:

Ver = 1.1 & cmd = cltmsg & seq = 15803 & uin = 415103947 & res = 0

Well, the above is an incomplete HTTP-based QQ protocol analysis. With the above Protocol, You can implement many things, such as QQ robot, QQ advertising system, and instant messaging integration tools.

Qq protocol network protocol-request part
 
// Log on
Ver = 1.0 & cmd = login & seq = & uin = & PS = & M5 = 1 & lc = 9326b87b234e7235

// Obtain the message
Ver = 1.0 & cmd = getmsgex & seq = & uin =

// Send a message
Ver = 1.0 & cmd = cltmsg & seq = & uin = & UN = & Mg =

// Friend list
Ver = 1.0 & cmd = List & seq = & uin = & Tn = 160 & UN = 0

// Obtain the friend status
Ver = 1.0 & cmd = query_stat & seq = & uin = & Tn = 50 & UN = 0

// Obtain friend information
Ver = 1.0 & cmd = getinfo & seq = & uin = & Lv = 2 & UN =

// Add friends
Ver = 1.0 & cmd = addtolist & seq = & uin = & UN =

// Respond to the other party's request and add you as a friend's response
Ver = 1.0 & cmd = ack_addtolist & seq = & uin = & UN = & Cd = & rs =

// Delete a friend
Ver = 1.0 & cmd = delfromlist & seq = & uin = & UN =

// Search for friends
Ver = 1.0 & cmd = finger & seq = & uin = & Ag = & SX = & Pv =

// Change your status. The st code should be consistent with the code for getting friend status.
Ver = 1.0 & cmd = change_stat & seq = & uin = & St =

// Log out
Ver = 1.0 & cmd = logout & seq = & uin =

Reprinted from: http://www.cnblogs.com/haaron-john/archive/2007/01/03/610527.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.