Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我需要一个PHP的XMPP库_Php_Xmpp - Fatal编程技术网

我需要一个PHP的XMPP库

我需要一个PHP的XMPP库,php,xmpp,Php,Xmpp,我不能使用composer(服务器在防火墙后面,PHP-download.com不工作) 特别是,我需要导出用户列表及其组 我已经尝试过了,但是它与PHP7不兼容,所以不能在服务器上使用composer。好的,但是为什么不在计算机上使用composer加载依赖项并上载供应商文件夹。那你就有你所需要的了 Composer将所有依赖项下载到供应商文件夹,并生成一些自动加载文件。上载孔项目时,它应该可以工作 $server=“此处的服务器名称”; $server = "SERVER NAME HE

我不能使用composer(服务器在防火墙后面,PHP-download.com不工作)

特别是,我需要导出用户列表及其组


我已经尝试过了,但是它与PHP7不兼容,所以不能在服务器上使用composer。好的,但是为什么不在计算机上使用composer加载依赖项并上载供应商文件夹。那你就有你所需要的了

Composer将所有依赖项下载到
供应商
文件夹,并生成一些自动加载文件。上载孔项目时,它应该可以工作

$server=“此处的服务器名称”;
$server   = "SERVER NAME HERE";
$username = "USER NAME HERE";
$password = "PASSWORD HERE";
$resource = "globe";
$streamid = "";

function vardump($data, $title = false){
    if($title){
        echo '<H2>' . $title . '</H2>';
    }
    echo '<PRE>';
    var_dump($data);
    echo '</PRE>';
}

function open_connection($server) {
    $connection = fsockopen($server, 5222, $errno, $errstr);
    if (!$connection) {
        print "$errstr ($errno)<br>";
        return false;
    }
    return $connection;
}

function send_xml($connection, $xml) {
    fwrite($connection, $xml);
}

function textcontains($text, $searchfor, $or = false){
    return stripos($text, $searchfor) !== false;
}

function send_recv_xml($connection, $xml, $size = 4096) {
    send_xml($connection, $xml);
    $data = recv_xml($connection, $size);
    $data["sent_xml"] = $xml;
    $data["sent_html"] = htmlspecialchars($xml);
    return $data;
}

function fread_untildone($connection, $size = 4096){
    $content = '';
    if($size < 0){
        while(!textcontains($content, '</iq>')){
            $content .= fread($connection, abs($size));
        }
    } else {
        $content = fread($connection, $size);
    }
    /*while(!feof($connection)){//did not work
        $content .= fread($connection, $size);
    }*/
    return $content;
}

function recv_xml($connection, $size = 4096) {
    $xml = fread_untildone($connection, $size);
    if ($xml === "") {
         return null;
    }
    // parses xml
    $xml_parser = xml_parser_create();
    xml_parse_into_struct($xml_parser, $xml, $val, $index);
    xml_parser_free($xml_parser);
    $RET = array($val, $index);
    $RET["originaldata"] = $xml;
    $RET["specialdata"] = htmlspecialchars($xml);
    $RET["time"] = time();
    return $RET;
}

function find_xmpp($connection, $tag, $value=null, &$ret=null) {
    static $val = null, $index = null;
    do {
        if ($val === null && $index === null) {
            list($val, $index) = recv_xml($connection);
            if ($val === null || $index === null) {
                return false;
            }
        }
        foreach ($index as $tag_key => $tag_array) {
            if ($tag_key === $tag) {
                if ($value === null) {
                    if (isset($val[$tag_array[0]]['value'])) {
                        $ret = $val[$tag_array[0]]['value'];
                    }
                    return true;
                }
                foreach ($tag_array as $i => $pos) {
                    if ($val[$pos]['tag'] === $tag && isset($val[$pos]['value']) &&
                        $val[$pos]['value'] === $value) {
                            $ret = $val[$pos]['value'];
                            return true;
                    }
                }
            }
        }
        $val = $index = null;
    } while (!feof($connection));

    return false;
}

