SS.php 772 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Services\Subscribe;
  4. use App\Models\Config;
  5. use App\Services\Subscribe;
  6. use function base64_encode;
  7. use const PHP_EOL;
  8. final class SS extends Base
  9. {
  10. public function getContent($user): string
  11. {
  12. $links = '';
  13. //判断是否开启SS订阅
  14. if (! Config::obtain('enable_ss_sub')) {
  15. return $links;
  16. }
  17. $nodes_raw = Subscribe::getSubNodes($user);
  18. foreach ($nodes_raw as $node_raw) {
  19. if ((int) $node_raw->sort === 0) {
  20. $links .= base64_encode($user->method . ':' . $user->passwd . '@' . $node_raw->server . ':' . $user->port) . '#' .
  21. $node_raw->name . PHP_EOL;
  22. }
  23. }
  24. return $links;
  25. }
  26. }