• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            Fork me on GitHub
            隨筆 - 215  文章 - 13  trackbacks - 0
            <2021年9月>
            2930311234
            567891011
            12131415161718
            19202122232425
            262728293012
            3456789


            專注即時通訊及網(wǎng)游服務(wù)端編程
            ------------------------------------
            Openresty 官方模塊
            Openresty 標(biāo)準(zhǔn)模塊(Opm)
            Openresty 三方模塊
            ------------------------------------
            本博收藏大部分文章為轉(zhuǎn)載,并在文章開頭給出了原文出處,如有再轉(zhuǎn),敬請保留相關(guān)信息,這是大家對原創(chuàng)作者勞動成果的自覺尊重!!如為您帶來不便,請于本博下留言,謝謝配合。

            常用鏈接

            留言簿(1)

            隨筆分類

            隨筆檔案

            相冊

            Awesome

            Blog

            Book

            GitHub

            Link

            搜索

            •  

            積分與排名

            • 積分 - 215339
            • 排名 - 118

            最新評論

            閱讀排行榜

            來自 Csdn https://blog.csdn.net/nassue_sn

            XMPP相關(guān)資料:https://blog.csdn.net/nassue_sn/article/category/6635474
            Ejabberd相關(guān)資料:https://blog.csdn.net/nassue_sn/article/category/6601126


            群聊離線消息實現(xiàn):http://www.cnblogs.com/lovechengcheng/p/4083398.html

            簡單集群搭建:https://blog.csdn.net/yongche_shi/article/details/52956125

            C#連接ejabberd2.1.x —— agsxmpp
            注冊新賬戶方法:(偽碼)

                        XmppClientConnection xmppCon;
                        xmppCon.RegisterAccount = true; // 設(shè)為true代表是新用戶注冊
                        xmppCon.OnRegistered += (sender) => {
                            // 新用戶注冊成功
                        };
                        xmppCon.OnRegisterError += (sender, e) => {
                            // 老用戶重復(fù)注冊
                        };
                        xmppCon.Open();

























            ----------------------------------------- 下方內(nèi)容因版本不匹配暫時廢棄 --------------------------------------------------


            PHP通過xmlrpc注冊ejabberd用戶

            http://www.bubuko.com/infodetail-551255.html

            正在研發(fā)一款社交軟件,架構(gòu)im使用了ejabberd作為xmpp服務(wù)器,于是遇到了如何通過php注冊xmpp用戶的問題。
            解決方法有幾個:
            1.用xmpphp框架發(fā)送含<body>元數(shù)據(jù)的消息到服務(wù)器要求處理,這個可參考:http://blog.csdn.net/newjueqi/article/details/7864066
            //1、測試文件 adduser.php

            include_once './XMPPHP/XMPP.php';

            $conn = new XMPPHP_XMPP($host, 5222, $xmppUserName$xmppPassword,  'xmpphp', 'svn.zhaoduila.net', false);

            try {
                $conn->connect();

                //發(fā)送好友請求、發(fā)送消息、刪除好友   需要以下兩行
                $conn->processUntil('session_start');
                $conn->presence();


                //添加用戶 
            //    $conn->registerNewUser($xmppUserName, $xmppPassword, $email);

                //發(fā)送消息 
            //    $conn->message('liuruikang1@svn.zhaoduila.net', 'This is a test message!');

                //發(fā)送好友請求
            //    $conn->addRosterContact($jid, $name);

                //刪除好友

                $conn->deleteRosterContact($jid);

                $conn->disconnect();


            catch (XMPPHP_Exception $e) {
                die($e->getMessage());
            }

            //2、我是直接把方法追加到  XMPP.php  文件中的

            /**
              * Register a new user.
              *
              * @param $entity
              * Entity we want information about
              
            */
              public function registerNewUser($username$password = NULL$email){
                if (!isset($password))
                    $password = $this->genRandomString(15);

                $id = 'reg_' . $this->getID();
                $xml = "<iq type='set' id='$id'>
                            <query xmlns='jabber:iq:register'>
                                <username>" . $username . "</username>
                                <password>" . $password . "</password>
                                <email>" . $mail . "</email>
                                <name></name>
                            </query>
                        </iq>";
                $this->addIdHandler($id, 'register_new_user_handler');
                $this->send($xml);
              }


              /**
              * Handler for new user registration
              *
              * @param XML Object $xml
              
            */
              public function register_new_user_handler($xml){
                      //dpm($xml);
                      //var_dump($xml);

                      switch ($xml->attrs['type']) {
                        case 'error':
                          $this->event('new_user_registered', 'error');
                          break;
                        case 'result':
                            // dpm($xml->subs);
                            $query = $xml->sub('query');
                            $username='';
                            $password='';
                            if(!is_array($query->subs)) {
                                foreach ($query->sub as $key => $value) {
                                    switch ($value->name) {
                                        case 'username':
                                            $username = $value->data;
                                            break;

                                        case 'password':
                                            $password = $value->data;
                                            break;
                                    }
                                }
                            }
                            $this->event('new_user_registered', array('jid' => $username . "@{$this->server}", 'password' => $password));
                        default:
                            $this->event('new_user_registered', 'default');
                    }
              }

              /**
               * Add contact to your roster
               
            */
              public function addRosterContact($jid$name$groups = array()){
                  // return if there is no jid specified
                  if(!$jidreturn;
                  // set name to the jid if none is specified
                  if (!$name) { $name = $jid; }
                  $id = $this->getID();
                  $xml = "<iq type='set' id='$id'>";
                  $xml .= "<query xmlns='jabber:iq:roster'>";
                  $xml .= "<item jid='$jid' name='$name'>";
                  foreach ($groups as $group) {
                          $xml .= "<group>$group</group>";
                  }
                  $xml .= "</item>";
                  $xml .= "</query>";
                  $xml .= "</iq>";
                  $xml .= "<presence to='" . $jid . "' type='subscribe'/>";
                  $this->addIdHandler($id, 'add_roster_contact_handler');
                  $this->send($xml);
              }

              /**
              * @param XML Object $xml
              
            */
              protected function add_roster_contact_handler($xml) {
                // do anything you wish here
                $this->event('contact_added');
              }

              /**
              *
              * @param $jid
              *       Contact you wish to remove
              
            */
             
              public function deleteRosterContact($jid) {
                $id = $this->getID();
                $xml = "<iq type='set' id='$id'>";
                $xml .= "<query xmlns='jabber:iq:roster'>";
                $xml .= "<item jid='" . $jid . "' subscription='remove' />";
                $xml .= "</query>";
                $xml .= "</iq>";
                $this->addIdHandler($id, 'delete_roster_contact_handler');
                $this->send($xml);
              }

              /**
              *
              * @param XML Object $xml
              
            */
              protected function delete_roster_contact_handler($xml) {
                // do any handling you wish here
                $this->event('contact_removed');
              }


                  function genRandomString($length){
                    $str='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
                    $len=strlen($str)-1;
                    $randstr='';
                    for($i=0;$i<$length;$i++){
                        $num=mt_rand(0,$len);
                        $randstr .= $str[$num];
                    }
                    return $randstr;
                  }
            2.使用php的xmpp庫jaxl,其demo代碼中包含一個register_user的腳本,通過shell調(diào)用:
            php example/register_user.php YOUR_DOMAIN
            即可生成用戶,缺點是性能較差且慢,不建議
            3.最優(yōu)方法是使用ejabberd自帶的命令行工具ejabberdctl來直接生成用戶。網(wǎng)上的回答基本是通過修改sudo用戶組權(quán)限來直接在php使用exec語句來執(zhí)行此命令
            $username = ‘tester‘;
            $password = ‘testerspassword‘;
            $node = ‘myserver.com‘;
            exec(‘sudo /usr/sbin/ejabberdctl register ‘.$username.‘ ‘.$node.‘ ‘.$password.‘ 2>&1‘,$output,$status);
            if($output == 0)
            {
                // Success!
            }
            else
            {
                // Failure, $output has the details
                echo ‘<pre>‘;
                foreach($output as $o)
                {
                    echo $o."\n";
                }
                echo ‘</pre>‘;
            }
            需要在sudoer文件中添加ejabberd用戶權(quán)限,相對不安全也比較麻煩,也不推薦。
            4.其實ejabberd在最近的版本中已經(jīng)集成了xmlrpc模塊,通過該模塊可直接訪問4560端口使用ejabberd的一些內(nèi)部命令。官網(wǎng)介紹地址:https://www.ejabberd.im/ejabberd_xmlrpc
            修改ejabberd.yml配置文件:

            listen:
              -
                port: 4560
                ip: "::"
                module: ejabberd_xmlrpc
                access_commands:
                  xmlrpc_access:
                    commands: all
                    options: []

            ..

            commands_admin_access: xmlrpc_access

            ..

            access_rules:
              xmlrpc_access:
                - allow: xmlrpc_acl

            ..

            api_permissions:
              "console commands":
                from:
                  - ejabberd_ctl
                who: all
                what: "*"
              "admin access":
                who:
                  - access:
                      - allow:
                        - acl: loopback
                        - acl: all
                  - oauth:
                    - scope: "ejabberd:admin"
                    - access:
                      - allow:
                        - acl: loopback
                        - acl: all

            重啟后 telnet HOST地址 4560 看能否接通,即說明xmlrpc已經(jīng)可以用了:
            關(guān)于php端的代碼在介紹地址中已有提及,以下是php通過ejabberdctl注冊一個用戶的demo的代碼:
            $params=array('user'=>'someUser','host'=>'ejabberdHost','password'=>'somPassword');
            $request = xmlrpc_encode_request('register', $params, (array('encoding' => 'utf-8')));

            $context = stream_context_create(array('http' => array(
                'method' => "POST",
                'header' => "User-Agent: XMLRPC::Client mod_xmlrpc\r\n" .
                "Content-Type: text/xml\r\n" .
                "Content-Length: ".strlen($request),
                'content' => $request
                )));

            $file = file_get_contents("http://127.0.0.1:4560", false$context);

            $response = xmlrpc_decode($file);

            if (xmlrpc_is_fault($response)) {
                trigger_error("xmlrpc: $response[faultString] ($response[faultCode])");
            else {
                print_r($response);
            }
            打印后即生成注冊成功的結(jié)果
            Have a nice try! :)

            Linux安裝php-xmlrpc擴(kuò)展:
            cd php-5.4.16/ext/xmlrpc
            /usr/local/php/bin/phpize
            ./configure --with-php-config=/usr/local/php/bin/php-config --with-xmlrpc=shared --with-libxmlrpc=/usr/local
            make
            make install

            添加到php.ini擴(kuò)展即可

            更多參考:
            https://github.com/processone/ejabberd/issues/1231
            https://github.com/processone/ejabberd/issues/1749
            https://github.com/processone/ejabberd/issues/1568
            https://bugs.php.net/bug.php?id=19124
            https://www.ejabberd.im/ejabberd_xmlrpc/
            https://blog.csdn.net/kenkao/article/details/53333595
            https://blog.csdn.net/u012930316/article/details/55251903

            https://www.cnblogs.com/--00/p/erlang_into_style.html
            posted on 2019-02-12 09:34 思月行云 閱讀(937) 評論(0)  編輯 收藏 引用 所屬分類: Erlang
            青青青国产精品国产精品久久久久| 国产99久久九九精品无码| 一本一道久久a久久精品综合| 久久精品亚洲男人的天堂| 久久免费观看视频| 色8久久人人97超碰香蕉987| 亚洲欧美精品伊人久久| 欧美亚洲国产精品久久高清| 久久精品aⅴ无码中文字字幕重口| 久久99中文字幕久久| 日韩一区二区三区视频久久| 99精品国产99久久久久久97| 97精品国产97久久久久久免费| 亚洲Av无码国产情品久久| 久久精品国产亚洲AV无码娇色| 久久99亚洲综合精品首页| 新狼窝色AV性久久久久久| 国产女人aaa级久久久级| 亚洲欧美日韩久久精品第一区| 99久久99久久精品国产片果冻| 伊人久久久AV老熟妇色| 九九热久久免费视频| 久久国产乱子伦免费精品| 欧美日韩精品久久久免费观看| 久久精品国产秦先生| 久久久无码一区二区三区| 日韩精品久久久久久久电影| 99热成人精品免费久久| 99re这里只有精品热久久| 久久国产高潮流白浆免费观看| 超级97碰碰碰碰久久久久最新| 久久露脸国产精品| 久久精品国产亚洲一区二区三区| 国产美女久久久| 97精品久久天干天天天按摩| 亚洲国产精品成人久久| 国产精品99久久久精品无码| 久久毛片一区二区| 久久久久久久久波多野高潮| 久久久久久久女国产乱让韩| 久久国产精品偷99|