QuantumultX.php 2.5 KB

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