Clash.php 1.4 KB

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