QuantumultX.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. namespace App\Utils\Clients;
  3. /*
  4. * 本文件依据
  5. * https://github.com/crossutility/Quantumult-X/blob/master/server-complete.snippet
  6. *
  7. */
  8. use App\Utils\Library\Templates\Client;
  9. class QuantumultX implements Client
  10. {
  11. public static function buildShadowsocks(array $server): string
  12. {
  13. $config = array_filter([
  14. "shadowsocks={$server['host']}:{$server['port']}",
  15. "method={$server['method']}",
  16. "password={$server['passwd']}",
  17. 'fast-open=true',
  18. "udp-relay={$server['udp']}",
  19. "tag={$server['name']}",
  20. ]);
  21. return implode(',', $config).PHP_EOL;
  22. }
  23. public static function buildShadowsocksr(array $server): string
  24. {
  25. $config = array_filter([
  26. "shadowsocks={$server['host']}:{$server['port']}",
  27. "method={$server['method']}",
  28. "password={$server['passwd']}",
  29. "ssr-protocol={$server['protocol']}",
  30. "ssr-protocol-param={$server['protocol_param']}",
  31. "obfs={$server['obfs']}",
  32. "obfs-host={$server['obfs_param']}",
  33. 'fast-open=true',
  34. "udp-relay={$server['udp']}",
  35. "tag={$server['name']}",
  36. ]);
  37. return implode(',', $config).PHP_EOL;
  38. }
  39. public static function buildVmess(array $server): string
  40. {
  41. $config = [
  42. "vmess={$server['host']}:{$server['port']}",
  43. "method={$server['method']}",
  44. "password={$server['uuid']}",
  45. 'fast-open=true',
  46. "udp-relay={$server['udp']}",
  47. "tag={$server['name']}",
  48. ];
  49. if ($server['v2_tls']) {
  50. if ($server['v2_net'] === 'tcp') {
  51. $config[] = 'obfs=over-tls';
  52. } else {
  53. $config[] = 'obfs=wss';
  54. }
  55. } elseif ($server['v2_net'] === 'ws') {
  56. $config[] = 'obfs=ws';
  57. }
  58. if ($server['v2_tls']) {
  59. $config[] = 'tls-verification=true';
  60. if (! empty($server['v2_host'])) {
  61. $config[] = "tls-host={$server['v2_host']}";
  62. }
  63. }
  64. if ($server['v2_type'] === 'ws' && ! empty($server['v2_path'])) {
  65. $config[] = "obfs-uri={$server['v2_path']}";
  66. $config[] = "obfs-host={$server['v2_host']}";
  67. }
  68. return implode(',', $config).PHP_EOL;
  69. }
  70. public static function buildTrojan(array $server): string
  71. {
  72. $config = array_filter([
  73. "trojan={$server['host']}:{$server['port']}",
  74. "password={$server['passwd']}",
  75. 'over-tls=true',
  76. $server['host'] ? "tls-host={$server['host']}" : '',
  77. // Tips: allowInsecure=false = tls-verification=true
  78. // $server['allow_insecure'] ? 'tls-verification=false' : 'tls-verification=true',
  79. 'fast-open=true',
  80. "udp-relay={$server['udp']}",
  81. "tag={$server['name']}",
  82. ]);
  83. return implode(',', $config).PHP_EOL;
  84. }
  85. }