seven 2 hafta önce
ebeveyn
işleme
701feae01d

+ 59 - 0
app/Jobs/SendTelegramGroupMessageJob.php

@@ -0,0 +1,59 @@
+<?php
+
+
+namespace App\Jobs;
+
+use Illuminate\Bus\Queueable;
+use Illuminate\Contracts\Queue\ShouldQueue;
+use Illuminate\Foundation\Bus\Dispatchable;
+use Illuminate\Queue\InteractsWithQueue;
+use Illuminate\Queue\SerializesModels;
+use Telegram\Bot\Api;
+use Illuminate\Support\Facades\Log;
+use App\Services\BaseService;
+use DragonCode\PrettyArray\Services\Formatters\Base;
+
+class SendTelegramGroupMessageJob implements ShouldQueue
+{
+    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
+
+    public $chatId;
+    public $text;
+    public $buttons;
+    public $image;
+    public $isTop;
+
+    /**
+     * @param string $chatId
+     * @param string $text
+     * @param array $buttons
+     * @param string|null $image
+     */
+    public function __construct( $text, $buttons = [], $image = null ,$isTop = false)
+    {
+        $this->text = $text;
+        $this->buttons = $buttons;
+        $this->image = $image;
+        $this->isTop = $isTop;
+    }
+
+    public function handle()
+    {
+        try {
+            BaseService::bettingGroupNotice($this->text, $this->buttons, $this->image,$this->isTop);
+        } catch (\Telegram\Bot\Exceptions\TelegramResponseException $e) {
+            // 捕获 Too Many Requests
+            if (str_contains($e->getMessage(), 'Too Many Requests')) {
+                preg_match('/retry after (\d+)/', $e->getMessage(), $matches);
+                $retryAfter = $matches[1] ?? 5;
+                Log::warning("Telegram 429 限制,等待 {$retryAfter} 秒重试...");
+                sleep($retryAfter + 1);
+
+                // 重试
+                $this->handle();
+            } else {
+                Log::error('Telegram 消息发送失败: '.$e->getMessage());
+            }
+        }
+    }
+}

+ 3 - 1
app/Services/BetService.php

@@ -20,6 +20,7 @@ use App\Services\IssueService;
 use App\Services\UserService;
 use App\Services\BalanceLogService;
 use App\Jobs\SendTelegramMessageJob;
+use App\Jobs\SendTelegramGroupMessageJob;
 
 /**
  * 投注
@@ -925,7 +926,8 @@ class BetService extends BaseService
         // }
 
         // 群通知
-        self::bettingGroupNotice($text, $inlineButton, '');
+        // self::bettingGroupNotice($text, $inlineButton, '');
+        SendTelegramGroupMessageJob::dispatch($text,$inlineButton,'');
     }