Clash.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace App\Utils;
  3. class Clash
  4. {
  5. public static function buildShadowsocks($uuid, $server)
  6. {
  7. $array = [];
  8. $array['name'] = $server['name'];
  9. $array['type'] = 'ss';
  10. $array['server'] = $server['host'];
  11. $array['port'] = $server['port'];
  12. $array['cipher'] = $server['cipher'];
  13. $array['password'] = $uuid;
  14. $array['udp'] = true;
  15. return $array;
  16. }
  17. public static function buildVmess($uuid, $server)
  18. {
  19. $array = [];
  20. $array['name'] = $server['name'];
  21. $array['type'] = 'vmess';
  22. $array['server'] = $server['host'];
  23. $array['port'] = $server['port'];
  24. $array['uuid'] = $uuid;
  25. $array['alterId'] = 2;
  26. $array['cipher'] = 'auto';
  27. $array['udp'] = true;
  28. if ($server['tls']) {
  29. $tlsSettings = json_decode($server['tlsSettings'], true);
  30. $array['tls'] = true;
  31. if (!empty($tlsSettings['allowInsecure'])) $array['skip-cert-verify'] = ($tlsSettings['allowInsecure'] ? true : false );
  32. if (!empty($tlsSettings['serverName'])) $array['servername'] = $tlsSettings['serverName'];
  33. }
  34. if ($server['network'] == 'ws') {
  35. $array['network'] = $server['network'];
  36. if ($server['networkSettings']) {
  37. $wsSettings = json_decode($server['networkSettings'], true);
  38. if (isset($wsSettings['path'])) $array['ws-path'] = $wsSettings['path'];
  39. if (isset($wsSettings['headers']['Host'])) $array['ws-headers'] = [
  40. 'Host' => $wsSettings['headers']['Host']
  41. ];
  42. }
  43. }
  44. return $array;
  45. }
  46. public static function buildTrojan($password, $server)
  47. {
  48. $array = [];
  49. $array['name'] = $server['name'];
  50. $array['type'] = 'trojan';
  51. $array['server'] = $server['host'];
  52. $array['port'] = $server['port'];
  53. $array['password'] = $password;
  54. $array['udp'] = true;
  55. if (!empty($server['server_name'])) $array['sni'] = $server['server_name'];
  56. if (!empty($server['allow_insecure'])) $array['skip-cert-verify'] = ($server['allow_insecure'] ? true : false );
  57. return $array;
  58. }
  59. }