我也是最近才看到的,大家可以到网上搜索一下qq的http协议,实现很简单,我只是稍微试了一下,写了以下几段代码,如果哪位有兴趣可以继续研究。如果有j2me或者各大手机厂商的sdk,研究一下javaqq也不错。最近要考试,只能先贴出来,先说明,未全部完成
代码:
<?php
class query {
private $timeout; // = 100; // max time for stablish the conection
private $server; // = '219.133.51.11';//'219.133.51.11'; // ip address
private $host; // = 'tqq.tencent.com'; // domain name
private $port; // = 8000;
private $postvalues; // = array ( 'ver' => '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->port, $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 ) {
$this->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;
}
}
?>
<?php
class qq {
private $query;
private $no;
private $pass;
public function login() {
$this->query->clearparams();
$this->query->addparams('ver','1.1');
$this->query->addparams('cmd','login');
$this->query->addparams('seq',rand(1000,9000));
$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(1000,9000));
$this->query->addparams('uin',$this->no);
$this->query->addparams('tn','160');
$this->query->addparams('un','0');
//$this->query->addparams('lc','9326b87b234e7235');
$this->query->go();
return $this->query->getretvalues();
}
public function changestat($st) {
$this->query->clearparams();
$this->query->addparams('ver','1.1');
$this->query->addparams('cmd','change_stat');
$this->query->addparams('seq',rand(1000,9000));
$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为要改变的状态,10为上线,20为离线,30为忙碌。
}
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(1000,9000));
$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).'<br>';
//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;
}
}
?>