delUser.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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(($node->server ?: $node->ip).':'.$node->push_port, $node->auth->secret);
  26. }
  27. }
  28. private function send($host, $secret): void
  29. {
  30. $client = new Client([
  31. 'base_uri' => $host,
  32. 'timeout' => 15,
  33. 'headers' => ['secret' => $secret],
  34. ]);
  35. if (is_array($this->userIds)) {
  36. $client->post('api/v2/user/del/list', ['json' => $this->userIds]);
  37. } else {
  38. $client->post('api/user/del/'.$this->userIds);
  39. }
  40. }
  41. }