首页 > 开发 > PHP > 正文

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

2024-05-04 23:04:37
字体:
来源:转载
供稿:网友
  这是一个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>


相关链接:用php实现qq挂机的程序
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表