文件说明
长链接命令启动文件目录 crmeb\services\workerman
├─chat
│ ├─ChatHandle.php 移动端聊天事件处理
│ └─ChatService.php 移动端服务
├─ChannelService.php 内部消息通讯服务
├─Response.php 返回数据集合
├─WorkermanHandle.php 平台端聊天事件处理
└─WorkermanService.php 平台端服务
ChatHandle.php
主要协助ChatService.php
在onMessage
事件中调用ChatHandle
内部方法
在ChatService.php
文件的onMessage
方法
或者也可以使用事件来调用
public function onMessage(TcpConnection $connection, $res)
{
$connection->lastMessageTime = time();
$res = json_decode($res, true);
if (!$res || !isset($res['type']) || !$res['type'] || $res['type'] == 'ping') {
return $this->response->connection($connection)->success('ping', ['now' => time()]);
}
if (!method_exists($this->handle, $res['type'])) return;
try {
//调用ChatHandle中的方法,从而实现不同的消息类型,调用不同的逻辑
$this->handle->{$res['type']}($connection, $res + ['data' => []], $this->response->connection($connection));
} catch (\Throwable $e) {
}
}