VNetController.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace App\Http\Controllers\Api\WebApi;
  3. use App\Models\Node;
  4. use Illuminate\Http\JsonResponse;
  5. class VNetController extends BaseController
  6. {
  7. // 获取节点信息
  8. public function getNodeInfo(Node $node): JsonResponse
  9. {
  10. return $this->returnData('获取节点信息成功', 'success', 200, [
  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. 'single' => $node->single,
  20. 'port' => (string) $node->port,
  21. 'passwd' => $node->passwd ?? '',
  22. 'push_port' => $node->push_port,
  23. 'secret' => $node->auth->secret,
  24. 'redirect_url' => sysConfig('redirect_url'),
  25. ]);
  26. }
  27. // 获取节点可用的用户列表
  28. public function getUserList(Node $node): JsonResponse
  29. {
  30. foreach ($node->users() as $user) {
  31. $order = $user->orders()->activePlan()->first(); // 取出用户正在使用的套餐
  32. if ($order) {
  33. $speed_limit = $order->goods->getRawOriginal('speed_limit');
  34. } else {
  35. $speed_limit = $user->getRawOriginal('speed_limit');
  36. }
  37. $data[] = [
  38. 'uid' => $user->id,
  39. 'port' => $user->port,
  40. 'passwd' => $user->passwd,
  41. 'method' => $user->method,
  42. 'protocol' => $user->protocol,
  43. 'obfs' => $user->obfs,
  44. 'obfs_param' => $node->obfs_param,
  45. 'speed_limit' => $speed_limit,
  46. 'enable' => $user->enable,
  47. ];
  48. }
  49. return $this->returnData('获取用户列表成功', 'success', 200, $data ?? [], ['updateTime' => time()]);
  50. }
  51. }