• 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();
    
  • 相关阅读:
    冒泡 选择 二分法 算法 排序算法
    VUE -->html
    tlplayer for wince 版本正式商用
    XBMC 最新版本错误
    libvlc 双击,鼠标事件消息响应
    windows平台下VLC2.0.5编译
    Fedora 17下交叉编译vlc-2.0.6-win32小记
    wzplayer for ios 针对(mms)优化版本V1.0
    wzplayer2 for windows ActiveX 试用地址
    wzplayer,tlplayer支持ActiveX
  • 原文地址:https://www.cnblogs.com/fsong/p/6207973.html
Copyright © 2020-2023  润新知