SendTelegramGroupMessageJob.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace App\Jobs;
  3. use Illuminate\Bus\Queueable;
  4. use Illuminate\Contracts\Queue\ShouldQueue;
  5. use Illuminate\Foundation\Bus\Dispatchable;
  6. use Illuminate\Queue\InteractsWithQueue;
  7. use Illuminate\Queue\SerializesModels;
  8. use Telegram\Bot\Api;
  9. use Illuminate\Support\Facades\Log;
  10. use App\Services\BaseService;
  11. use DragonCode\PrettyArray\Services\Formatters\Base;
  12. use Telegram\Bot\Exceptions\TelegramResponseException;
  13. class SendTelegramGroupMessageJob implements ShouldQueue
  14. {
  15. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  16. public $chatId;
  17. public $text;
  18. public $buttons;
  19. public $image;
  20. public $isTop;
  21. public $separator;
  22. /**
  23. * @param string $chatId
  24. * @param string $text
  25. * @param array $buttons
  26. * @param string|null $image
  27. * @param string $separator 分隔符
  28. */
  29. public function __construct($text, $buttons = [], $image = null, $isTop = false, $separator = "\n")
  30. {
  31. $this->text = $text;
  32. $this->buttons = $buttons;
  33. $this->image = $image;
  34. $this->isTop = $isTop;
  35. $this->separator = $separator;
  36. }
  37. public function handle()
  38. {
  39. try {
  40. BaseService::bettingGroupNotice($this->text, $this->buttons, $this->image, $this->isTop, $this->separator);
  41. } catch (TelegramResponseException $e) {
  42. try {
  43. BaseService::bettingGroupNotice($this->text, $this->buttons, $this->image, $this->isTop, $this->separator);
  44. } catch (TelegramResponseException $e) {
  45. try {
  46. BaseService::bettingGroupNotice($this->text, $this->buttons, $this->image, $this->isTop, $this->separator);
  47. } catch (TelegramResponseException $e) {
  48. Log::error('Telegram 消息发送失败: ' . $e->getMessage());
  49. Log::error("失败消息: \n" . $this->text);
  50. }
  51. }
  52. }
  53. }
  54. }