mirror of
				https://github.com/v2board/v2board.git
				synced 2025-10-31 01:11:46 +08:00 
			
		
		
		
	Protocols: add V2ray Client Protocol
Usage: add &flag=v2rayng at the end of subscription link for V2rayNG Client add &flag=v2rayn at the end of subscription link for V2rayN Client
This commit is contained in:
		
							
								
								
									
										60
									
								
								app/Http/Controllers/Client/Protocols/V2rayN.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										60
									
								
								app/Http/Controllers/Client/Protocols/V2rayN.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,60 @@ | |||||||
|  | <?php | ||||||
|  |  | ||||||
|  | namespace App\Http\Controllers\Client\Protocols; | ||||||
|  |  | ||||||
|  |  | ||||||
|  | class V2rayN | ||||||
|  | { | ||||||
|  |     public $flag = 'v2rayn'; | ||||||
|  |     private $servers; | ||||||
|  |     private $user; | ||||||
|  |  | ||||||
|  |     public function __construct($user, $servers) | ||||||
|  |     { | ||||||
|  |         $this->user = $user; | ||||||
|  |         $this->servers = $servers; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public function handle() | ||||||
|  |     { | ||||||
|  |         $servers = $this->servers; | ||||||
|  |         $user = $this->user; | ||||||
|  |         $uri = ''; | ||||||
|  |  | ||||||
|  |         foreach ($servers as $item) { | ||||||
|  |             if ($item['type'] === 'v2ray') { | ||||||
|  |                 $uri .= self::buildVmess($user['uuid'], $item); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         return base64_encode($uri); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public static function buildVmess($uuid, $server) | ||||||
|  |     { | ||||||
|  |         $config = [ | ||||||
|  |             "v" => "2", | ||||||
|  |             "ps" => $server['name'], | ||||||
|  |             "add" => $server['host'], | ||||||
|  |             "port" => (string)$server['port'], | ||||||
|  |             "id" => $uuid, | ||||||
|  |             "aid" => (string)$server['alter_id'], | ||||||
|  |             "net" => $server['network'], | ||||||
|  |             "type" => "none", | ||||||
|  |             "host" => "", | ||||||
|  |             "path" => "", | ||||||
|  |             "tls" => $server['tls'] ? "tls" : "", | ||||||
|  |             "sni" => $server['tls'] ? isset(json_decode($server['tlsSettings'], true)['serverName']) : "" | ||||||
|  |         ]; | ||||||
|  |         if ((string)$server['network'] === 'ws') { | ||||||
|  |             $wsSettings = json_decode($server['networkSettings'], true); | ||||||
|  |             if (isset($wsSettings['path'])) $config['path'] = $wsSettings['path']; | ||||||
|  |             if (isset($wsSettings['headers']['Host'])) $config['host'] = $wsSettings['headers']['Host']; | ||||||
|  |         } | ||||||
|  |         if ((string)$server['network'] === 'grpc') { | ||||||
|  |             $grpcSettings = json_decode($server['networkSettings'], true); | ||||||
|  |             if (isset($grpcSettings['path'])) $config['path'] = $grpcSettings['serviceName']; | ||||||
|  |         } | ||||||
|  |         return "vmess://" . base64_encode(json_encode($config)) . "\r\n"; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  | } | ||||||
							
								
								
									
										60
									
								
								app/Http/Controllers/Client/Protocols/V2rayNG.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										60
									
								
								app/Http/Controllers/Client/Protocols/V2rayNG.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,60 @@ | |||||||
|  | <?php | ||||||
|  |  | ||||||
|  | namespace App\Http\Controllers\Client\Protocols; | ||||||
|  |  | ||||||
|  |  | ||||||
|  | class V2rayNG | ||||||
|  | { | ||||||
|  |     public $flag = 'v2rayng'; | ||||||
|  |     private $servers; | ||||||
|  |     private $user; | ||||||
|  |  | ||||||
|  |     public function __construct($user, $servers) | ||||||
|  |     { | ||||||
|  |         $this->user = $user; | ||||||
|  |         $this->servers = $servers; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public function handle() | ||||||
|  |     { | ||||||
|  |         $servers = $this->servers; | ||||||
|  |         $user = $this->user; | ||||||
|  |         $uri = ''; | ||||||
|  |  | ||||||
|  |         foreach ($servers as $item) { | ||||||
|  |             if ($item['type'] === 'v2ray') { | ||||||
|  |                 $uri .= self::buildVmess($user['uuid'], $item); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         return base64_encode($uri); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public static function buildVmess($uuid, $server) | ||||||
|  |     { | ||||||
|  |         $config = [ | ||||||
|  |             "v" => "2", | ||||||
|  |             "ps" => $server['name'], | ||||||
|  |             "add" => $server['host'], | ||||||
|  |             "port" => (string)$server['port'], | ||||||
|  |             "id" => $uuid, | ||||||
|  |             "aid" => (string)$server['alter_id'], | ||||||
|  |             "net" => $server['network'], | ||||||
|  |             "type" => "none", | ||||||
|  |             "host" => "", | ||||||
|  |             "path" => "", | ||||||
|  |             "tls" => $server['tls'] ? "tls" : "", | ||||||
|  |             "sni" => $server['tls'] ? isset(json_decode($server['tlsSettings'], true)['serverName']) : "" | ||||||
|  |         ]; | ||||||
|  |         if ((string)$server['network'] === 'ws') { | ||||||
|  |             $wsSettings = json_decode($server['networkSettings'], true); | ||||||
|  |             if (isset($wsSettings['path'])) $config['path'] = $wsSettings['path']; | ||||||
|  |             if (isset($wsSettings['headers']['Host'])) $config['host'] = $wsSettings['headers']['Host']; | ||||||
|  |         } | ||||||
|  |         if ((string)$server['network'] === 'grpc') { | ||||||
|  |             $grpcSettings = json_decode($server['networkSettings'], true); | ||||||
|  |             if (isset($grpcSettings['path'])) $config['path'] = $grpcSettings['serviceName']; | ||||||
|  |         } | ||||||
|  |         return "vmess://" . base64_encode(json_encode($config)) . "\r\n"; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  | } | ||||||
		Reference in New Issue
	
	Block a user