function xmpp_connect($server, $username, $password, $resource = "globe") {
    global $streamid;
    $connection = open_connection($server);
    if (!$connection) {
        return false;
    }
    send_xml($connection, '<stream:stream xmlns:stream="http://etherx.jabber.org/streams" version="1.0" xmlns="jabber:client" to="' . $server . '" xml:lang="en" xmlns:xml="http://www.w3.org/XML/1998/namespace">');
    $data = recv_xml($connection);
    $streamid = $data[0][0]["attributes"]["ID"];
    //vardump($streamid, "stream id:");

    send_xml($connection, '<iq type="get" to="' . $server . '" id="auth1"><query xmlns="jabber:iq:auth"><username>' . $username . '</username></query></iq>');
    $data = recv_xml($connection);

    $XML = '<iq type="set" id="auth2"><query xmlns="jabber:iq:auth">';
    $fields = [];
    foreach($data[1] as $KEY => $VALUE){
        $KEY = strtolower($KEY);
        switch($KEY){
            case "username":    $VALUE = $username; break;
            case "password":    $VALUE = $password; break;
            case "digest":      $VALUE = strtolower(sha1($streamid . $password)); break;
            case "resource":    $VALUE = $resource; break;
            default: $VALUE = "";
        }
        $fields[ $KEY ] = $VALUE;
        if($VALUE){
            $XML .= '<' . $KEY . '>' . $VALUE . '</' . $KEY . '>';
        }
    }
    $XML .= '</query></iq>';
    //vardump($fields, "auth");

    $data = send_recv_xml($connection, $XML);
    //vardump($data, 'login');

    return $connection;
}

function xmpp_enum_users($connection, $server, $username, $resource = "globe"){
    //$XML = '<iq from="' . $username . '@' . $server . '/' . $resource . '" id="get-registered-users-list-1" to="' . $server . '" type="set" xml:lang="en">';
    //$XML .= '<command xmlns="http://jabber.org/protocol/commands" action="execute" node="http://jabber.org/protocol/admin#get-registered-users-list"/></iq>';

    /*$XML = '<iq from="' . $username . '" type="result" to="' . $username . '@' . $server . '/' .  $resource . '" id="123">
    <query xmlns="http://jabber.org/protocol/disco#items">
        <item jid="conference.localhost" />
        <item jid="pubsub.localhost" />
        <item jid="riot.localhost" />
        <item jid="vjud.localhost" />
        <item node="announce" name="Announcements" jid="localhost" />
        <item node="config" name="Configuration" jid="localhost" />
        <item node="user" name="User Management" jid="localhost" />
        <item node="online users" name="Online Users" jid="localhost" />
        <item node="all users" name="All Users" jid="localhost" />
        <item node="outgoing s2s" name="Outgoing s2s Connections" jid="localhost" />
        <item node="running nodes" name="Running Nodes" jid="localhost" />
        <item node="stopped nodes" name="Stopped Nodes" jid="localhost" />
    </query></iq>';*/
    global $streamid;
    $XML = '<iq from="' . $username . '@' . $server . '/' .  $resource . '" id="' . $streamid . '" type="get"><query xmlns="jabber:iq:roster"/></iq>';
    return send_recv_xml($connection, $XML, -4096);
}

function xmpp_disconnect($connection){
    fclose($connection);
}


$connection = xmpp_connect($server, $username, $password, $resource);
$data = xmpp_enum_users($connection, $server, $username, $resource);
$xml = simplexml_load_string($data["originaldata"]);
$users = [];
foreach($xml->query->item as $user){
    $username = $user->attributes()->name;
    $group = $user->group[0];
    $users[$username] = $group;
}

vardump($users, "users");
echo '<HR>' . json_encode($users);
echo '<HR>';
foreach($users as $username => $group){
    echo $username . '=' . $group . '<BR>';
}

