SSController.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace App\Http\Controllers\Api\WebApi;
  3. use App\Models\Node;
  4. use Illuminate\Http\JsonResponse;
  5. class SSController extends BaseController
  6. {
  7. // 获取节点信息
  8. public function getNodeInfo(Node $node): JsonResponse
  9. {
  10. $data = [
  11. 'id' => $node->id,
  12. 'method' => $node->method,
  13. 'protocol' => $node->protocol,
  14. 'obfs' => $node->obfs,
  15. 'obfs_param' => $node->obfs_param ?? '',
  16. 'is_udp' => $node->is_udp,
  17. 'speed_limit' => $node->getRawOriginal('speed_limit'),
  18. 'client_limit' => $node->client_limit,
  19. 'sinlge' => $node->single,
  20. 'port' => $node->port,
  21. 'passwd' => $node->passwd ?? '',
  22. 'push_port' => $node->push_port
  23. ];
  24. // i['port'] = $node->port;
  25. // }f ($node->single) {
  26. // $data
  27. return $this->returnData('获取节点信息成功', 'success', 200, $data);
  28. }
  29. // 获取节点可用的用户列表
  30. public function getUserList(Node $node): JsonResponse
  31. {
  32. foreach ($node->users() as $user) {
  33. // $data[] = [
  34. // 'uid' => $user->id,
  35. // 'port' => $user->port,
  36. // 'passwd' => $node->passwd,
  37. // 'speed_limit' => $user->getRawOriginal('speed_limit'),
  38. // 'enable' => $user->enable,
  39. // ];
  40. $data[] = [
  41. 'uid' => $user->id,
  42. 'port' => $user->port,
  43. 'passwd' => $user->passwd,
  44. 'method' => $node->method,
  45. 'protocol' => $user->protocol,
  46. 'speed_limit' => $user->getRawOriginal('speed_limit'),
  47. 'enable' => $user->enable,
  48. 'client_limit' => $user->client_limit,
  49. ];
  50. }
  51. return $this->returnData('获取用户列表成功', 'success', 200, $data ?? [], ['updateTime' => time()]);
  52. }
  53. }