QQ API Interface

Source: Internet
Author: User

1. Find the server that supports QQ HTTP protocol. People may be confused by some false image, you may think that the HTTP server is based on 80 port communication (such as: 218.17.209.23:80), in fact, it is true that HTTP-based servers should be: http://tqq.tencent.com:8000 , which is a server that communicates through 8000 ports. Because the HTTP server in QQ does not support the GET method in the HTTP protocol, it supports the POST method. So we have to give QQ HTTP protocol parameters, then you will need to use the POST method.

2. C # and DELPHI are communications that implement the POST method of HTTP. C #: An object called Webclien T is provided under system.web space in C #, and this object allows C # to send a request directly to the server for the WE B client. Then we have to submit the POST method to the server, then we must use its Uploaddata () method. First, the information to be requested is first converted to bytes (because POST submits the stream data of the character) and then as a parameter of Uploaddata (). Use Uploadd ATA () for data submission, and finally return, POST feedback information. As follows: WebClient _client = new WebClient (); String postvalues = "ver=1.0&cmd=query_s tat&seq=12321&uin=29501213&tn=50&un= 0"; byte[] ByteArray = System.Text.Encoding.ASC Ii. GetBytes (postvalues); byte[] Pagedata = _client. Uploaddata (Host, "P OST", ByteArray); In this way, we use C # to do an HTTP POST method submission.
When the value is passed in and returned, it is based on UTF-8, and C # displays Chinese very often.

