QuantumultX.php 1.8 KB

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