If we use PHP to get QQ username and online status QQ does not provide us with API interface, if you want to get us through the QQ space or QQ Web version of the chat to achieve.
QQ by returning different pictures, to indicate online or offline, the icon also changed
Since the picture is different, then, the return of the HTTP header information in the Content-length also must be different, and, the color picture must be larger than the same dark color picture, so, to find a style of color and dark image of the middle value, Can reach the QQ online status by judging the length of the head return
Here is the code
The code is as follows |
Copy Code |
function Get_qq_status ($uin) { 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, below a better
code as follows |
copy code |
!--? 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,")) return (-1); if (! (Socket_write ($socket, $reques))) return (-1); if (! ($respon = Socket_read ($socket, 1024x768, Php_binary_read))) return (-1); Socket_close ($socket); $field = Explode ("rn", $respon); for ($i =0; $i if (strncasecmp ($field [$i], "Location:", 9) = = 0) { if (Strpo S ($field [$i], "online") { $ret = 1; } else if (Strpos ($field [$i], "offline")) { $ret = 0; } else { $ret =-1; }//if break; }//If }//For return ($ret); } /*}}} */ echo Tphp_qq_online (561272831); ?> |
Example, QQ user nickname and online status
The code is as follows |
Copy Code |
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 ';//Pre-set $username = $QQARR [$QQ]; if (! $username) { $username = Getqqnick ($QQ); } return $username; } |
http://www.bkjia.com/PHPjc/633157.html www.bkjia.com true http://www.bkjia.com/PHPjc/633157.html techarticle If we use PHP to get QQ username and online status QQ does not provide us with API interface, if you want to get us through the QQ space or QQ Web version of the chat to achieve. QQ by return different ...