delUser.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace App\Jobs\VNet;
  3. use GuzzleHttp\Client;
  4. use Illuminate\Bus\Queueable;
  5. use Illuminate\Contracts\Queue\ShouldQueue;
  6. use Illuminate\Foundation\Bus\Dispatchable;
  7. use Illuminate\Queue\InteractsWithQueue;
  8. use Illuminate\Queue\SerializesModels;
  9. class delUser implements ShouldQueue
  10. {
  11. use Dispatchable;
  12. use InteractsWithQueue;
  13. use Queueable;
  14. use SerializesModels;
  15. private $userIds;
  16. private $nodes;
  17. public function __construct($userIds, $nodes)
  18. {
  19. $this->userIds = $userIds;
  20. $this->nodes = $nodes;
  21. }
  22. public function handle(): void
  23. {
  24. foreach ($this->nodes as $node) {
  25. $this->send(
  26. ($node->server ?: $node->ip) . ':' . $node->push_port,
  27. $node->auth->secret
  28. );
  29. }
  30. }
  31. private function send($host, $secret): void
  32. {
  33. $client = new Client(
  34. [
  35. 'base_uri' => $host,
  36. 'timeout' => 15,
  37. 'headers' => ['secret' => $secret],
  38. ]
  39. );
  40. if (is_array($this->userIds)) {
  41. $client->post('api/v2/user/del/list', ['json' => $this->userIds]);
  42. } else {
  43. $client->post('api/user/del/' . $this->userIds);
  44. }
  45. }
  46. }