SendTgMegJob.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace App\Jobs;
  3. use App\Repositories\Service\CommonService;
  4. use Illuminate\Bus\Queueable;
  5. use Illuminate\Contracts\Queue\ShouldBeUnique;
  6. use Illuminate\Contracts\Queue\ShouldQueue;
  7. use Illuminate\Foundation\Bus\Dispatchable;
  8. use Illuminate\Queue\InteractsWithQueue;
  9. use Illuminate\Queue\SerializesModels;
  10. use Modules\Api\Services\ConfigService;
  11. class SendTgMegJob implements ShouldQueue
  12. {
  13. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  14. public $params;
  15. public $name;
  16. public $message;
  17. /**
  18. * Create a new job instance.
  19. *
  20. * @return void
  21. */
  22. public function __construct($name,$message,$params)
  23. {
  24. $this->name = $name;
  25. $this->params = $params;
  26. $this->message = $message;
  27. }
  28. /**
  29. * Execute the job.
  30. *
  31. * @return void
  32. */
  33. public function handle()
  34. {
  35. $configService = make(ConfigService::class);
  36. $tgMsgServer = $configService->getValue('tg_msg_server');
  37. $tgApiToken = $configService->getValue('tg_api_token');
  38. if ($tgMsgServer && $tgApiToken) {
  39. $content = json_encode($this->params,JSON_UNESCAPED_UNICODE);
  40. make(CommonService::class)->httpPost(
  41. [
  42. 'name' => $this->name,
  43. 'message' => $this->message,
  44. 'content'=>$content,
  45. 'title' => '支付中心'
  46. ],
  47. $tgMsgServer . 'api/tg/send/message',
  48. ['AUTH-TOKEN' => $tgApiToken]);
  49. }
  50. }
  51. }