I recently used php to chat with QQ. you can search for QQ's http protocol on the internet. the implementation is very simple. I just tried it a little and wrote the following code, if anyone is interested, continue the study. If you have SDKs for j2_9 or major mobile phone manufacturers, it is good to study javaQQ. I want to take the test recently. I can only post it first. I want to explain it first. not all of them have been completed.
Code:
'1. 1', private $ ret; public function go () {$ this-> postValues = substr ($ this-> postValues, 0,-1 ); $ request = "post http/1.1 \ r \ n"; $ request. = "Host: $ this-> host \ r \ n"; $ length = strlen ($ this-> postValues); $ request. = "Content-Type: application/x-www-form-urlencoded \ r \ n"; $ request. = "Content-Length: $ length \ r \ n"; $ request. = "\ r \ n"; $ request. = $ this-> postValues; $ socket = fsockopen ($ this-> server, $ this-> p Ort, $ errno, $ errstr, $ this-> timeout); fputs ($ socket, $ request); $ ret = ''; while (! Feof ($ socket) {$ ret. = fgets ($ socket, 4096);} fclose ($ socket); $ this-> setRetValues ($ ret);} public function clearParams () {$ this-> postValues = ''; return true;} public function addParams ($ var, $ value) {$ this-> postValues. = urlencode ($ var ). "= ". urlencode ($ value ). '&';} public function setTimeout ($ timeout) {$ this-> timeout = $ timeout; return true;} public function setServer ($ server) {$ t His-> server = $ server; return true;} public function setHost ($ host) {$ this-> host = $ host; return true;} public function setPort ($ port) {$ this-> port = $ port; return true;} public function getRetValues () {parse_str (iconv ('utf-8', 'gb2312 ', $ this-> ret), $ arrValues); return $ arrValues; // return $ this-> ret;} private function setRetValues ($ ret) {$ this-> ret = $ ret; return ture ;}}?>
Query-> clearParams (); $ this-> query-> addParams ('Ver ', '1. 1 '); $ this-> query-> addParams ('cmd', 'login'); $ this-> query-> addParams ('seq ', rand (); $ this-> query-> addParams ('uin', $ this-> no); $ this-> query-> addParams ('ps ', $ this-> pass); $ this-> query-> addParams ('m5 ', '1'); $ this-> query-> addParams ('LC ', '9326b87b234e7235 '); $ this-> query-> go (); return $ this-> query-> getRetValues ();} public function getFriendList (){// VER = 1.1 & CMD = List & SEQ = & UIN = & TN = 160 & UN = 0 $ this-> query-> clearParams (); $ this-> query-> addParams ('Ver ', '1. 1 '); $ this-> query-> addParams ('cmd', 'list'); $ this-> query-> addParams ('seq ', rand (); $ this-> query-> addParams ('uin', $ this-> no); $ this-> query-> addParams ('tn ', '20140901'); $ this-> query-> addParams ('un', '0'); // $ this-> query-> addParams ('LC ', '9326b87b234e7235 '); $ this-> query-> go (); return $ this-> query-> getRetVal Ues ();} public function changeStat ($ st) {$ this-> query-> clearParams (); $ this-> query-> addParams ('Ver ', '1. 1 '); $ this-> query-> addParams ('cmd', 'change _ stat'); $ this-> query-> addParams ('seq ', rand (); $ this-> query-> addParams ('uin', $ this-> no); $ this-> query-> addParams ('st ', $ st); $ this-> query-> go (); return $ this-> query-> getRetValues (); // VER = 1.1 & CMD = Change_Stat & SEQ = & UIN = & ST = // ST indicates the status to be changed, 10 indicates Online, 20 indicates offline, and 30 indicates busy .} Public function getMsg () {// VER = 1.1 & CMD = GetMsgEx & SEQ = & UIN = $ this-> query-> clearParams (); $ this-> query-> addParams ('Ver ', '1. 1 '); $ this-> query-> addParams ('cmd', 'getmsgex'); $ this-> query-> addParams ('seq ', rand (1000,9000); $ this-> query-> addParams ('uin', $ this-> no); $ this-> query-> go (); return $ this-> query-> getRetValues ();} public function getUserInfo ($ user_no) {// VER = 1.1 & CMD = GetInfo & SEQ = & UIN = & LV = 2 & UN = $ this-> query-> clearParams (); $ this-> query-> addParams ('Ver ', '1. 1 '); $ this-> query-> addParams ('cmd', 'getinfo'); $ this-> query-> addParams ('seq ', rand (); $ this-> query-> addParams ('uin', $ this-> no); $ this-> query-> addParams ('lv ', '2'); $ this-> query-> addParams ('un', $ user_no); $ this-> query-> go (); echo time (). ''. (double) microtime (true ).'
'; // Echo $ user_no. 'OK'; // print_r ($ this-> query-> getRetValues ();} public function setQQInfo ($ no, $ pass) {$ this-> no = $ no; $ this-> pass = md5 ($ pass); return true;} public function setQuery ($ query) {$ this-> query = $ query; return true ;}}?>