PHP實現QQ掛機編程(2):取QQ線上狀態

來源:互聯網
上載者:User
  這是一個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掛機的程式

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.