• JAXL连接Openfire发送房间消息


    使用composer形式安装的JAXL

    <?php
    require_once "vendor/autoload.php";
    $client = new JAXL(array(
        'jid' => '',
        'pass' => '',
        'host'=>'ubuntu',
        'auth_type'=>'ANONYMOUS', //匿名登录
        'log_level' => JAXLLogger::DEBUG,
    ));
    
    $_room_full_jid = "test@conference.ubuntu/ordersender";
    $room_full_jid = new XMPPJid($_room_full_jid);
    
    
    $client->require_xep(array(
        '0045',     // MUC
        '0203',     // Delayed Delivery
        '0199',  // XMPP Ping
    ));
    
    $client->add_cb('on_auth_success', function() {
        global $client, $room_full_jid;
        // set status
        $client->set_status("available!",'dnd',10);
    
         $client->get_vcard();               // fetch your vcard
        $client->get_roster();              // fetch your roster list
    
        JAXLLogger::info("got on_auth_success cb, jid ".$client->full_jid->to_string());
        JAXLLogger::info("got on_auth_success cb, room_full_jid ".$room_full_jid->to_string());
        // join muc room
        $client->xeps['0045']->join_room($room_full_jid);
    
        //start send message
        //@link http://wiki.jabbercn.org/XEP-0045#.E5.8F.91.E9.80.81.E6.B6.88.E6.81.AF.E7.BB.99.E6.89.80.E6.9C.89.E6.88.BF.E5.AE.A2 例子60的xml格式
        //@link JAXL 文档 https://jaxl.readthedocs.io/en/latest/users/xml_objects.html
        $xml = new JAXLXml('message');
        $_room_full_jid2 = "test@conference.ubuntu";
    	$to2 = new XMPPJid($_room_full_jid2);
        $xml->attrs(array(
        	'from'=>$client->full_jid->to_string(),
        	'to'=>$to2->to_string(),
        	'type'=>'groupchat'
        	));
        $xml->c('body')->t('Hello world');
        //xml<message from="244a387a@ubuntu/244a387a" to="test@conference.ubuntu" type="groupchat"><body>Hello world</body></message>
        JAXLLogger::info("xml".$xml->to_string());
        $client->send($xml); //发送消息
        $client->send_end_stream(); //断开连接
        
    });
    
    function on_auth_failure_callback($reason)
    {
        global $client;
        $client->send_end_stream();
        JAXLLogger::info("got on_auth_failure cb with reason $reason");
    }
    $client->add_cb('on_auth_failure', 'on_auth_failure_callback');
    
    
    
    function on_disconnect_callback()
    {
        JAXLLogger::info("got on_disconnect cb");
    }
    $client->add_cb('on_disconnect', 'on_disconnect_callback');
    
    
    
    $client->start();
    
  • 相关阅读:
    kafka 消息推送报错"dial tcp: lookup iZ2ze2k3******7abjcsyZ on 219.141.140.10:53: no such host"
    MacBook安装Homebrew的国内安装脚本 告别龟速下载安装
    docker info命令的使用和返回结果描述
    Python requests.post方法中data与json参数区别
    redis master-slave python switch logic (升级版,序列七)
    ELKF日志收集系统
    MySQL 中的concat函数使用
    程序员的街舞“梦”
    第一份工作没有工资,信不信
    Java中的享元设计模式,涨姿势了!
  • 原文地址:https://www.cnblogs.com/fsong/p/6207973.html
Copyright © 2020-2023  润新知