Sfoglia il codice sorgente

Merge branch 'master' of http://git.bocai108.com:10180/Ethan/Customer-Service

Jonlin 6 anni fa
parent
commit
f7e331d6a8

+ 31 - 0
application/service/controller/Index.php

@@ -92,6 +92,37 @@ class Index extends Common
     }//end userWords()
 
 
+    /**
+     * 获取敏感词
+     *
+     * @access public
+     * @return array JsonString
+     */
+    public function sensitiveWords()
+    {
+        // 验证token.
+        $tokenStatus = $this->verifyToken();
+        $code        = -2;
+        $msg         = '错误';
+        if ($tokenStatus === false) {
+            return json(['code' => $code, 'data' => [], 'msg' => $msg]);
+        }
+
+        try {
+            // 获取快捷语.
+            $wordsField = ['*'];
+            $sysWordsWhere['sensitivewords_status'] = 1;
+            // 查询系统快捷语.
+            $sensitiveWords = model('sensitivewords')->selectWords($wordsField, $sysWordsWhere);
+
+            return json(['code' => 200, 'data' => $sensitiveWords, 'msg' => '成功']);
+        } catch (\Exception $e) {
+            return json(['code' => $code, 'data' => [], 'msg' => $msg]);
+        }//end try
+
+    }//end userWords()
+
+
     public function index()
     {
         $getUserInfo = $this->getUserInfo();

+ 55 - 20
application/service/controller/Words.php

@@ -107,12 +107,12 @@ class Words extends Common
 
 
     /**
-     * 获取会话历史详细
+     * 快捷语修改
      *
      * @access public
      * @return array JsonString
      */
-    public function historyInfo()
+    public function deleteWords()
     {
         // 验证token.
         $tokenStatus = $this->verifyToken();
@@ -124,30 +124,65 @@ class Words extends Common
 
         try {
             // 获取用户信息.
-            $servicelogId = input('get.servicelog_id');
-            $chatLogField = ['*'];
-            // 关联信息.
-            $chatLogWhere['servicelog_id'] = $servicelogId;
-            // 分页.
-            $currentPage = input('get.currentPage', '1');
-            $pageSize    = input('get.pageSize', '10');
-            $offset      = (($currentPage - 1) * $pageSize);
-            // 获取用户信息.
-            $chatLog      = model('ChatLog')->selectChatLog($chatLogField, $offset, $pageSize, $chatLogWhere);
-            $countChatLog = model('ChatLog')->countChatLog($chatLogWhere);
+            $getUserInfo    = $this->getUserInfo();
+            $userWordsWhere = [
+                'user_id' => $getUserInfo->id,
+                'id'      => input('post.id'),
+            ];
+            $deleteResult   = model('Words')->deleteWords($userWordsWhere);
+
+            // 参数返回.
+            if (empty($deleteResult) === false) {
+                return json(['code' => 200, 'data' => [], 'msg' => '成功']);
+            } else {
+                return json(['code' => 1, 'data' => [], 'msg' => 1]);
+            }
+        } catch (\Exception $e) {
+            return json(['code' => $code, 'data' => [], 'msg' => $msg]);
+        }//end try
+
+    }//end deleteWords()
 
-            $result['total']       = $countChatLog;
-            $result['countPage']   = (ceil(($result['total']) / $pageSize));
-            $result['currentPage'] = $currentPage;
-            $result['list']        = $chatLog;
-            $result['pageSize']    = $pageSize;
 
-            return json(['code' => 200, 'data' => $result, 'msg' => '成功']);
+    /**
+     * 快捷语修改
+     *
+     * @access public
+     * @return array JsonString
+     */
+    public function addWords()
+    {
+        // 验证token.
+        $tokenStatus = $this->verifyToken();
+        $code        = -2;
+        $msg         = '错误';
+        if ($tokenStatus === false) {
+            return json(['code' => $code, 'data' => [], 'msg' => $msg]);
+        }
+
+        try {
+            // 获取用户信息.
+            $getUserInfo    = $this->getUserInfo();
+            $userWordsData = [
+                'user_id' => $getUserInfo->id,
+                'title'      => input('post.title'),
+                'content'      => input('post.content'),
+                'status'      => input('post.status'),
+                'add_time'      => date('Y-m-d H:i:s'),
+            ];
+            $deleteResult   = model('Words')->addWords($userWordsData);
+
+            // 参数返回.
+            if (empty($deleteResult) === false) {
+                return json(['code' => 200, 'data' => [], 'msg' => '成功']);
+            } else {
+                return json(['code' => 1, 'data' => [], 'msg' => 1]);
+            }
         } catch (\Exception $e) {
             return json(['code' => $code, 'data' => [], 'msg' => $msg]);
         }//end try
 
-    }//end historyInfo()
+    }//end deleteWords()
 
 
 }

