PHP取QQ状态



<?php
// vim: set expandtab tabstop=4 shiftwidth=4 fdm=marker:
// +----------------------------------------------------------------------+
// | PHP Library.                                                         |
// +----------------------------------------------------------------------+
// | Copyright (c) 2004 Fishchen, China.                                  |
// +----------------------------------------------------------------------+
// | Authors: Fishchen, China.                                            |
// |          fishchen <fishchen#gmail.com>                               |
// +----------------------------------------------------------------------+
// $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<count($field); $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 );
}}} */


?>


你可能感兴趣的:(PHP,socket,qq,vim,Gmail)