Surge.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace App\Utils\Clients;
  3. use App\Utils\Library\Templates\Client;
  4. class Surge implements Client
  5. {
  6. public static function buildShadowsocks(array $server): string
  7. {
  8. $config = array_filter([
  9. "{$server['name']}=ss",
  10. $server['host'],
  11. $server['port'],
  12. "encrypt-method={$server['method']}",
  13. "password={$server['passwd']}",
  14. 'tfo=true',
  15. "udp-relay={$server['udp']}",
  16. ]);
  17. return implode(',', $config).PHP_EOL;
  18. }
  19. public static function buildVmess(array $server): string
  20. {
  21. $config = [
  22. "{$server['name']}=vmess",
  23. $server['host'],
  24. $server['port'],
  25. "username={$server['uuid']}",
  26. 'vmess-aead=true',
  27. 'tfo=true',
  28. "udp-relay={$server['udp']}",
  29. ];
  30. if ($server['v2_tls']) {
  31. array_push($config, 'tls=true', "sni={$server['v2_host']}");
  32. }
  33. if ($server['v2_net'] === 'ws') {
  34. array_push($config, 'ws=true', "ws-path={$server['v2_path']}", "ws-headers=Host:{$server['v2_host']}");
  35. }
  36. return implode(',', $config).PHP_EOL;
  37. }
  38. public static function buildTrojan(array $server): string
  39. {
  40. $config = array_filter([
  41. "{$server['name']}=trojan",
  42. $server['host'],
  43. $server['port'],
  44. "password={$server['passwd']}",
  45. $server['sni'] ? "sni={$server['sni']}" : '',
  46. 'tfo=true',
  47. "udp-relay={$server['udp']}",
  48. // "skip-cert-verify={$server['allow_insecure']}"
  49. ]);
  50. return implode(',', $config).PHP_EOL;
  51. }
  52. public static function buildShadowsocksr(array $server): array|string
  53. {
  54. return '';
  55. }
  56. }