1
0

QuantumultX.php 2.9 KB

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