<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                這里進行數據庫的記錄操作,很簡單。 在Events.php文件里onMessage方法添加幾句代碼就行 ~~~ public static function onMessage($client_id, $message) { // 向所有人發送 $message_data = json_decode($message,true); if(!$message_data){ return; } switch($message_data['type']){ case "bind": $fromid = $message_data['fromid']; Gateway::bindUid($client_id, $fromid); return; case "say": $text = nl2br(htmlspecialchars($message_data['data'])); $fromid = $message_data['fromid']; $toid = $message_data['toid']; $date=[ 'type'=>'text', 'data'=>$text, 'fromid'=>$fromid, 'toid'=>$toid, 'time'=>time() ]; echo "datasend".$fromid."\n"; echo "datasend".$toid."\n"; //判斷用戶是否在線,在線給數據庫添加1記錄值為已讀 if(Gateway::isUidOnline($toid)){ //發送消息給接受用戶 Gateway::sendToUid($toid,json_encode($date)); $date['isread']= 1; }else{ $date['isread']= 0; } //修改數組type為save,發送到自己的接收信息函數上進行數據保存操作 $date['type'] = "save"; Gateway::sendToUid($fromid,json_encode($date)); return; } } ~~~ 這里是html代碼: ``` var fromid = 13; // var toid = 12; var API_URL = "http://localhost/tchat/public/index.php/api/api/"; var ws = new WebSocket("ws://192.168.0.102:8282"); // var ws = new WebSocket("ws://192.168.10.51:8282"); ws.onmessage = function(e){ var message = eval("("+e.data+")"); switch (message.type){ case "init": var bild = '{"type":"bind","fromid":"'+fromid+'"}'; ws.send(bild); return; case "text": console.log(message); if(toid==message.fromid) { $(".chat-content").append(' <div class="chat-text section-left flex"><span class="char-img" style="background-image:"></span> <span class="text"><i class="icon icon-sanjiao4 t-32"></i>' + message.data + '</span> </div>'); } return; case "save": save_message(message); return; } // $(".chat-content").append(' <div class="chat-text section-left flex"><span class="char-img" style="background-image: "></span> <span class="text"><i class="icon icon-sanjiao4 t-32"></i>' + message.data + '</span> </div>'); // console.log(message); } $(".send-btn").click(function(){ var text = $(".send-input").val(); var message = '{"data":"'+text+'","type":"say","fromid":"'+fromid+'","toid":"'+toid+'"}'; $(".chat-content").append('<div class="chat-text section-right flex"><span class="text"><i class="icon icon-sanjiao3 t-32"></i>'+text+'</span> <span class="char-img" style="background-image: "></span> </div>'); ws.send(message); $(".send-input").val(""); }) function save_message(message){ $.post( API_URL+"insertchat" , message, function(){ },'json' ) } ``` 就添加一個post方法的函數,將數據傳回到服務器,由服務器進行數據庫記錄操作,下面是保存的代碼 ~~~ public function insertchat() { if (Request::instance()->isAjax()) { $message = input("post."); $datas['fromid'] = $message['fromid']; $datas['fromname'] = $message['fromid']; $datas['toid'] = $message['toid']; $datas['toname'] = $message['toid']; $datas['content'] = $message['data']; $datas['time'] = $message['time']; $datas['isread'] = $message['isread']; $datas['type'] = 1; Db::name("communication")->insert($datas); } } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看