Home > php教程 > php手册 > PHP实现QQ挂机编程(2):取QQ在线状态

PHP实现QQ挂机编程(2):取QQ在线状态

WBOY
Release: 2016-06-21 08:59:06
Original
895 people have browsed it

  这是一个PHP取QQ在线状态程序。原理很简单,省略不说了,可以看代码。用的是互动状态这个服务去取状态的。

  用法也简单,传入的参数为QQ号码,函数返回1则表示QQ在线,函数返回0则表示QQ不在线,返回小于0则表示出错。

  注:需要QQ是用QQ2004II beta1或以上版本登陆才可以检测得到。


代码如下:

// vim: set expandtab tabstop=4 shiftwidth=4 fdm=marker:
// | Copyright (c) 2004 Fishchen, China.
// | Authors: Fishchen, China.
// $Id$

/**
* @note License: GNU General Public License (GPL) version 2
* @file $RCSfile$
* @version 1.0
* @author fishchen
* @date 2004/12/24 11:00:00 (Merry Xmas)
* @brief Get QQ Online Status.
*/

/* {{{ function tphp_qq_online( $uin ) */
/**
* Get QQ online status.
*
* @note Need user login QQ with QQ2004IIbeta1 or laster.
* @param int $uin QQ Number.
* @retval int $ret 1: online, 0: offline, */
function tphp_qq_online( $uin )
{
$reques = "GET /pa?p=1:".$uin.":1 HTTP/1.1\r\n";
$reques .= "Host: wpa.qq.com\r\n";
$reques .= "User-Agent: PHP_QQ_SPY\r\n\r\n";

if ( !( $socket = socket_create( AF_INET, SOCK_STREAM, SOL_TCP ) ) ) return(-1);
if ( !( socket_connect( $socket, "wpa.qq.com", 80 ) ) ) return(-1);
if ( !( socket_write( $socket, $reques ) ) ) return(-1);
if ( !( $respon = socket_read( $socket, 1024, PHP_BINARY_READ ) ) ) return(-1);;
socket_close( $socket );

$field = explode( "\r\n", $respon );
for ( $i=0; $i if ( strncasecmp($field[$i], "Location:", 9) == 0 ) {
if ( strpos( $field[$i], "online") ) {
$ret = 1;
} else if ( strpos( $field[$i], "offline") ) {
$ret = 0;
} else {
$ret = -1;
} // if
break;
} // if
} // for

return( $ret );
}
/* }}} */

/* {{{ sample:
echo tphp_qq_online( 80000800 );
}}} */

?>


注:以上为抛砖引玉,各位可以以此参照写出其他语言的版本;

附:不用程序,得到一个用户QQ在线状态(把下面代码另存为一个.htm文件即可)


小图标:


大图标:


相关链接:用php实现qq挂机的程序



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template