Clash.php 2.8 KB

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