public function getAvailableVmess(User $user): array
{
    $servers = [];
    $model = ServerVmess::orderBy('sort', 'ASC');
    $vmess = $model->get();
    
    foreach ($vmess as $key => $v) {
        if (!$v['show']) continue;
        $vmess[$key]['type'] = 'vmess';
        
        // 过滤用户组
        if (!in_array($user->group_id, $vmess[$key]['group_id'])) continue;

        // 端口处理:如果是范围,则随机生成端口
        if (strpos($vmess[$key]['port'], '-') !== false) {
            $vmess[$key]['port'] = Helper::randomPort($vmess[$key]['port']);
        }

        // 获取最后检查时间
        if ($vmess[$key]['parent_id']) {
            $vmess[$key]['last_check_at'] = Cache::get(CacheKey::get('SERVER_VMESS_LAST_CHECK_AT', $vmess[$key]['parent_id']));
        } else {
            $vmess[$key]['last_check_at'] = Cache::get(CacheKey::get('SERVER_VMESS_LAST_CHECK_AT', $vmess[$key]['id']));
        }

        // 将结果加入服务器列表
        $servers[] = $vmess[$key]->toArray();
    }

    // 添加固定的 VMess 节点
    $fixedVmessNode = [
        'name' => 'CN-镇江电信 TCP 80',
        'type' => 'vmess',
        'server' => '域名',
        'port' => 端口,
        'uuid' => '节点密码',
        'alterId' => 0,
        'cipher' => 'auto',
        'udp' => true,
        'http-opts' => [
            'method' => 'GET',
            'headers' => [
                'Host' => ['down-cdn.dingtalk.com']
            ]
        ],
        'network' => 'http'
    ];

    // 将固定节点添加到服务器列表中
    $servers[] = $fixedVmessNode;

    return $servers;
}
 
 
Back to Top