PHP实现QQ挂机编程(2):取QQ在线状态
这是一个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 ( 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挂机的程序

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The usage of return in C language is: 1. For functions whose return value type is void, you can use the return statement to end the execution of the function early; 2. For functions whose return value type is not void, the function of the return statement is to end the execution of the function. The result is returned to the caller; 3. End the execution of the function early. Inside the function, we can use the return statement to end the execution of the function early, even if the function does not return a value.

This article brings you relevant knowledge about php+socket, which mainly introduces IO multiplexing and how php+socket implements web server? Friends who are interested can take a look below. I hope it will be helpful to everyone.

1. Socket programming based on TCP protocol 1. The socket workflow starts with the server side. The server first initializes the Socket, then binds to the port, listens to the port, calls accept to block, and waits for the client to connect. At this time, if a client initializes a Socket and then connects to the server (connect), if the connection is successful, the connection between the client and the server is established. The client sends a data request, the server receives the request and processes the request, then sends the response data to the client, the client reads the data, and finally closes the connection. An interaction ends. Use the following Python code to implement it: importso

Source code: publicclassReturnFinallyDemo{publicstaticvoidmain(String[]args){System.out.println(case1());}publicstaticintcase1(){intx;try{x=1;returnx;}finally{x=3;}}}#Output The output of the above code can simply conclude: return is executed before finally. Let's take a look at what happens at the bytecode level. The following intercepts part of the bytecode of the case1 method, and compares the source code to annotate the meaning of each instruction in

The first step on the SpringBoot side is to introduce dependencies. First we need to introduce the dependencies required for WebSocket, as well as the dependencies for processing the output format com.alibabafastjson1.2.73org.springframework.bootspring-boot-starter-websocket. The second step is to create the WebSocket configuration class importorg. springframework.context.annotation.Bean;importorg.springframework.context.annotation.Config

Solution to the problem that the php socket cannot be connected: 1. Check whether the socket extension is enabled in php; 2. Open the php.ini file and check whether "php_sockets.dll" is loaded; 3. Uncomment "php_sockets.dll".

With the development of the Internet, file transfer has become an indispensable part of people's daily work and entertainment. However, traditional file transfer methods such as email attachments or file sharing websites have certain limitations and cannot meet the needs of real-time and security. Therefore, using PHP and Socket technology to achieve real-time file transfer has become a new solution. This article will introduce the technical principles, advantages and application scenarios of using PHP and Socket technology to achieve real-time file transfer, and demonstrate the implementation method of this technology through specific cases. technology

Common network communication and security problems and solutions in C# In today's Internet era, network communication has become an indispensable part of software development. In C#, we usually encounter some network communication problems, such as data transmission security, network connection stability, etc. This article will discuss in detail common network communication and security issues in C# and provide corresponding solutions and code examples. 1. Network communication problems Network connection interruption: During the network communication process, the network connection may be interrupted, which may cause
