Clash.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace App\Components\Client;
  3. /*
  4. * 本文件依据Clash文件编辑
  5. * https://github.com/Dreamacro/clash/tree/master/adapters/outbound
  6. *
  7. */
  8. class Clash
  9. {
  10. public static function buildShadowsocks($server)
  11. {
  12. return [
  13. 'name' => $server['name'],
  14. 'type' => 'ss',
  15. 'server' => $server['host'],
  16. 'port' => $server['port'],
  17. 'password' => $server['passwd'],
  18. 'cipher' => $server['method'],
  19. 'udp' => $server['udp'],
  20. ];
  21. }
  22. public static function buildShadowsocksr($server)
  23. {
  24. return [
  25. 'name' => $server['name'],
  26. 'type' => 'ssr',
  27. 'server' => $server['host'],
  28. 'port' => $server['port'],
  29. 'password' => $server['passwd'],
  30. 'cipher' => $server['method'],
  31. 'obfs' => $server['obfs'],
  32. 'protocol' => $server['protocol'],
  33. 'obfs-param' => $server['obfs_param'],
  34. 'protocol-param' => $server['protocol_param'],
  35. 'udp' => $server['udp'],
  36. ];
  37. }
  38. public static function buildVmess($server)
  39. {
  40. $array = [
  41. 'name' => $server['name'],
  42. 'type' => 'vmess',
  43. 'server' => $server['host'],
  44. 'port' => $server['port'],
  45. 'uuid' => $server['uuid'],
  46. 'alterId' => $server['v2_alter_id'],
  47. 'cipher' => $server['method'],
  48. 'udp' => $server['udp'],
  49. ];
  50. if ($server['v2_tls']) {
  51. $array['tls'] = true;
  52. $array['servername'] = $server['v2_host'];
  53. }
  54. $array['network'] = $server['v2_net'];
  55. if ($server['v2_net'] === 'ws') {
  56. $array['ws-opts'] = [];
  57. $array['ws-opts']['path'] = $server['v2_path'];
  58. if ($server['v2_host']) {
  59. $array['ws-opts']['headers'] = ['Host' => $server['v2_host']];
  60. }
  61. // TODO: 2022.06.01 remove it
  62. $array['ws-path'] = $server['v2_path'];
  63. if ($server['v2_host']) {
  64. $array['ws-headers'] = ['Host' => $server['v2_host']];
  65. }
  66. }
  67. return $array;
  68. }
  69. public static function buildTrojan($server)
  70. {
  71. $array = [
  72. 'name' => $server['name'],
  73. 'type' => 'trojan',
  74. 'server' => $server['host'],
  75. 'port' => $server['port'],
  76. 'password' => $server['passwd'],
  77. 'udp' => $server['udp'],
  78. ];
  79. if (! empty($server['sni'])) {
  80. $array['sni'] = $server['sni'];
  81. }
  82. return $array;
  83. }
  84. }