seven vor 1 Tag
Ursprung
Commit
51e269e047
2 geänderte Dateien mit 45 neuen und 5 gelöschten Zeilen
  1. 18 5
      app/Http/Controllers/api/TelegramWebHook.php
  2. 27 0
      app/Services/BaseService.php

+ 18 - 5
app/Http/Controllers/api/TelegramWebHook.php

@@ -28,6 +28,7 @@ use App\Models\Config;
 use App\Services\GameplayRuleService;
 use App\Services\BetService;
 use App\Services\IssueService;
+use App\Services\KeyboardService;
 
 class TelegramWebHook extends Controller
 {
@@ -524,6 +525,7 @@ class TelegramWebHook extends Controller
      */    
     public function setReplyKeyboard($chatId)
     {
+        $replyInfo = KeyboardService::findOne(['button' => '开始使用']);
         $telegram = new Api(config('services.telegram.token'));
 
         $keyboard = [
@@ -538,11 +540,22 @@ class TelegramWebHook extends Controller
             'one_time_keyboard' => false, // 保持显示,不会点击后收起
         ];
 
-        $telegram->sendMessage([
-            'chat_id' => $chatId,
-            'text' => '你好,请选择功能菜单',
-            'reply_markup' => json_encode($replyMarkup),
-        ]);
+        if($replyInfo){
+            $image = '';
+            if($replyInfo->image){
+                $image = url($replyInfo->image);
+
+            }
+            KeyboardService::sendMessage($chatId, $replyInfo->text, $keyboard ,$image);
+        }else{
+             $telegram->sendMessage([
+                'chat_id' => $chatId,
+                'text' => '你好,请选择功能菜单',
+                'reply_markup' => json_encode($replyMarkup),
+            ]);
+        }
+
+       
     }
 
 

+ 27 - 0
app/Services/BaseService.php

@@ -166,6 +166,33 @@ class BaseService
         
     }
 
+    /**
+     * @description: 发送消息
+     * @param {string} $chatId 聊天ID
+     * @param {string} $text 消息内容
+     * @param {array} $keyboard 操作按钮
+     * @param {*string} $image  图片
+     * @return {*}
+     */
+    public static function sendMessage($chatId ,$text ,$keyboard = [] ,$image = '')
+    {
+        $botMsg = [
+            'chat_id' => $chatId,
+        ];
+        if(count($keyboard)>0){
+            $botMsg['reply_markup'] = json_encode(['inline_keyboard' => $keyboard]);
+        }
+        if($image != ''){
+            $botMsg['photo'] = InputFile::create($image);
+            $botMsg['caption'] = $text;
+            $botMsg['protect_content'] = true;  // 防止转发
+            self::telegram()->sendPhoto($botMsg);
+        }else{
+            $botMsg['text'] = $text;
+            self::telegram()->sendMessage($botMsg);
+        }
+    }
+
     /**
      * @description: 弹窗提示
      * @param {*} $memberId