| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- <?php
- namespace App\Utils\Clients\Protocols;
- use App\Utils\Library\Templates\Protocol;
- class QuantumultX implements Protocol
- {
- public static function build(array $servers, bool $isEncode = false): string
- {
- $validTypes = ['shadowsocks', 'shadowsocksr', 'vmess', 'trojan'];
- $url = '';
- foreach ($servers as $server) {
- if (in_array($server['type'], $validTypes, true)) {
- $url .= call_user_func([self::class, 'build'.ucfirst($server['type'])], $server);
- }
- }
- return $isEncode ? base64_encode($url) : $url;
- }
- public static function buildShadowsocks(array $server): string
- {
- $config = array_filter([
- "shadowsocks={$server['host']}:{$server['port']}",
- "method={$server['method']}",
- "password={$server['passwd']}",
- 'fast-open=true',
- "udp-relay={$server['udp']}",
- "tag={$server['name']}",
- ]);
- return implode(',', $config).PHP_EOL;
- }
- public static function buildShadowsocksr(array $server): string
- {
- $config = array_filter([
- "shadowsocks={$server['host']}:{$server['port']}",
- "method={$server['method']}",
- "password={$server['passwd']}",
- "ssr-protocol={$server['protocol']}",
- "ssr-protocol-param={$server['protocol_param']}",
- "obfs={$server['obfs']}",
- "obfs-host={$server['obfs_param']}",
- 'fast-open=true',
- "udp-relay={$server['udp']}",
- "tag={$server['name']}",
- ]);
- return implode(',', $config).PHP_EOL;
- }
- public static function buildVmess(array $server): string
- {
- $config = [
- "vmess={$server['host']}:{$server['port']}",
- "method={$server['method']}",
- "password={$server['uuid']}",
- 'fast-open=true',
- "udp-relay={$server['udp']}",
- "tag={$server['name']}",
- ];
- if ($server['v2_tls']) {
- if ($server['v2_net'] === 'tcp') {
- $config[] = 'obfs=over-tls';
- } else {
- $config[] = 'obfs=wss';
- }
- } elseif ($server['v2_net'] === 'ws') {
- $config[] = 'obfs=ws';
- }
- if ($server['v2_tls']) {
- $config[] = 'tls-verification=true';
- if (! empty($server['v2_host'])) {
- $config[] = "tls-host={$server['v2_host']}";
- }
- }
- if ($server['v2_type'] === 'ws' && ! empty($server['v2_path'])) {
- $config[] = "obfs-uri={$server['v2_path']}";
- $config[] = "obfs-host={$server['v2_host']}";
- }
- return implode(',', $config).PHP_EOL;
- }
- public static function buildTrojan(array $server): string
- {
- $config = array_filter([
- "trojan={$server['host']}:{$server['port']}",
- "password={$server['passwd']}",
- 'over-tls=true',
- $server['host'] ? "tls-host={$server['host']}" : '',
- // Tips: allowInsecure=false = tls-verification=true
- // $server['allow_insecure'] ? 'tls-verification=false' : 'tls-verification=true',
- 'fast-open=true',
- "udp-relay={$server['udp']}",
- "tag={$server['name']}",
- ]);
- return implode(',', $config).PHP_EOL;
- }
- }
|