Ken 2 недель назад
Родитель
Сommit
d8b3da6c89
2 измененных файлов с 47 добавлено и 14 удалено
  1. 19 12
      app/Http/Controllers/api/TelegramWebHook.php
  2. 28 2
      app/Services/TopUpService.php

+ 19 - 12
app/Http/Controllers/api/TelegramWebHook.php

@@ -106,15 +106,22 @@ class TelegramWebHook extends Controller
                     BetService::alertNotice($callbackId, $alertText);
                 }
 
+                //选择充值地址
+                if ($data === "topup@@TRC20" || $data === "topup@@ERC20") {
+                    $type = preg_replace('/^topup@@/', '', $data);
+                    $topService = new TopUpService();
+                    $res = $topService->scan($chatId, $messageId);
+                    $telegram->sendPhoto($res);
+                }
+
                 //点击充值按钮
                 if ($data === 'topup@@topup') {
                     $telegram->deleteMessage([
                         'chat_id' => $chatId,
                         'message_id' => $messageId,
                     ]);
-                    $topService = new TopUpService();
-                    $res = $topService->scan($chatId, $messageId);
-                    $telegram->sendPhoto($res);
+                    $res = TopUpService::chooseAddress($chatId, $messageId);
+                    $telegram->editMessageText($res);
                 }
 
                 //点击充值的账单按钮
@@ -353,12 +360,12 @@ class TelegramWebHook extends Controller
 
                     $returnMsg = $this->processChatMessage($chatId, $messageId, $message, $message['from']);
                     if ($returnMsg) {
-                        if(isset($returnMsg['photo']) && $returnMsg['photo'] != ''){
+                        if (isset($returnMsg['photo']) && $returnMsg['photo'] != '') {
                             $this->telegram->sendPhoto($returnMsg);
-                        }else{
+                        } else {
                             $this->telegram->sendMessage($returnMsg);
                         }
-                        
+
                     }
                     DB::commit();
                 } catch (MessageException $e) {
@@ -566,13 +573,13 @@ class TelegramWebHook extends Controller
                                 unset($res['text']);
                                 $res['caption'] = $text;
                                 $res['protect_content'] = true;  // 防止转发
-                                
+
                             }
 
                             return $res;
                             break;
                         }
-                        
+
                         $stepStatus = Cache::get(get_step_key($chatId), -1);
                         $stepStatus = intval($stepStatus);
                         switch ($stepStatus) {
@@ -619,20 +626,20 @@ class TelegramWebHook extends Controller
             ['投注大群']
         ];
 
-        if($replyInfo && $replyInfo->buttons){
+        if ($replyInfo && $replyInfo->buttons) {
             $keyboard = [];
             $buttons = json_decode($replyInfo->buttons, true);
 
             foreach ($buttons as $rowIndex => $row) {
-                if(!empty($row)){
+                if (!empty($row)) {
                     foreach ($row as $buttonIndex => $button) {
                         $keyboard[$rowIndex][$buttonIndex] = $button['text'];
                     }
                 }
-                
+
             }
             $keyboard = array_values($keyboard); // 重新索引数组
-            Log::error('自定义开始使用按钮: '.json_encode($keyboard));
+            Log::error('自定义开始使用按钮: ' . json_encode($keyboard));
 
         }
 

+ 28 - 2
app/Services/TopUpService.php

@@ -176,6 +176,32 @@ class TopUpService
         ];
     }
 
+    public static function chooseAddress($chatId, $messageId)
+    {
+//        $address = Config::where('field', 'receiving_address')->first()->val;
+//        $address1 = Config::where('field', 'receiving_address')->first()->val;
+
+        $keyboard = [
+            [
+                ['text' => 'TRC20', 'callback_data' => 'topUp@@TRC20'],
+                ['text' => 'ERC20', 'callback_data' => 'topUp@@ERC20']
+            ],
+            [
+                ['text' => "🔙返回", 'callback_data' => "topUp@@home1"],
+            ]
+        ];
+
+        $text = '请选择网络类型';
+        return [
+            'chat_id' => $chatId,
+            'text' => $text,
+            'reply_markup' => json_encode(['inline_keyboard' => $keyboard]),
+            'message_id' => $messageId,
+        ];
+
+
+    }
+
     //获取充值二维码
     public function scan($chatId, $messageId)
     {
@@ -198,9 +224,9 @@ class TopUpService
 
         $replyInfo = KeyboardService::findOne(['button' => '充值提示文字']);
         $caption = "\n";
-        if($replyInfo){
+        if ($replyInfo) {
             $caption .= "{$replyInfo->reply}\n\n";
-        }else{
+        } else {
             $caption .= "支持货币({$res['net']}):{$res['coin']}\n";
             $caption .= "专属收款地址:\n";
             $caption .= "{$address}\n";