Files
ProxyPanel/app/Jobs/VNet/getUser.php

49 lines
1.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Jobs\VNet;
use App\Models\Node;
use Arr;
use Exception;
use Http;
use Log;
class GetUser
{
public function list(Node $node, string $mode = 'uid'): false|array
{
$list = $this->send(($node->server ?: $node->ips()[0]).':'.$node->push_port, $node->auth->secret);
if (is_array($list)) {
if ($mode === 'uid') {
return Arr::pluck($list, 'uid');
}
if ($mode === 'port') {
return Arr::pluck($list, 'port');
}
return $list;
}
return false;
}
private function send(string $host, string $secret): false|array
{
try {
$response = Http::baseUrl($host)->timeout(20)->withHeader('secret', $secret)->get('api/user/list');
$message = $response->json();
if ($message && $response->ok()) {
return $message;
}
Log::warning('【用户列表】获取失败(推送地址:'.$host.'');
} catch (Exception $exception) {
Log::alert('【用户列表】获取异常:'.$exception->getMessage());
}
return false;
}
}