QuantumultX.php 2.9 KB

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