InitAppPackJob.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * app 打包 初始化
  4. */
  5. namespace App\Jobs;
  6. use App\Models\Mysql\PackModel;
  7. use GuzzleHttp\Client;
  8. use Illuminate\Bus\Queueable;
  9. use Illuminate\Contracts\Queue\ShouldQueue;
  10. use Illuminate\Foundation\Bus\Dispatchable;
  11. use Illuminate\Queue\InteractsWithQueue;
  12. use Illuminate\Queue\SerializesModels;
  13. class InitAppPackJob implements ShouldQueue
  14. {
  15. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  16. protected $params = [];
  17. /**
  18. * @param array $params
  19. */
  20. public function __construct(array $params = [])
  21. {
  22. $this->params = $params;
  23. }
  24. /**
  25. *
  26. * @return void
  27. */
  28. public function handle()
  29. {
  30. $formData = [
  31. 'timeout' => 30,
  32. 'headers' => [
  33. 'X-TOKEN' => env('PACK_TOKEN', 'NrVcnuCUveQbr'),
  34. 'Content-Type' => 'application/json',
  35. 'Accept' => 'application/json',
  36. ],
  37. 'json' => [$this->params],
  38. ];
  39. logger('--母包初始化--',$formData);
  40. $url = env('PACK_URL', 'http://dispatch_php.test.wg8.site') . '/api/channel/init/mom';
  41. $Client = new Client();
  42. try {
  43. $res = $Client->post($url, $formData);
  44. } catch (\Exception $exception) {
  45. logger('母包初始化失败!-' . $exception->getMessage(), $this->params);
  46. return;
  47. }
  48. logger('--母包初始化返回数据--'.$res->getBody()->getContents());
  49. }
  50. }