+ 34 - 0
application/service/model/Sensitivewords.php

@@ -0,0 +1,34 @@
+<?php
+namespace app\service\model;
+
+use think\Model;
+
+/**
+ * 敏感词模型
+ */
+class Sensitivewords extends Model
+{
+
+
+    /**
+     * 数据筛选
+     *
+     * @access public
+     * @param mixed $field 字段
+     * @param mixed $where 条件
+     * @return array 返回类型
+     */
+    public function selectWords($field, $where=[])
+    {
+        $result = $this->field($field);
+        if (empty($where) === false) {
+            $result = $result->where($where);
+        }
+
+        $result = $result->select();
+        return $result;
+
+    }//end selectWords()
+
+
+}

+ 32 - 0
application/service/model/Words.php

@@ -48,4 +48,36 @@ class Words extends Model
     }//end updateWords()
 
 
+    /**
+     * 数据删除
+     *
+     * @access public
+     * @param mixed $where 条件
+     * @return array 返回类型
+     */
+    public function deleteWords($where)
+    {
+        $result = $this->where($where)->delete();
+
+        return $result;
+
+    }//end deleteWords()
+
+
+    /**
+     * 数据增加
+     *
+     * @access public
+     * @param mixed $data 数据
+     * @return array 返回类型
+     */
+    public function addWords($data)
+    {
+        $result = $this->insert($data);
+
+        return $result;
+
+    }//end addWords()
+
+
 }

+ 261 - 96
vendor/GatewayWorker_windows/Applications/whisper/Events.php

@@ -88,9 +88,11 @@ class Events
             Timer::add(60 * 40, function () {
                 self::writeLog(2);
             });
+
         }
     }
 
