[PHP]QQ在线状态检测API

4 Comments

之前需要为了一个项目需要一个QQ状态检测的API,在网上找了个遍。发现有一些第三方的API、也找到了腾讯官方的API:
http://webpresence.qq.com/getonline?Type=1&qqnum:
但是发现这些API都不够完美,只能检测到电脑在线的用户。Google了很久,找到了一段Python代码,发现wpa.qq.com返回的在线状态图片的Http Header部分可以读取到在线状态。Content-Length为2262时是离线或隐身,2329时是在线。下面为API的代码。

/**
 * QQ在线状态检测API
 * ============================================================================
 * * 版权所有 1992-???? 梅达华,并保留所有权利。
 * 网站地址: http://www.meidahua.com;
 * ----------------------------------------------------------------------------
 * 本软件使用BY-NC-SA 3.0 许可进行授权,您能在不用于商业目的的前提下对程序代码
 * 进行修改和使用;允许对程序代码以任何形式任何目的的再发布,但必须保留原版权
 * 信息。
 * ============================================================================
 * $Author: MeiDaHua $
*/
		function php_qq_status($qqnum) {
			  $url='http://wpa.qq.com/pa?p=1:'.$qqnum.':1';
			  $curl = curl_init();
			  curl_setopt($curl, CURLOPT_URL, $url);
			  curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
			  curl_setopt($curl, CURLOPT_HEADER, 1);
			  curl_setopt($curl, CURLOPT_NOBODY, 1);
			  curl_setopt($curl, CURLOPT_ENCODING, "gzip, deflate");
			  $data=curl_exec($curl);
			  curl_close($curl);
			  $status=explode("Content-Length: ",$data);
			  $status=explode("\r\n",$status[1]);
			  if ($status[0]=="2262"){
			  $result="0";}
			  elseif ($status[0]=="2329"){
			  $result="1";}
			  else{
			  $result="2";}
			  return $result;
		}
$qqnum=$_GET["qq"];
echo php_qq_status($qqnum);

这个API,保存为php_qq_status.php后,访问php_qq_status.php?qq=QQ号即可。返回0为离线或隐身,返回1为在线,返回2为接口出错。

4 Thoughts on “[PHP]QQ在线状态检测API

回复 windknight

您的电子邮箱地址不会被公开。 必填项已用 * 标注