1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-23 20:00:27 +08:00
2020-08-22 19:47:57 +08:00

54 lines
1.4 KiB
PHP

<?php
namespace App\Http\Desktop\Services;
use App\Caches\Setting as SettingCache;
use GatewayClient\Gateway;
trait ImCsTrait
{
public function getCsUser()
{
$csUserIds = [];
$onlineUserIds = [];
$cache = new SettingCache();
$imInfo = $cache->get('im');
Gateway::$registerAddress = $this->getRegisterAddress();
if (!empty($imInfo['cs_user1_id'])) {
$csUserIds[] = $imInfo['cs_user1_id'];
if (Gateway::isUidOnline($imInfo['cs_user1_id'])) {
$onlineUserIds[] = $imInfo['cs_user1_id'];
}
}
if (!empty($imInfo['cs_user2_id'])) {
$csUserIds[] = $imInfo['cs_user2_id'];
if (Gateway::isUidOnline($imInfo['cs_user2_id'])) {
$onlineUserIds[] = $imInfo['cs_user2_id'];
}
}
if (!empty($imInfo['cs_user3_id'])) {
$csUserIds[] = $imInfo['cs_user3_id'];
if (Gateway::isUidOnline($imInfo['cs_user3_id'])) {
$onlineUserIds[] = $imInfo['cs_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);
}
}