朋友网关于QQ相关的PHP代码(研究QQ的绝佳资料)(7)

function logout()
    {
        //退出登陆
        //VER=1.1&CMD=Logout&SEQ=&UIN=
        $str = "VER=1.1&CMD=Logout&SEQ=".rand(1000,9000)."&UIN=".$this->uin;
        $return = $this->encode($this->query($str));
        if($return['RES']==0 and $return['UIN'] == $this->uin)
        {
            //服务器成功得到信息
            return QQ_RETURN_SUCCESS;
        }
        else
        {
            //失败
            return QQ_RETURN_FAILED;
        }
    }

function getMsg()
    {
        //获得消息
        //VER=1.1&CMD=GetMsgEx&SEQ=&UIN=
        //MT表示消息类型,99表示系统消息,9表示用户消息。UN表示消息发送来源用户,MG表示发送的消息,MG消息可以表示某些特定的系统含意
        //当MT=99时:MG=10表示用户上线,MG=20表示用户离线,MG=30表示用户忙碌
        $str = "VER=1.1&CMD=GetMsgEx&SEQ=".rand(1000,9000)."&UIN=".$this->uin;
        $return = $this->encode($this->query($str));
        if($return['RES']==0 and $return['UIN'] == $this->uin)
        {
            //服务器成功得到信息
            if($return['MN'] > 0)
            {
                //消息数>0
                $mts = $this->split_str($return['MT']);    //消息类型
                $uns = $this->split_str($return['UN']); //发送者号码
                $mgs = $this->split_str($return['MG']); //消息内容
                $error = 0;
                (count($mts)==count($uns))==(count($uns)==count($mgs))?
                    $num = count($uns)
                    :
                    $error = 1;
                ;
                if($error == 1) return QQ_GETMSG_ERROR;    //出差错了
                $arr = array();
                for($i=0;$i<$num;$i++)
                {
                    $arr[] = array(
                        "MT" => $mts[$i] ,
                        "UN" => $uns[$i] ,
                        "MG" => $this->utf8_to_gb2312($mgs[$i])
                    );
                }
                return ($arr);
            }
            else
            {
                //在线好友数<=0
                return QQ_GETMSG_NONE;
            }
        }
        else
        {
            //失败
            return QQ_RETURN_FAILED;
        }
    }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/e7cf048b808aaaaf76e4422e219f844a.html