+
     /**
      * 当客户端连接时触发
      * 如果业务不需此回调可以删除onConnect
@@ -111,7 +113,7 @@ class Events
                     'content' => htmlspecialchars($sayHello['0']['word'])
                 ]
             ];
-            Gateway::sendToClient($client_id, json_encode($hello));
+            Gateway::sendToClient($client_id, json_encode($hello, 256));
             unset($hello);
         }
         unset($sayHello);
@@ -129,7 +131,7 @@ class Events
             return;
         } else {
             echo "onMessage: " . $message . "\r\n";
-            //print_r([self::$global->kfList, self::$global->userList, self::$global->uidSimpleList, self::$global->userToKf]);
+            print_r([self::$global->kfList, self::$global->userList, self::$global->uidSimpleList, self::$global->userToKf]);
         }
 
         $message = json_decode($message, true);
@@ -163,57 +165,16 @@ class Events
 
                 // 绑定 client_id 和 uid
                 Gateway::bindUid($client_id, $message['uid']);
+                $_SESSION['group'] = $message['group'];
+                $_SESSION['iskefu'] = 1;
+                $_SESSION['uid'] = $message['uid'];
+
                 // TODO 尝试拉取用户来服务 [二期规划]
 
                 break;
             // 顾客初始化
             case 'userInit';
-                $userList = self::$global->userList;
-                // 如果该顾客未在内存中记录则记录
-                if (!array_key_exists($message['uid'], $userList)) {
-                    do {
-                        $NewUserList = $userList;
-                        $NewUserList[$message['uid']] = [
-                            'id' => $message['uid'],
-                            'name' => $message['name'],
-                            'avatar' => $message['avatar'],
-                            'website' => $_SESSION['origin'],//$_SERVER['HTTP_ORIGIN'],
-                            'browse' => Gateway::browse_info(),
-                            'system' => Gateway::get_os(),
-                            'ip' => isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '',
-                            'group' => $message['group'],
-                            'client_id' => $client_id
-                        ];
-
-                    } while (!self::$global->cas('userList', $userList, $NewUserList));
-                    unset($NewUserList, $userList);
-
-                    // 维护 UID对应的client_id 数组
-                    do {
-                        $old = $newList = self::$global->uidSimpleList;
-                        $newList[$message['uid']] = [
-                            $client_id,
-                            $message['group']
-                        ];
-
-                    } while (!self::$global->cas('uidSimpleList', $old, $newList));
-                    unset($old, $newList);
-
-                    // 写入接入值
-                    $key = date('Ymd') . 'total_in';
-                    self::$global->$key = 0;
-                    do {
-                        $oldKey = date('Ymd', strtotime('-1 day')); // 删除前一天的统计值
-                        unset(self::$global->$oldKey);
-                    } while (!self::$global->increment($key));
-                    unset($key);
-                }
-
-                // 绑定 client_id 和 uid
-                Gateway::bindUid($client_id, $message['uid']);
-
-                // 尝试分配新会员进入服务
-                self::userOnlineTask($client_id, $message['group']);
+                self::userInitEnt($client_id, $message);
                 break;
             // 聊天
             case 'chatMessage':
@@ -282,7 +243,7 @@ class Events
                                 'content' => $waitMsg,
                             ]
                         ];
-                        Gateway::sendToClient($userClient, json_encode($waitMessage));
+                        Gateway::sendToClient($userClient, json_encode($waitMessage, 256));
                         unset($waitMessage);
                     }
                     return;
@@ -338,7 +299,7 @@ class Events
                             'content' => '暂时没有客服上班,请稍后再咨询。',
                         ]
                     ];
-                    Gateway::sendToClient($userInfo[$message['uid']]['0'], json_encode($waitMessage));
+                    Gateway::sendToClient($userInfo[$message['uid']]['0'], json_encode($waitMessage, 256));
                     unset($waitMessage);
                 }
                 unset($userInfo);
@@ -358,7 +319,74 @@ class Events
                     self::serverClose($client['0']);
                 }
                 break;
+            // default:
+            //    Gateway::closeClient($client_id);
         }
+
+    }
+
+    //用户发送邦定用户事件
+    public static function userInitEnt($client_id, $message)
+    {
+        $userList = self::$global->userList;
+        // 如果该顾客未在内存中记录则记录
+
+        $uidSimpleList = self::$global->uidSimpleList;
+        if (isset($uidSimpleList[$message['uid']])) {
+            $uidSimpleList = self::$global->uidSimpleList;
+            $oldclientid = $uidSimpleList[$message['uid']]['0'];
+            Gateway::sendToClient($oldclientid, json_encode(['type' => 'reLoginErr', 'msg' => '相同账号登陆,本次退出'], 256));
+            Gateway::closeClient($oldclientid);
+            sleep(2);
+        }
+
+        if (!array_key_exists($message['uid'], $userList)) {
+            do {
+                $NewUserList = $userList;
+                $NewUserList[$message['uid']] = [
+                    'id' => $message['uid'],
+                    'name' => $message['name'],
+                    'avatar' => $message['avatar'],
+                    'website' => $_SESSION['origin'],//$_SERVER['HTTP_ORIGIN'],
+                    'browse' => Gateway::browse_info(),
+                    'system' => Gateway::get_os(),
+                    'ip' => isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '',
+                    'group' => $message['group'],
+                    'client_id' => $client_id
+                ];
+
+            } while (!self::$global->cas('userList', $userList, $NewUserList));
+            unset($NewUserList, $userList);
+
+            // 维护 UID对应的client_id 数组
+            do {
+                $old = $newList = self::$global->uidSimpleList;
+                $newList[$message['uid']] = [
+                    $client_id,
+                    $message['group']
+                ];
+
+            } while (!self::$global->cas('uidSimpleList', $old, $newList));
+            unset($old, $newList);
+
+            // 写入接入值
+            $key = date('Ymd') . 'total_in';
+            self::$global->$key = 0;
+            do {
+                $oldKey = date('Ymd', strtotime('-1 day')); // 删除前一天的统计值
+                unset(self::$global->$oldKey);
+            } while (!self::$global->increment($key));
+            unset($key);
+        }
+
+        // 绑定 client_id 和 uid
+        Gateway::bindUid($client_id, $message['uid']);
+        $_SESSION['iskefu'] = 0;
+        $_SESSION['uid'] = $message['uid'];
+
+        // 尝试分配新会员进入服务
+        self::userOnlineTask($client_id, $message['group'], $message['uid']);
+
     }
 
     /**
@@ -370,33 +398,132 @@ class Events
      */
     public static function onClose($client_id)
     {
-        $uidSimpleList = self::$global->uidSimpleList;
-        $userId = '';
-        foreach ($uidSimpleList as $k => $v) {
-            if ($v[0] == $client_id) {
-                $userId = $k;
+        $isKefuoff = isset($_SESSION['iskefu']) ? $_SESSION['iskefu'] : 0;
+        $uid = isset($_SESSION['uid']) ? $_SESSION['uid'] : false;
+        if (empty($uid)) {
+            return;
+        }
+
+        if ($isKefuoff) {
+            self::serviceOffline($client_id, $uid);
+        } else {
+            self::guestOffline($client_id, $uid);
+        }
+        return;
+    }
+
+    //客服下线了
+    public static function serviceOffline($client_id, $uid)
+    {
+        $group = $_SESSION['group'];
+        $kefuinfo_old = $kefuinfo_old_new = self::$global->kfList;
+        $user_info = $kefuinfo_old_new[$group][$uid]['user_info'];
+
+        $simpliUsers = self::$global->uidSimpleList;
+        $simpliUsersID_UID_Arr = [];
+        if (!empty($simpliUsers)) {
+            foreach ($simpliUsers as $key => $val) {
+                $simpliUsersID_UID_Arr[$val['0']] = $key;
             }
         }
-        $kfId = '';
-        if ($userId) {
-            $userToKf = self::$global->userToKf;
-            $kfId = $userToKf[$userId][1];
+
+        $now = time();
+        if (!empty($user_info)) {
+            foreach ($user_info as $val) {
+                Gateway::sendToClient($val, json_encode(['type' => 'serviceoffline', 'msg' => '客户人员下线!'], 256));
+                if (isset($simpliUsersID_UID_Arr[$val])) {
+                    self::$db->query("update `ws_service_log` set `status` = '2',end_time=$now  where `user_id`= '$simpliUsersID_UID_Arr[$val]' and  kf_id='$uid' and  group_id=$group  and  `status`!=2 ");
+                }
+                Gateway::closeClient($val);
+            }
         }
-        if ($kfId) {
-            $client = Gateway::getClientIdByUid($kfId);
-            // 返回.
-            $chat_message = [
-                'message_type' => 'userClose',
-                'data' => [
-                    'content' => '用户连接已断开',
-                    'time' => date('H:i'),
-                ]
-            ];
-            self::$db->query("update `ws_service_log` set `status` = '3' where `client_id`= '" . $client_id . "'");
-            Gateway::sendToClient($client['0'], json_encode($chat_message));
+        unset($kefuinfo_old_new[$group][$uid]);
+        do {
+        } while (!self::$global->cas('kfList', $kefuinfo_old, $kefuinfo_old_new));
+        return;
+    }
+
+    //用户下线了
+    public static function guestOffline($client_id, $uid)
+    {
+        $kfuid = -1;
+        $krclient_id = 0;
+        $kfgroup = -1;
+
+        $userToKf = $userToKfNew = self::$global->userToKf;
+        if (isset($userToKfNew[$uid])) {
+            $kfuid = isset($userToKfNew[$uid]['1']) ? $userToKfNew[$uid]['1'] : -1;
+            $krclient_id = isset(Gateway::getClientIdByUid($kfuid)['0']) ? Gateway::getClientIdByUid($kfuid)['0'] : 0;
+            unset($userToKfNew[$uid]);
+            do {
+            } while (!self::$global->cas('userToKf', $userToKf, $userToKfNew));
+        }
+
+        $uidSimpleList = $uidSimpleListNew = self::$global->uidSimpleList;
+        if (isset($uidSimpleListNew[$uid])) {
+            $kfgroup = $uidSimpleListNew[$uid]['1'];
+            unset($uidSimpleListNew[$uid]);
+            do {
+            } while (!self::$global->cas('uidSimpleList', $uidSimpleList, $uidSimpleListNew));
+        }
+
+        $userList = $userListNew = self::$global->userList;
+        if (!empty($userList)) {
+            $ischange = 0;
+            foreach ($userList as $key => $val) {
+                if ($val['id'] == $uid) {
+                    unset($userListNew[$key]);
+                    $ischange = 1;
+                    break;
+                }
+            }
+            if ($ischange) {
+                do {
+                } while (!self::$global->cas('userList', $userList, $userListNew));
+            }
+        }
+
+
+        if ($kfuid != -1 && $kfgroup != -1) {
+            $kefuinfo_old = $kefuinfo_old_new = self::$global->kfList;
+            $ischange_kf_list = 0;
+            if (isset($kefuinfo_old[$kfgroup][$kfuid])) {
+                $infos = $kefuinfo_old[$kfgroup][$kfuid]['user_info'];
+                if ($infos) {
+                    if (is_array($infos)) {
+                        foreach ($infos as $key => $val) {
+                            if ($val == $client_id) {
+                                $ischange_kf_list = 1;
+                                unset($kefuinfo_old_new[$kfgroup][$kfuid]['user_info'][$key]);
+                                $kefuinfo_old_new[$kfgroup][$kfuid]['task'] = $kefuinfo_old_new[$kfgroup][$kfuid]['task'] - 1;
+                            }
+                        }
+                    }
+                    if ($ischange_kf_list) {
+                        do {
+                        } while (!self::$global->cas('kfList', $kefuinfo_old, $kefuinfo_old_new));
+
+                        $chat_message = [
+                            'message_type' => 'userClose',
+                            'data' => [
+                                'content' => '用户连接已断开',
+                                'time' => date('H:i'),
+                            ]
+                        ];
+                        $now = time();
+                        $kf__uid = substr($kfuid, 2);
+                        $sql = "update `ws_service_log` set `status` = '3',end_time=$now  where `user_id`= '$uid' and  kf_id='$kf__uid' and  group_id=$kfgroup  and  status=1 ";
+                        //echo "客户退出:". $sql ."\n";
+                        self::$db->query($sql);
+                        Gateway::sendToClient($krclient_id, json_encode($chat_message, 256));
+                    }
+                }
+            }
         }
+
     }
 
+
     /**
      * 客服结束会话
      * @param int $client_id 连接id
@@ -414,7 +541,7 @@ class Events
                 'time' => date('H:i'),
             ]
         ];
-        Gateway::sendToClient($client_id, json_encode($chat_message));
+        Gateway::sendToClient($client_id, json_encode($chat_message, 256));
         $isServiceUserOut = false;
         // 将会员服务信息,从客服的服务列表中移除
         $old = $kfList = self::$global->kfList;
@@ -444,6 +571,7 @@ class Events
                     };
                     unset($oldSimple, $simpleList);
 
+
                     $outUser = self::$db->query("select `user_id`,`group_id` from `ws_service_log` where `client_id`= '" . $client_id . "'");
                     // 通知 客服删除退出的用户
                     if (!empty($outUser)) {
@@ -453,7 +581,7 @@ class Events
                                 'id' => $outUser['0']['user_id']
                             ]
                         ];
-                        Gateway::sendToClient($vo['client_id'], json_encode($del_message));
+                        Gateway::sendToClient($vo['client_id'], json_encode($del_message, 256));
                         unset($del_message);
 
                         // 尝试分配新会员进入服务
@@ -557,7 +685,7 @@ class Events
                     'kf_name' => $res['data']['1']
                 ]
             ];
-            Gateway::sendToClient($res['data']['3']['client_id'], json_encode($noticeUser));
+            Gateway::sendToClient($res['data']['3']['client_id'], json_encode($noticeUser, 256));
             unset($noticeUser);
 
             // 通知客服端绑定会员的信息
@@ -567,7 +695,7 @@ class Events
                     'user_info' => $res['data']['3']
                 ]
             ];
-            Gateway::sendToClient($res['data']['2'], json_encode($noticeKf));
+            Gateway::sendToClient($res['data']['2'], json_encode($noticeKf, 256));
             unset($noticeKf);
 
             // 逐一通知
@@ -582,7 +710,7 @@ class Events
                     ]
                 ];
 
-                Gateway::sendToClient($vo['client_id'], json_encode($waitMessage));
+                Gateway::sendToClient($vo['client_id'], json_encode($waitMessage, 256));
                 $number++;
             }
             unset($waitMessage, $number);
@@ -611,7 +739,7 @@ class Events
                                 'content' => $waitMsg,
                             ]
                         ];
-                        Gateway::sendToClient($vo['client_id'], json_encode($waitMessage));
+                        Gateway::sendToClient($vo['client_id'], json_encode($waitMessage, 256));
                     }
                     break;
                 case -2:
@@ -631,7 +759,7 @@ class Events
                             ]
                         ];
 
-                        Gateway::sendToClient($vo['client_id'], json_encode($waitMessage));
+                        Gateway::sendToClient($vo['client_id'], json_encode($waitMessage, 256));
                         $number++;
                     }
                     break;
@@ -644,13 +772,14 @@ class Events
      * 有人进入执行分配
      * @param $client_id
      * @param $group
+     * @param $uid
      */
-    private static function userOnlineTask($client_id, $group)
+    private static function userOnlineTask($client_id, $group, $uid = 0)
     {
         // TODO 此处查询最大的可服务人数,后面可以用其他的方式,存储这个数值,让其更高效的访问
         $maxNumber = self::getMaxServiceNum();
 
-        $res = self::assignmentTask(self::$global->kfList, self::$global->userList, $group, $maxNumber);
+        $res = self::assignmentTask(self::$global->kfList, self::$global->userList, $group, $maxNumber, $uid);
         unset($maxNumber);
 
         if (1 == $res['code']) {
@@ -682,8 +811,13 @@ class Events
                 'status' => 1,
                 'end_time' => 0
             ];
+            $hisSession = self::$db->select('*')->from('ws_service_log')->where('user_id=:user_id and kf_id=:kf_id and group_id=:group_id and status in (1,3)')->bindValues(array('user_id' => $res['data']['3']['id'], 'kf_id' => intval(ltrim($res['data']['0'], 'KF')), 'group_id' => $group))->row();
+            if (!$hisSession) {
+                $conversationId = self::$db->insert('ws_service_log')->cols($serviceLog)->query();
+            } else {
+                self::$db->update('ws_service_log')->cols(['status' => 1])->where('id=' . $hisSession['id'])->query();
+            }
 
-            $conversationId = self::$db->insert('ws_service_log')->cols($serviceLog)->query();
             unset($serviceLog);
 
 
@@ -696,7 +830,7 @@ class Events
                     'kf_name' => $res['data']['1']
                 ]
             ];
-            Gateway::sendToClient($client_id, json_encode($noticeUser));
+            Gateway::sendToClient($client_id, json_encode($noticeUser, 256));
             unset($noticeUser);
 
             // 通知客服端绑定会员的信息
@@ -707,7 +841,7 @@ class Events
                     'conversationId' => $conversationId,
                 ]
             ];
-            Gateway::sendToClient($res['data']['2'], json_encode($noticeKf));
+            Gateway::sendToClient($res['data']['2'], json_encode($noticeKf, 256));
             unset($noticeKf);
 
             // 写入接入值
@@ -744,7 +878,7 @@ class Events
                 ]
             ];
 
