VNetController.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace App\Http\Controllers\Api\WebApi;
  3. use App\Models\SsNode;
  4. use App\Models\User;
  5. use Illuminate\Http\Request;
  6. class VNetController extends BaseController {
  7. // 获取节点信息
  8. public function getNodeInfo($id) {
  9. $node = SsNode::query()->whereId($id)->first();
  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->speed_limit,
  18. 'client_limit' => $node->client_limit,
  19. 'single' => $node->single,
  20. 'port' => $node->port,
  21. 'passwd' => $node->passwd,
  22. 'push_port' => $node->push_port,
  23. ]);
  24. }
  25. // 获取节点可用的用户列表
  26. public function getUserList(Request $request, $id) {
  27. $node = SsNode::query()->whereId($id)->first();
  28. $users = User::query()->where('status', '<>', -1)->whereEnable(1)->where('level', '>=', $node->level)->get();
  29. $data = [];
  30. foreach($users as $user){
  31. $new = [
  32. 'uid' => $user->id,
  33. 'port' => $user->port,
  34. 'passwd' => $user->passwd,
  35. 'method' => $user->method,
  36. 'protocol' => $user->protocol,
  37. 'obfs' => $user->obfs,
  38. 'obfs_param' => $node->obfs_param,
  39. 'speed_limit' => $user->speed_limit,
  40. 'enable' => $user->enable
  41. ];
  42. array_push($data, $new);
  43. }
  44. if($data){
  45. return $this->returnData('获取用户列表成功', 'success', 200, $data, ['updateTime' => time()]);
  46. }
  47. return $this->returnData('获取用户列表失败');
  48. }
  49. }