1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-23 11:58:41 +08:00
2020-09-23 21:41:21 +08:00

55 lines
1.3 KiB
PHP

<?php
namespace App\Http\Home\Services;
use App\Services\Service as AppService;
use GatewayClient\Gateway;
trait ImCsTrait
{
public function getCsUser()
{
$csUserIds = [];
$onlineUserIds = [];
$appService = new AppService();
$csInfo = $appService->getSettings('im.cs');
Gateway::$registerAddress = $this->getRegisterAddress();
if (!empty($csInfo['user1_id'])) {
$csUserIds[] = $csInfo['user1_id'];
if (Gateway::isUidOnline($csInfo['user1_id'])) {
$onlineUserIds[] = $csInfo['user1_id'];
}
}
if (!empty($csInfo['user2_id'])) {
$csUserIds[] = $csInfo['user2_id'];
if (Gateway::isUidOnline($csInfo['user2_id'])) {
$onlineUserIds[] = $csInfo['user2_id'];
}
}
if (!empty($csInfo['user3_id'])) {
$csUserIds[] = $csInfo['user3_id'];
if (Gateway::isUidOnline($csInfo['user3_id'])) {
$onlineUserIds[] = $csInfo['user3_id'];
}
}
if (count($onlineUserIds) > 0) {
$key = array_rand($onlineUserIds);
$userId = $onlineUserIds[$key];
} else {
$key = array_rand($csUserIds);
$userId = $csUserIds[$key];
}
return $this->getImUser($userId);
}
}