zoukankan      html  css  js  c++  java
  • 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();
    
  • 相关阅读:
    poj 3280 Cheapest Palindrome(区间DP)
    POJ 2392 Space Elevator(多重背包)
    HDU 1285 定比赛名次(拓扑排序)
    HDU 2680 Choose the best route(最短路)
    hdu 2899 Strange fuction (三分)
    HDU 4540 威威猫系列故事――打地鼠(DP)
    HDU 3485 Count 101(递推)
    POJ 1315 Don't Get Rooked(dfs)
    脱离eclipse,手动写一个servlet
    解析xml,几种方式
  • 原文地址:https://www.cnblogs.com/fsong/p/6207973.html
Copyright © 2011-2022 走看看