QuantumultX.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. } else {
  34. array_push($config, 'obfs=wss');
  35. }
  36. } else if ($server['network'] === 'ws') {
  37. array_push($config, 'obfs=ws');
  38. }
  39. if ($server['tls']) {
  40. if ($server['tlsSettings']) {
  41. $tlsSettings = json_decode($server['tlsSettings'], true);
  42. if (isset($tlsSettings['allowInsecure']) && !empty($tlsSettings['allowInsecure']))
  43. array_push($config, 'tls-verification=' . $tlsSettings['allowInsecure'] ? 'false' : 'true');
  44. if (isset($tlsSettings['serverName']) && !empty($tlsSettings['serverName']))
  45. array_push($config, "sni={$tlsSettings['serverName']}");
  46. }
  47. }
  48. if ($server['network'] === 'ws') {
  49. if ($server['networkSettings']) {
  50. $wsSettings = json_decode($server['networkSettings'], true);
  51. if (isset($wsSettings['path']) && !empty($wsSettings['path']))
  52. array_push($config, "obfs-uri={$wsSettings['path']}");
  53. if (isset($wsSettings['headers']['Host']) && !empty($wsSettings['headers']['Host']))
  54. array_push($config, "obfs-host={$wsSettings['headers']['Host']}");
  55. }
  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. }