Clash.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. $array['udp'] = true;
  16. if ($server->tls) {
  17. $tlsSettings = json_decode($server->tlsSettings);
  18. $array['tls'] = true;
  19. if (isset($tlsSettings->allowInsecure)) $array['skip-cert-verify'] = ($tlsSettings->allowInsecure ? true : false );
  20. }
  21. if ($server->network == 'ws') {
  22. $array['network'] = $server->network;
  23. if ($server->networkSettings) {
  24. $wsSettings = json_decode($server->networkSettings);
  25. if (isset($wsSettings->path)) $array['ws-path'] = $wsSettings->path;
  26. if (isset($wsSettings->headers->Host)) $array['ws-headers'] = [
  27. 'Host' => $wsSettings->headers->Host
  28. ];
  29. }
  30. }
  31. return $array;
  32. }
  33. public static function buildTrojan($password, $server)
  34. {
  35. $array = [];
  36. $array['name'] = $server->name;
  37. $array['type'] = 'trojan';
  38. $array['server'] = $server->host;
  39. $array['port'] = $server->port;
  40. $array['password'] = $password;
  41. $array['udp'] = true;
  42. $array['sni'] = $server->server_name;
  43. if ($server->allow_insecure) {
  44. $array['skip-cert-verify'] = true;
  45. } else {
  46. $array['skip-cert-verify'] = false;
  47. }
  48. return $array;
  49. }
  50. }