Surge.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace App\Utils;
  3. class Surge
  4. {
  5. public static function buildVmess($uuid, $server)
  6. {
  7. $proxies = $server->name . ' = vmess, ' . $server->host . ', ' . $server->port . ', username=' . $uuid . ', tfo=true';
  8. if ($server->tls) {
  9. $tlsSettings = json_decode($server->tlsSettings);
  10. $proxies .= ', tls=' . ($server->tls ? "true" : "false");
  11. if (isset($tlsSettings->allowInsecure)) {
  12. $proxies .= ', skip-cert-verify=' . ($tlsSettings->allowInsecure ? "true" : "false");
  13. }
  14. }
  15. if ($server->network == 'ws') {
  16. $proxies .= ', ws=true';
  17. if ($server->networkSettings) {
  18. $wsSettings = json_decode($server->networkSettings);
  19. if (isset($wsSettings->path)) $proxies .= ', ws-path=' . $wsSettings->path;
  20. if (isset($wsSettings->headers->Host)) $proxies .= ', ws-headers=host:' . $wsSettings->headers->Host;
  21. }
  22. }
  23. $proxies .= "\r\n";
  24. return $proxies;
  25. }
  26. public static function buildTrojan($password, $server)
  27. {
  28. $config = [
  29. "{$server->name}=trojan",
  30. "{$server->host}",
  31. "{$server->port}",
  32. "password={$password}",
  33. $server->allow_insecure ? 'skip-cert-verify=true' : 'skip-cert-verify=false',
  34. $server->server_name ? "sni={$server->server_name}" : "",
  35. "tfo=true"
  36. ];
  37. $config = array_filter($config);
  38. $uri = implode(',', $config);
  39. $uri .= "\r\n";
  40. return $uri;
  41. }
  42. }