TrojanController.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace App\Http\Controllers\Api\WebApi;
  3. use App\Models\Node;
  4. use Illuminate\Http\JsonResponse;
  5. class TrojanController extends BaseController {
  6. // 获取节点信息
  7. public function getNodeInfo($id): JsonResponse {
  8. $node = Node::find($id);
  9. return $this->returnData('获取节点信息成功', 'success', 200, [
  10. 'id' => $node->id,
  11. 'is_udp' => $node->is_udp? true : false,
  12. 'speed_limit' => $node->speed_limit,
  13. 'client_limit' => $node->client_limit,
  14. 'push_port' => $node->push_port,
  15. 'redirect_url' => sysConfig('redirect_url'),
  16. 'trojan_port' => $node->port,
  17. 'secret' => $node->auth->secret,
  18. 'license' => sysConfig('trojan_license'),
  19. ]);
  20. }
  21. // 获取节点可用的用户列表
  22. public function getUserList($id): JsonResponse {
  23. $users = Node::find($id)->node_access_users;
  24. $data = [];
  25. foreach($users as $user){
  26. $data[] = [
  27. 'uid' => $user->id,
  28. 'password' => $user->passwd,
  29. 'speed_limit' => $user->speed_limit
  30. ];
  31. }
  32. return $this->returnData('获取用户列表成功', 'success', 200, $data, ['updateTime' => time()]);
  33. }
  34. }