Clash.php 2.8 KB

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