Home > Backend Development > PHP Tutorial > PHP gets QQ user nickname and online status (example analysis)_PHP tutorial

PHP gets QQ user nickname and online status (example analysis)_PHP tutorial

WBOY
Release: 2016-07-13 10:25:53
Original
1156 people have browsed it

QQ indicates online or offline by returning different pictures, and the icons also change accordingly. Since the pictures are different, the Content-Length in the returned HTTP header information must also be different, and the color pictures must be better than the same The dark picture of the subtitle should be larger, so by finding the intermediate value between the color and dark pictures of a certain style, you can obtain the QQ online status by judging the return length of the header
The following is the code

Copy code The code is as follows:

{
error_reporting(0);
$f=file_get_contents('http://wpa.qq.com/pa?p=1:'.$uin.':4');
if(!$f) return(true);
foreach($http_response_header as $val)
{
if(strpos($val,'Content-Length')!==false)
{
return(intval(substr($val, 16,50))>1000);
}
}
}

?>


The above is relatively simple, here is a better one
Copy the code The code is as follows:

function tphp_qq_online( $uin )
{
$reques = "GET /pa?p=1:".$uin.":1 HTTP/1.1rn ";
$reques .= "Host: wpa.qq.comrn";
$reques .= "User-Agent: PHP_QQ_SPYrnrn";

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( "rn", $respon );
for ( $i=0; $i if ( Strncasecmp ($ field [$ i], "local:", 9) == 0) {
if ($ field [$ i], "online") {
$ RET = 1;
         } else if ( strpos( $field[$i], "offline") ) {                                                                                                               } // if
               break; 🎜>

echo tphp_qq_online( 561272831 );

?>


Example, qq user nickname and online status



Copy code
The code is as follows:

//Get QQ status
function getQQState($qq){

$url ='http://wpa.qq.com/pa?p=2:'.$qq.': 41&r=' . time ();
$headInfo = get_headers($url,1);
$length = $headInfo['Content-Length'];
if ($length==1243) { return true; }else { return false; }
}
//Get QQ nickname
function getQQNick($qq){
$str = file_get_contents('http://r.qzone.qq.com/cgi-bin/user/cgi_personal_card?uin='.$qq);
$pattern = '/'.preg_quote('"nickname":"' ,'/').'(.*?)'.preg_quote('",','/').'/i';
preg_match ( $pattern,$str, $result );
return $result[1];
}
//Get QQ name
function getQQName($qq){
//$qqArr = include 'friendArr.php';//Preset
//$username = $qqArr[$qq];
if (!$username) {
$username = getQQNick($qq);
}
return $username;
}






http://www.bkjia.com/PHPjc/824918.html

www.bkjia.com

true

http: //www.bkjia.com/PHPjc/824918.html
TechArticle

QQ returns different pictures to indicate online or offline, and the icons also change accordingly. Since the pictures are different, then , the Content-Length in the returned HTTP header information must also be different, and the color pictures...

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template