-            Gateway::sendToClient($client_id, json_encode($waitMessage));
+            Gateway::sendToClient($client_id, json_encode($waitMessage, 256));
             unset($waitMessage);
         }
     }
@@ -757,7 +891,7 @@ class Events
      * @param $group
      * @param $total
      */
-    private static function assignmentTask($kfList, $userList, $group, $total)
+    private static function assignmentTask($kfList, $userList, $group, $total, $uid = 0)
     {
         // 没有客服上线
         if (empty($kfList) || empty($kfList[$group])) {
@@ -779,20 +913,51 @@ class Events
             return ['code' => -1];
         }
 
-        $kf = $kfList[$group];
-        $user = array_shift($userList);
+        //上次用户掉线后,还可以继续上一次 (如果没有关闭) 的会话  --1
+        $odltalksession = false;
+        $user = $user_first = array_shift($userList);
+        if ($uid > 0 && $user['id'] != $uid && count($userList) > 1) {
+            $timevalielimit = time() - 60 * 5;
+            $odltalksession = self::$db->select('*')->from('ws_service_log')->where('user_id=:uid and  `group`=:group and  `status`=3 and  end_time>=:timevalielimit"')->bindValues(array('uid' => $uid, 'group' => $group, 'timevalielimit' => $timevalielimit))->row();
+            if ($odltalksession) {
+                foreach ($userList as $ttkey => $ttval) {
+                    if ($ttval['id'] == $uid) {
+                        array_unshift($userList, $user);
+                        $user = $userList[$ttkey];
+                        unset($userList[$ttkey]);
+                        break;
+                    }
+                }
+            }
+        }
 
-        $kf = array_shift($kf);
-        $min = $kf['task'];
-        $flag = $kf['id'];
 
-        foreach ($kfList[$group] as $key => $vo) {
-            if ($vo['task'] < $min) {
-                $min = $vo['task'];
-                $flag = $key;
+        //上次用户掉线后,还可以继续上一次 (如果没有关闭) 的会话  --2
+        if ($odltalksession) {
+            $oldkrid = 'KF' . $odltalksession['kf_id'];
+            if (isset($kfList[$group][$oldkrid])) {
+                $kf = $kfList[$group][$oldkrid];
+                $min = $kf['task'];
+                $flag = $kf['id'];
+                unset($kfList[$group][$oldkrid]);
+            } else {
+                goto NOSIGNKF;
+            }
+        } else {
+            NOSIGNKF:
+            $kf = $kfList[$group];
+            $kf = array_shift($kf);
+            $min = $kf['task'];
+            $flag = $kf['id'];
+
+            foreach ($kfList[$group] as $key => $vo) {
+                if ($vo['task'] < $min) {
+                    $min = $vo['task'];
+                    $flag = $key;
+                }
             }
+            unset($kf);
         }
-        unset($kf);
 
         // 需要排队了
         if ($kfList[$group][$flag]['task'] == $total) {
@@ -909,7 +1074,7 @@ class Events
                 'content' => $getRobot ? htmlspecialchars($getRobot[0]['robot_content']) : 'error',
             ]
         ];
-        Gateway::sendToClient($client_id, json_encode($chat_message));
+        Gateway::sendToClient($client_id, json_encode($chat_message, 256));
     }
 
     /**

+ 3 - 3
vendor/GatewayWorker_windows/Applications/whisper/start_gateway.php

@@ -38,7 +38,7 @@ $gateway->registerAddress = '127.0.0.1:1238';
 // 心跳间隔
 $gateway->pingInterval = 10;
 // 心跳数据
-$gateway->pingData = '{"type":"ping"}';
+$gateway->pingData = '{"message_type":"ping"}';
 
 
 // 当客户端连接上来时,设置连接的onWebSocketConnect,即在websocket握手时的回调
@@ -50,14 +50,14 @@ $gateway->onConnect = function ($connection) {
         $_SESSION['origin'] = $_SERVER['HTTP_ORIGIN'];
         $getToken = isset($_GET['apiToken']) ? $_GET['apiToken'] : '';
 
+
         if ($getToken !== $apiToken) {
              //$connection->close();
             // return;
         }
         $_SESSION['remotip'] = $connection->getRemoteIp();
         $_SESSION['remotport'] = $connection->getRemotePort();
-        $_SESSION['userAgent'] = $_SERVER['HTTP_USER_AGENT'];
-        $_SESSION['origin'] = $_SERVER['HTTP_ORIGIN'];
+
 
         // 可以在这里判断连接来源是否合法,不合法就关掉连接
         // $_SERVER['HTTP_ORIGIN']标识来自哪个站点的页面发起的websocket链接