QuantumultX.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. namespace App\Utils;
  3. class QuantumultX
  4. {
  5. public static function buildShadowsocks($password, $server)
  6. {
  7. $config = [
  8. "shadowsocks={$server['host']}:{$server['port']}",
  9. "method={$server['cipher']}",
  10. "password={$password}",
  11. 'fast-open=true',
  12. 'udp-relay=true',
  13. "tag={$server['name']}"
  14. ];
  15. $config = array_filter($config);
  16. $uri = implode(',', $config);
  17. $uri .= "\r\n";
  18. return $uri;
  19. }
  20. public static function buildVmess($uuid, $server)
  21. {
  22. $config = [
  23. "vmess={$server['host']}:{$server['port']}",
  24. 'method=chacha20-poly1305',
  25. "password={$uuid}",
  26. 'fast-open=true',
  27. 'udp-relay=true',
  28. "tag={$server['name']}"
  29. ];
  30. if ($server['network'] === 'tcp') {
  31. if ($server['tls']) {
  32. $tlsSettings = json_decode($server['tlsSettings'], true);
  33. array_push($config, 'obfs=over-tls');
  34. if (isset($tlsSettings['allowInsecure'])) {
  35. // Tips: allowInsecure=false = tls-verification=true
  36. array_push($config, $tlsSettings['allowInsecure'] ? 'tls-verification=false' : 'tls-verification=true');
  37. }
  38. if (!empty($tlsSettings['serverName'])) {
  39. array_push($config, "obfs-host={$tlsSettings['serverName']}");
  40. }
  41. }
  42. }
  43. if ($server['network'] === 'ws') {
  44. if ($server['tls']) {
  45. $tlsSettings = json_decode($server['tlsSettings'], true);
  46. array_push($config, 'obfs=wss');
  47. if (isset($tlsSettings['allowInsecure'])) {
  48. array_push($config, $tlsSettings['allowInsecure'] ? 'tls-verification=false' : 'tls-verification=true');
  49. }
  50. } else {
  51. array_push($config, 'obfs=ws');
  52. }
  53. if ($server['networkSettings']) {
  54. $wsSettings = json_decode($server['networkSettings'], true);
  55. if (isset($wsSettings['path'])) array_push($config, "obfs-uri={$wsSettings['path']}");
  56. if (isset($wsSettings['headers']['Host'])) array_push($config, "obfs-host={$wsSettings['headers']['Host']}");
  57. }
  58. }
  59. $uri = implode(',', $config);
  60. $uri .= "\r\n";
  61. return $uri;
  62. }
  63. public static function buildTrojan($password, $server)
  64. {
  65. $config = [
  66. "trojan={$server['host']}:{$server['port']}",
  67. "password={$password}",
  68. 'over-tls=true',
  69. $server['server_name'] ? "tls-host={$server['server_name']}" : "",
  70. // Tips: allowInsecure=false = tls-verification=true
  71. $server['allow_insecure'] ? 'tls-verification=false' : 'tls-verification=true',
  72. 'fast-open=true',
  73. 'udp-relay=true',
  74. "tag={$server['name']}"
  75. ];
  76. $config = array_filter($config);
  77. $uri = implode(',', $config);
  78. $uri .= "\r\n";
  79. return $uri;
  80. }
  81. }