TrojanController.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. // 获取节点信息
  8. public function getNodeInfo(Node $node): JsonResponse
  9. {
  10. return $this->returnData('获取节点信息成功', 'success', 200, [
  11. 'id' => $node->id,
  12. 'is_udp' => $node->is_udp ? true : false,
  13. 'speed_limit' => $node->getRawOriginal('speed_limit'),
  14. 'client_limit' => $node->client_limit,
  15. 'push_port' => $node->push_port,
  16. 'redirect_url' => sysConfig('redirect_url'),
  17. 'trojan_port' => $node->port,
  18. 'secret' => $node->auth->secret,
  19. 'license' => sysConfig('trojan_license'),
  20. ]);
  21. }
  22. // 获取节点可用的用户列表
  23. public function getUserList(Node $node): JsonResponse
  24. {
  25. foreach ($node->users() as $user) {
  26. $data[] = [
  27. 'uid' => $user->id,
  28. 'password' => $user->passwd,
  29. 'speed_limit' => $user->getRawOriginal('speed_limit'),
  30. 'client_limit' => $user->client_limit,
  31. ];
  32. }
  33. return $this->returnData('获取用户列表成功', 'success', 200, $data ?? [], ['updateTime' => time()]);
  34. }
  35. }