Ethan 6 жил өмнө
parent
commit
876a6b8f2c

+ 2 - 2
public/static/customer/js/whisper-cli.js

@@ -14,7 +14,7 @@ var commChat = 1;
 if(config != undefined && config.socket != undefined){
 
     // 创建一个Socket实例
-    var socket = new WebSocket('ws://' + config.socket+'?apiToken=70b0a7d015ef9a5268b2bc7e3e96af24');
+    var socket = new WebSocket('ws://' + config.socket+'?apiToken=8444fb09eec653b322a4ad74b836aed0');
 
     // 加锁
     lockTextarea();
@@ -27,7 +27,7 @@ if(config != undefined && config.socket != undefined){
         // 登录
         var login_data = '{"type":"userInit", "uid": 1, "name" : "' + config.name +
             '", "avatar" : "' + config.avatar + '", "group" : ' + config.group + '}';
-        socket.send(login_data);
+        //socket.send(login_data);
 
         // 解锁
         unlockTextarea();

+ 3 - 8
public/static/service/js/whisper.js

@@ -6,7 +6,7 @@ var uinfo = {
 };
 
 // 创建一个Socket实例
-var socket = new WebSocket('ws://' + socket_server+'?apiToken=70b0a7d015ef9a5268b2bc7e3e96af24');
+var socket = new WebSocket('ws://' + socket_server+'?apiToken=8444fb09eec653b322a4ad74b836aed0');
 
 // 打开Socket
 socket.onopen = function (res) {
@@ -306,14 +306,9 @@ function cc() {
     var uid = $("#active-user").attr('data-id');
 
     socket.send(JSON.stringify({
-        type: 'closeUser',
-        data: {to_id: uid, from_name: uinfo.username, from_id: uinfo.id}
+        type: 'kfCloseUser',
+        data: {to_id: uid}
     }));
-
-    $("#u-" + uid).append(word);
-    $(".msg-area").val('');
-    // 滚动条自动定位到最底端
-    wordBottom();
 }
 
 // 展示客服发送来的消息

+ 55 - 8
vendor/GatewayWorker_windows/Applications/whisper/Events.php

@@ -331,11 +331,11 @@ class Events
             case 'evaluate':
                 self::evaluate($client_id, $message);
                 break;
-            // 关闭会话.
-            case 'closeUser':
+            // 客服关闭会话.
+            case 'kfCloseUser':
                 $client = Gateway::getClientIdByUid($message['data']['to_id']);
                 if(!empty($client)){
-                    self::onClose($client['0']);
+                    self::serverClose($client['0']);
                 }
                 break;
         }
@@ -350,8 +350,50 @@ class Events
      */
     public static function onClose($client_id)
     {
-        print_r([$client_id,self::$global->uidSimpleList,self::$global->userList]);
+        $uidSimpleList = self::$global->uidSimpleList;
+        $userId = '';
+        foreach ($uidSimpleList as $k => $v) {
+            if ($v[0] == $client_id) {
+                $userId = $k;
+            }
+        }
+        $kfId = '';
+        if ($userId) {
+            $userToKf = self::$global->userToKf;
+            $kfId = $userToKf[$userId][1];
+        }
+        if ($kfId) {
+            $client = Gateway::getClientIdByUid($kfId);
+            // 返回.
+            $chat_message = [
+                'message_type' => 'userClose',
+                'data' => [
+                    'content' => '用户连接已断开',
+                    'time' => date('H:i'),
+                ]
+            ];
+            Gateway::sendToClient($client['0'], json_encode($chat_message));
+        }
+    }
 
+    /**
+     * 客服结束会话
+     * @param int $client_id 连接id
+     *
+     * tips: 当服务端主动退出的时候,会出现 exit status 9.原因是:服务端主动断开之后,连接的客户端会走这个方法,而短时间内进程
+     * 需要处理这多的逻辑,又有cas操作,导致进程退出会超时,然后会被内核杀死,从而报出错误 9.实际对真正的业务没有任何的影响。
+     */
+    public static function serverClose($client_id)
+    {
+        // 返回.
+        $chat_message = [
+            'message_type' => 'closeBysever',
+            'data' => [
+                'content' => '客服停止了该会话',
+                'time' => date('H:i'),
+            ]
+        ];
+        Gateway::sendToClient($client_id, json_encode($chat_message));
         $isServiceUserOut = false;
         // 将会员服务信息,从客服的服务列表中移除
         $old = $kfList = self::$global->kfList;
@@ -361,7 +403,7 @@ class Events
 
                     $isServiceUserOut = true;
 
-                    // 根据client id 去更新这个会员离线的一些信息
+                    // 根据client id 去更新会话工单一些信息
                     self::$db->query("update `ws_service_log` set `end_time` = " . time() . " , `status` = '2' where `client_id`= '" . $client_id . "'");
 
                     // 从会员的内存表中检索出该会员的信息,并更新内存
@@ -380,7 +422,7 @@ class Events
                     while(!self::$global->cas('uidSimpleList', $oldSimple, $simpleList)){};
                     unset($oldSimple, $simpleList);
 
-                    //$outUser = self::$db->query("select `user_id`,`group_id` from `ws_service_log` where `client_id`= '" . $client_id . "'");
+                    $outUser = self::$db->query("select `user_id`,`group_id` from `ws_service_log` where `client_id`= '" . $client_id . "'");
                     // 通知 客服删除退出的用户
                     if(!empty($outUser)){
                         $del_message = [
@@ -587,7 +629,12 @@ class Events
 
             while(!self::$global->cas('kfList', self::$global->kfList, $res['data']['4'])){}; // 更新客服数据
             while(!self::$global->cas('userList', self::$global->userList, $res['data']['5'])){}; // 更新会员数据
-
+            $userToKf = self::$global->userToKf;
+            $userToKf[$res['data']['3']['id']] = [
+                $res['data']['3']['id'],
+                $res['data']['0']
+            ];
+            self::$global->userToKf = $userToKf;
             // 通知会员发送信息绑定客服的id
             $noticeUser = [
                 'message_type' => 'connect',
@@ -857,7 +904,7 @@ class Events
      */
     private static function evaluate($client_id, $message)
     {
-        // 查询问题.
+        // 修改数据库.
         $evaluate_id = $message['data']['evaluate_id'];
         $result = self::$db->query("UPDATE `ws_service_log` SET `evaluate_id` = '" . $evaluate_id . "' WHERE `client_id`='" . $client_id . "'");
         if ($result) {

+ 0 - 4
vendor/GatewayWorker_windows/Applications/whisper/start_gateway.php

@@ -39,10 +39,6 @@ $gateway->pingInterval = 10;
 // 心跳数据
 $gateway->pingData = '{"message_type":"ping"}';
 
-<<<<<<< HEAD
-/*
-=======
->>>>>>> 0f5d31b38816e57e85443225e6fc57cdd78c1920
 // 当客户端连接上来时,设置连接的onWebSocketConnect,即在websocket握手时的回调
 $gateway->onConnect = function($connection)
 {