Home  >  Article  >  Backend Development  >  PHP快速准确的检测QQ是否在线类

PHP快速准确的检测QQ是否在线类

WBOY
WBOYOriginal
2016-06-20 13:00:58832browse

PHP快速准确的检测QQ是否在线类

昨天我需要这个功能,就在网上找了一下,基本没有用。很多都是几年前发的代码。

就自己写了一个类,现在分享给大家。

相信大家都知道腾讯有一个QQ在线状态,临时会话的那个服务。

在线就显示在线的图标,否则就显示离线的图标。


我就是根据判断这个写的代码。

<?php
/*@
 *@
 *@ Time:2013-5-2
 *@
 *@ Name:qqwp.php
 */
//header("Content-type:text/html; Charset=UTF-8");
function qq_status(){
    if (empty($qq))$qq = 429590191;
    $url = 'http://wpa.qq.com/pa?p=2:'.$qq.':52';
    $Headers = get_headers($url, 1);
    if ($Headers['Location']=='http://pub.idqqimg.com/qconn/wpa/button/button_121.gif'){
        $Status = 1;  //QQ在线
    }elseif ($Headers['Location']=='http://pub.idqqimg.com/qconn/wpa/button/button_120.gif'){
        $Status = 2;  //QQ离线
    }else {
        $Status = 0;  //未知
    }
    Return $Status;
}
//测试数据
$qqwp = qq_status('429590191');  //测试QQ是否在线,返回1=在线,返回2=离线,返回0=错误
if ($qqwp==1){
    echo 'QQ在线';
}elseif ($qqwp==2){
    echo 'QQ离线';
}else {
    echo '出错了';
}
?>

 


Statement:
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