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.

129 lines
3.8 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 Uid extends Base
{
/**
* 将client_id与uid绑定
* @param string $client_id 客户端ID
* @param string $uid 用户ID
* @date 2022-05-17
*/
public function bindUid($client_id, $uid)
{
// 设置GatewayWorker服务的Register服务ip和端口请根据实际情况改成实际值(ip不能是0.0.0.0)
Gateway::$registerAddress = $this->config['ip'] . ':' . $this->config['port'];
// client_id与uid绑定
$result = Gateway::bindUid($client_id, $uid);
// 记录日志
$uid = defined('UID') ? UID : '';
platformLog([
'client_id' => $client_id,
'uid' => $uid,
], $result, 'gateway_worker_bind_uid_uid_' . $uid);
return $result;
}
/**
* 返回与uid绑定的所有在线的client_id
* @param string $uid 用户ID
* @date 2022-06-01
*/
public function getClientIdByUid($uid)
{
// 设置GatewayWorker服务的Register服务ip和端口请根据实际情况改成实际值(ip不能是0.0.0.0)
Gateway::$registerAddress = $this->config['ip'] . ':' . $this->config['port'];
// 发送消息
$result = Gateway::getClientIdByUid($uid);
// 记录日志
$uid = defined('UID') ? UID : '';
platformLog([
'uid' => $uid,
], $result, 'gateway_worker_get_client_id_by_uid_uid_' . $uid);
return $result;
}
/**
* 判断$uid是否在线
* @param string $uid 用户ID
* @date 2022-06-01
*/
public function isUidOnline($uid)
{
// 设置GatewayWorker服务的Register服务ip和端口请根据实际情况改成实际值(ip不能是0.0.0.0)
Gateway::$registerAddress = $this->config['ip'] . ':' . $this->config['port'];
// 判断$uid是否在线
$result = Gateway::isUidOnline($uid);
// 记录日志
$uid = defined('UID') ? UID : '';
platformLog([
'uid' => $uid,
], $result, 'gateway_worker_is_uid_online_uid_' . $uid);
return $result;
}
/**
* 向uid绑定的所有在线client_id发送数据
* @param string $uid 用户ID
* @param array $message 消息
* @param string $data_transfer 数据转换 json--转成json格式 ''--不做任何转换
* @date 2022-05-17
*/
public function sendToUid($uid, $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);
}
// 向uid绑定的所有在线client_id发送数据
$result = Gateway::sendToUid($uid, $message);
// 记录日志
$uid = defined('UID') ? UID : '';
platformLog([
'uid' => $uid,
'message' => $message
], $result, 'getaway_worker_send_to_uid_uid_' . $uid);
return $result;
}
/**
* 返回client_id绑定的uid
* @param string $client_id 客户端ID
* @date 2022-07-28
*/
public function getUidByClientId($client_id)
{
// 设置GatewayWorker服务的Register服务ip和端口请根据实际情况改成实际值(ip不能是0.0.0.0)
Gateway::$registerAddress = $this->config['ip'] . ':' . $this->config['port'];
// 返回client_id绑定的uid
$result = Gateway::getUidByClientId($client_id);
// 记录日志
$uid = defined('UID') ? UID : '';
platformLog([
'client_id' => $client_id
], $result, 'getaway_worker_get_uid_by_client_id_uid_' . $uid);
return $result;
}
}