QuantumultX.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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['tls']) {
  31. if ($server['network'] === 'tcp')
  32. array_push($config, 'obfs=over-tls');
  33. if ($server['tlsSettings']) {
  34. $tlsSettings = json_decode($server['tlsSettings'], true);
  35. if (isset($tlsSettings['allowInsecure']) && !empty($tlsSettings['allowInsecure']))
  36. array_push($config, 'tls-verification=' . ($tlsSettings['allowInsecure'] ? 'false' : 'true'));
  37. if (isset($tlsSettings['serverName']) && !empty($tlsSettings['serverName']))
  38. $host = $tlsSettings['serverName'];
  39. }
  40. }
  41. if ($server['network'] === 'ws') {
  42. if ($server['tls'])
  43. array_push($config, 'obfs=wss');
  44. else
  45. array_push($config, 'obfs=ws');
  46. if ($server['networkSettings']) {
  47. $wsSettings = json_decode($server['networkSettings'], true);
  48. if (isset($wsSettings['path']) && !empty($wsSettings['path']))
  49. array_push($config, "obfs-uri={$wsSettings['path']}");
  50. if (isset($wsSettings['headers']['Host']) && !empty($wsSettings['headers']['Host']) && !isset($host))
  51. $host = $wsSettings['headers']['Host'];
  52. }
  53. }
  54. if (isset($host)) {
  55. array_push($config, "obfs-host={$host}");
  56. }
  57. $uri = implode(',', $config);
  58. $uri .= "\r\n";
  59. return $uri;
  60. }
  61. public static function buildTrojan($password, $server)
  62. {
  63. $config = [
  64. "trojan={$server['host']}:{$server['port']}",
  65. "password={$password}",
  66. 'over-tls=true',
  67. $server['server_name'] ? "tls-host={$server['server_name']}" : "",
  68. // Tips: allowInsecure=false = tls-verification=true
  69. $server['allow_insecure'] ? 'tls-verification=false' : 'tls-verification=true',
  70. 'fast-open=true',
  71. 'udp-relay=true',
  72. "tag={$server['name']}"
  73. ];
  74. $config = array_filter($config);
  75. $uri = implode(',', $config);
  76. $uri .= "\r\n";
  77. return $uri;
  78. }
  79. }