3, to realize the QQ user login. QQ communication in the user must be logged in before they can send each other information and so on. QQ login is very key, we see the user online, not the user's QQ has been connected to the server, but timed to send the letter to the server, prove that they are also connected to the line, if the QQ is beyond the time to think that users have dropped the line. In the login agreement, the password is used to encrypt the standard MD5, QQ and C # self-contained, but the direct use, must be processed, to make it into a standard MD5, processing code as follows:
public static string MD5 (String Tocrys tring) {MD5CryptoServiceProvider hashmd5; hashmd5 = new M d5cryptoserviceprovide R (); Return bitconverter.tostring (Hashmd5.computeh Ash (Encoding.Default.GetBytes (tocrystring))). Re Place ("-", "" "). ToLower ();//asp is lowercase, turn all characters into lowercase} Understand how QQ is the user password encryption, then we began to really, parsing QQ HTTP Login protocol, we put the protocol as the PO ST parameters to the server, and the server feedback the corresponding information to the client : Incoming protocol:
VER=1.1&CMD=LOGIN&SEQ=&UIN=&PS=&M5 =1&lc=9326b87b234e7235 VER is used to illustrate the version of the QQ protocol, CMD is the command that describes the protocol, Login refers to QQ login, SEQ is his to prevent repeated sending and set a mark, generally we take the current time value of a paragraph put. (C#:datetime.now.ticks.to String (). Substring (7,7) delphi:copystr (Inttost R (GetTickCount ()), 1,5), UIN is the user QQ number that you want to log in, PS, is the value of the password after the MD5 encryption. Return protocol: Ver=1.1&cmd=login&seq=11281&uin=&re s=0&rs=0&hi=60&li=300 (Success) RES is 0 for successful return, RS for 0 table  Successful login. ver=1.1&cmd=login&seq=11422&uin=315 103947&res=0&rs=1&ra= Login Failed RS is 1 for login failed, then a prompt message will appear RA description original Because
4, Get QQ list. If you add your friends, then your friends will be placed in your QQ friend list, then we want to get QQ list is necessary to Q Q server to send a friend list of the agreement (I do not from the complex known parameters): Ver=1.1&cmd=list&seq=&amp ; Uin=&tn=160&u n=0 The server gets the protocol, returns if successful: ver=1.1&cmd=list&seq=43661&uin=2950 1213&res=0&fn=1 &sn=24&un=561256,1943 497,....
After the UN is your friend's QQ number, each number is separated by. Then we just need to get the code behind the UN and list it OK. C # can use String. Split (', ') puts the value into the list for processing, and DELPHI can use Split () to put the values into Tstri NGS for processing.

5, to get QQ friends online list to get QQ friends online list, and get friends list is similar, the only difference is the use of the command is Query_stat, the agreement is as follows: ver=1.1&cmd=query_stat&seq=&uin=& Amp;tn =50&un=0 The server gets the protocol, returns if successful: ver=1.1&cmd=query_stat& seq=-1&uin=29501213&res=0&fc= 141,270,2 70,&fn=1&sn=3&st=10,10,10,&un= FC is the ID of the QQ avatar, such as the Avatar ID of 270, then its head using the image of 91.bmp, its algorithm for id/3+1. ST for the status of QQ users, 10 is on-line, 20 offline, 30 busy. UN for online users QQ number, NK for online users of QQ nickname. ST, Un,nk, each comma-separated data corresponds to each other.

6, to get QQ user information. If you want to see the real name of QQ users, MAIL, age, personal description and other information, then we must send to the server to get information about friends: ver=1.1&cmd=getinfo&seq=&uin=&lv=2&  Un= UN is the QQ number to view user information. If the server gets the protocol, it returns if successful:
ver=1.1&cmd=getinfo&seq=12707&uin=4  15103947&res=0&ad= Yunnan Kunming &AG=0&EM=Mi  [ email protected]&fc=270&hp=msg  er.org (under construction ...) &jb= Programmer &lv=2&pc=650000 & ph=0871-6466529&pr= Network for the media%252c relationship-based%252c information for the financial%252c customers.%0 d%0a&pv=  Yunnan Province &rn= Liu X&sc= Social University &sx=0&un=2425 9132&nk= micro-path AD user's contact address,ag  for user age, EM for user MAI L,FC for the user avatar, HP for the user site, JB for the user occupation, p C for the user's postal code, PH for the user contact telephone, PR for the user profile, P v  for the user so the province, RN for the user's real name, SC for the user's graduation institutions, SX for user gender, UN for users QQ, N K is the user QQ nickname. 7, add QQ friends.   Want to add friends, it is necessary to send Addtolist command to the server, the specific command is as follows:  ver=1.1&cmd=addtolist&seq=&uin=&un= UN for us to increase the user's QQ No.   returns if successful after the server has received the agreement: ver=1.1&cmd=addtolist&seq=13666&uin=4  15103947&res=0&cd=0& un=24259132 CD to be added QQ authentication status, CD 0 for "Allow   who list me as a friend", CD 1 means "Need ID to identify me as a friend", CD 3 means "Do not allow me to be listed as a friend." If the CD is 0  then the user will be directly added to the friend, if the CD is 1, then also send a response to add a friend's responses.

8. Respond to friends.
Response Plus for friend responses are on both sides: 1, if you send a request to add the other person as a friend, if the other party needs to verify, then must send a response plus a friend's response. 2, if the other side to send a friend request to you, then you can add to your friend's response, one is to add a friend, one is to pass the verification, one is to refuse to add to friends. We want to send a command to the server: Ver=1.1&cmd=ack_addtolist&seq=&uin=&u n=&cd=&rs= CD is in response status and CD is 0 for "verified". A CD of 1 indicates that the "Reject Plus as Friend" CD is 2. "Add a friend to the request". RS is the reason you want to request. Returns if successful after the server has received a protocol: Ver=1.1&cmd=ack_addtolist&seq=1130&ui n=415103947&res=0&

9. Delete Friends.  Deleting a friend is easy, sending the delfromlist command to the server deletes the user: Ver=1.1&cmd=delfromlist&seq=&uin=&un = UN is the QQ number of the user you want to delete. Returns if successful after the server has received a protocol: Ver=1.1&cmd=delfromlist&seq=24514&uin =415103947&res=0&

10. Change the current state of the user. QQ can be set to online, stealth and other states, we can send Ch Ange_stat to the server to change the current state, the specific command is as follows: Ver=1.1&cmd=change_stat&seq=&uin=&st =
ST is the state to change, 10 is on-line, 20 is offline, and 30 is busy. Returns if successful after the server has received a protocol: Ver=1.1&cmd=change_stat&seq=17512&uin =415103947&res=0&

11, log out to log out, to send command Logout to the server, the specific command is as follows: Ver=1.1&cmd=logout&seq=&uin= after the server gets the agreement, if successful then return: ver=1.1&cmd= Logout&seq=15803&uin=41 5103947&res=0

12, get Friends QQ message if you want to receive a friend's message, to send a command to the server Getmsge x, the specific command is as follows: ver=1.1&cmd=getmsgex&seq=&uin= the server gets the agreement, if successful then return: ver=  1.1&cmd=getmsgex&seq=56661&uin= 29501213&res=0&mn=3&mt=99,9,9,&un=24 259132,24259132,24259132,&mg=30, ASDFASD fasdfasdf, Asdfasdfasdf,& MT represents a message type, 99 represents a system message, and 9 represents a user message. UN indicates that the message is sent to the source user, MG indicates the message sent, MG message can represent certain system meanings, for example: MT is 99, when MG is 30, 24259132 means user 4259132 is now UN in busy state, can be based on this message to the Friend list brush New, improve efficiency.

13. Send messages to Friends QQ
To send a message to a friend, to send a command to the server cltmsg command, the specific command is as follows: Ver=1.1&cmd=cltmsg&seq=&uin=&un=&m g= UN for the message sent to the user QQ number, MG for The message sent to the user. If the server gets the agreement, it returns if successful: Ver=1.1&cmd=cltmsg&seq=15 803&uin=415103947&res=0 Well, the above is QQ based on an incomplete protocol analysis of HTTP, Using the above agreement you can achieve a lot of things, such as: QQ robot, QQ advertising system, instant messaging integration tools and so on QQ protocol network Protocol--Request part
Login ver=1.0&cmd=login&seq=&uin=&ps=&m5= 1&lc=9326b87b234e7235//Get message VER=1.0&CMD= getmsgex&seq=&uin=//Send Message ver=1.0&cmd=cltmsg&seq=&uin=&un=&m G=//Friends List VER=1.0&CMD= List&seq=&uin=&tn=160&un = 0//Get friend status ver=1.0&cmd=query_stat&seq=&uin=&tn= 50& Un=0
Get friend Info Ver=1.0&cmd=getinfo&seq=&uin=&lv=2&u n=//Add friend ver=1.0&cmd=addtolist&seq=  &uin=&un=//respond to each other's requests and add your response to a friend Ver=1.0&cmd=ack_addtolist&seq=&uin=&u n=&cd=&rs=//delete friends Ver=1.0&cmd=delfromlist&seq=&uin=&un =//Search for Friends ver=1.0&cmd=finger&seq=&uin=&ag= &SX =&pv=//Change your status, ST's code should be consistent with get buddy status code ver=1.0&cmd=change_stat&seq=&uin=&st =//Sign out ver=1.0& Amp cmd=logout&seq=&uin=

QQ API Interface

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.