You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.7 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
namespace websocket;
use GatewayClient\Gateway;
class Client extends Base
{
/**
* 判断$client是否在线
* @param string $client_id client_id
* @date 2022-07-14
*/
public function isOnline($client_id)
{
// 设置GatewayWorker服务的Register服务ip和端口请根据实际情况改成实际值(ip不能是0.0.0.0)
Gateway::$registerAddress = $this->config['ip'] . ':' . $this->config['port'];
// 判断$client_id是否在线
$result = Gateway::isOnline($client_id);
// 记录日志
$uid = defined('UID') ? UID : '';
platformLog([
'client_id' => $client_id
], $result, 'gateway_worker_is_online_uid_' . $uid);
return $result;
}
/**
* 向client_id发送数据
* @param string $client_id client_id
* @param array $message 消息
* @param string $data_transfer 数据转换 json--转成json格式 ''--不做任何转换
* @date 2022-07-14
*/
public function sendToClient($client_id, $message = [], $data_transfer = 'json')
{
// 设置GatewayWorker服务的Register服务ip和端口请根据实际情况改成实际值(ip不能是0.0.0.0)
Gateway::$registerAddress = $this->config['ip'] . ':' . $this->config['port'];
if ($data_transfer == 'json') {
$message = json_encode($message);
}
// 发送消息
$result = Gateway::sendToClient($client_id, $message);
// 记录日志
$uid = defined('UID') ? UID : '';
platformLog([
'client_id' => $client_id,
'message' => $message
], $result, 'getaway_worker_send_to_client_uid_' . $uid);
return $result;
}
}