51 lines
1.0 KiB
PHP
51 lines
1.0 KiB
PHP
<?php
|
|
/**
|
|
* Created by PhpStorm.
|
|
* User: zn
|
|
* Date: 2017/6/15
|
|
* Time: 11:01
|
|
*/
|
|
|
|
namespace comm;
|
|
|
|
|
|
use common\models\UserInfo;
|
|
use common\services\UserService;
|
|
use SwooleYiiApp;
|
|
|
|
/**
|
|
* 客户端消息
|
|
* Class MessageUtil
|
|
* @package comm
|
|
*/
|
|
class ClientMessageUtil
|
|
{
|
|
//发送客户端信息
|
|
public static function SendClientMessage($fd, $commandID, $status = 0, $data = null)
|
|
{
|
|
$returnData['command_id'] = $commandID;
|
|
$returnData['status'] = $status;
|
|
|
|
if (!empty($data))
|
|
$returnData['data'] = $data;
|
|
|
|
$jsonData = json_encode($returnData);
|
|
|
|
SocketCommUtil::log('发送消息', $fd, $jsonData);
|
|
|
|
if (SwooleYiiApp::$server->exist($fd))
|
|
SwooleYiiApp::$server->push($fd, $jsonData);
|
|
}
|
|
|
|
/**
|
|
* 清理断线用户数据
|
|
* @param $fd
|
|
*/
|
|
public static function clearCloseClient($fd)
|
|
{
|
|
$userInfo = UserInfo::loadByFd($fd);
|
|
if (empty($userInfo)) return;
|
|
|
|
UserService::loginOut($userInfo->userID);
|
|
}
|
|
} |