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

80酷酷网    80kuku.com

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

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

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


代码如下:

<?php
// 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, <0: error.
*/
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文件即可)

<script language=vbscript>

Function GetURL(url)

Set Retrieval = CreateObject("Microsoft.XMLHTTP")

With Retrieval

.Open "GET", url, False, "", ""

.Send

GetURL = .ResponseText

End With

Set Retrieval = Nothing

End Function

</script>


小图标:

<script language=vbscript>

Dim T,Start,Length,PicURL

T=GetURL("http://search.tencent.com/cgi-bin/friend/oicq_find?oicq_no=1924192")


Start=Instr(1,T,"ShowResult("+chr(34))

Start=Instr(Start,T,"http://")

Length=Instr(Start,T,chr(34)+","+chr(34))-Start

PicURL=Mid(T,Start,Length)

′document.write "<img src=′"&PicURL&"′>"

document.write "<a href=http://search.tencent.com/cgi-bin/friend/user_show_info?ln=1924192
target=_blank title=QQ:1924192><img src="&PicURL&" width=16
height=16 border=0></a>"

</script>


大图标:

<script language=vbscript>

Dim T,Start,Length,PicURL

T=GetURL("http://search.tencent.com/cgi-bin/friend/user_show_info?ln=1924192")


Start=Instr(1,T,"img height=32")

Start=Instr(Start,T,"http://")

Length=Instr(Start,T,chr(34)+" width=32")-Start

PicURL=Mid(T,Start,Length)

′document.write "<img src=′"&PicURL&"′>"

document.write "<a href=http://search.tencent.com/cgi-bin/friend/user_show_info?ln=1924192
target=_blank title=QQ:1924192><img src="&PicURL&" width=32
height=32 border=0></a>"

</script>


相关链接:

分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: