如有疑问,欢迎打扰~~~~~
php + websocket 实现即时通讯。
右键菜单功能。
群聊功能以及右键菜单功能
<?php namespace app\server\controller; use think\worker\Server; use think\Session; use Workerman\Lib\Timer; // 心跳间隔55秒 define('HEARTBEAT_TIME', 55); define('CHECK_HEARTBEAT_TIME', 10); // 检查连接的间隔时间 class Worker extends Server { protected $socket = 'websocket://www.tp5.com:2346'; protected $processes = 1; protected $uidConnections = array(); static $count = 0; /** * 收到信息 * @param $connection * @param $data */ public function onMessage($connection, $data) { // 判断当前客户端是否已经验证,既是否设置了uid,设置了直接发送消息,未设置第一次为设置uid dump('开始'); $connection->lastMessageTime = time(); if(!isset($connection->uid)) { $uid = json_decode($data,true); if ($uid['message_type'] == 'event'){ dump($uid); switch ($uid['type']){ case 'sendOrder': $arr = [ 'message_type' => 'event', 'type' => 'sendOrder', 'username' => $uid['username'], 'imgUrl' => $uid['imgUrl'], 'info' => $uid['info'], ]; $receipt = json_encode($arr,JSON_UNESCAPED_UNICODE ); break; case 'online': $arr = [ 'message_type' => 'event', 'type' => 'online', 'username' => $uid['username'], ]; $receipt = json_encode($arr,JSON_UNESCAPED