xmpp_disconnect($connection);
$username=“此处的用户名”; $password=“此处密码”; $resource=“globe”; $streamid=“”; 函数vardump($data,$title=false){ 如果($标题){ 回显“.$title.”; } 回声'; var_dump($数据); 回声'; } 函数打开\u连接($server){ $connection=fsockopen($server,5222,$errno,$errstr); 如果(!$connection){ 打印“$errstr($errno)
”; 返回false; } 返回$connection; } 函数send_xml($connection,$xml){ fwrite($connection,$xml); } 函数textcontains($text,$searchfor,$or=false){ 返回stripos($text,$searchfor)!==false; } 函数send_recv_xml($connection,$xml,$size=4096){ 发送xml($connection,$xml); $data=recv_xml($connection,$size); $data[“sent_xml”]=$xml; $data[“sent_html”]=htmlspecialchars($xml); 返回$data; } 函数fread_untildone($connection,$size=4096){ $content=''; 如果($size<0){ 而(!textcontains($content,')){ $content.=fread($connection,abs($size)); } }否则{ $content=fread($connection,$size); } /*而(!feof($connection)){//不起作用 $content.=fread($connection,$size); }*/ 返回$content; } 函数recv_xml($connection,$size=4096){ $xml=fread_untildone($connection,$size); 如果($xml==“”){ 返回null; } //解析xml $xml\u parser=xml\u parser\u create(); xml_parse_为_结构($xml_parser,$xml,$val,$index); xml解析器免费($xml解析器); $RET=数组($val,$index); $RET[“originaldata”]=$xml; $RET[“specialdata”]=htmlspecialchars($xml); $RET[“time”]=time(); 返回$RET; } 函数find_xmpp($connection,$tag,$value=null,&$ret=null){ 静态$val=null,$index=null; 做{ 如果($val==null&&$index==null){ 列表($val,$index)=recv_xml($connection); 如果($val==null | |$index==null){ 返回false; } } foreach($tag\u key=>$tag\u数组的索引){ 如果($tag_key===$tag){ 如果($value==null){ if(isset($val[$tag_数组[0]]['value'])){ $ret=$val[$tag_数组[0]]['value']; } 返回true; } foreach($i=>$pos的标记数组){ 如果($val[$pos]['tag']==$tag&&isset($val[$pos]['value']))&& $val[$pos]['value']==$value){ $ret=$val[$pos]['value']; 返回true; } } } } $val=$index=null; }而(!feof($connection)); 返回false; } 函数xmpp_connect($server、$username、$password、$resource=“globe”){ 全球$streamid; $connection=打开连接($server); 如果(!$connection){ 返回false; } 发送xml($connection'); $data=recv_xml($connection); $streamid=$data[0][0][“attributes”][“ID”]; //vardump($streamid,“streamid:”); 发送xml($connection,“.$username.”); $data=recv_xml($connection); $XML=''; $fields=[]; foreach($data[1]作为$KEY=>$VALUE){ $KEY=strtolower($KEY); 交换机($KEY){ 案例“username”:$VALUE=$username;中断; 案例“password”:$VALUE=$password;中断; 案例“摘要”:$VALUE=strtolower(sha1($streamid.$password));中断; 案例“资源”:$VALUE=$resource;中断; 默认值:$VALUE=“”; } $fields[$KEY]=$VALUE; 如果(价值){ $XML.=''.$VALUE'.'; } } $XML.=''; //vardump($fields,“auth”); $data=send_recv_xml($connection,$xml); //vardump($data,'login'); 返回$connection; } 函数xmpp_enum_users($connection、$server、$username、$resource=“globe”){ //$XML=''; //$XML.=''; /*$XML='0 ';*/ 全球$streamid; $XML=''; 返回send_recv_xml($connection,$xml,-4096); } 功能xmpp\u断开($connection){ fclose($连接); } $connection=xmpp_connect($server、$username、$password、$resource); $data=xmpp\u enum\u用户($connection、$server、$username、$resource); $xml=simplexml_load_string($data[“originaldata”]); $users=[]; foreach($xml->query->item as$user){ $username=$user->attributes()->name; $group=$user->group[0]; $users[$username]=$group; } vardump($users,“users”); 回音“
”。json_编码($users); 回声“
”; foreach($username=>$group的用户){ 回显$username.'='.$group.'
'; } xmpp_断开($connection);

这是XMPP客户机的开始。我花了一段时间才找到要连接的基本代码,我注意到其他人要求这个,但没有得到它。

我还必须安装一个PHP服务器