Clash.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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);
  30. $array['tls'] = true;
  31. if (isset($tlsSettings->allowInsecure)) $array['skip-cert-verify'] = ($tlsSettings->allowInsecure ? true : false );
  32. if (isset($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);
  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. $array['sni'] = $server->server_name;
  56. if ($server->allow_insecure) {
  57. $array['skip-cert-verify'] = true;
  58. } else {
  59. $array['skip-cert-verify'] = false;
  60. }
  61. return $array;
  62. }
  63. }