Ken 5 zile în urmă
părinte
comite
fb0a0231b3
2 a modificat fișierele cu 25 adăugiri și 23 ștergeri
  1. 9 23
      app/Http/Controllers/api/TelegramWebHook.php
  2. 16 0
      app/Services/LogService.php

+ 9 - 23
app/Http/Controllers/api/TelegramWebHook.php

@@ -4,6 +4,7 @@ namespace App\Http\Controllers\api;
 
 
 use App\Constants\StepStatus;
 use App\Constants\StepStatus;
 use App\Constants\Util;
 use App\Constants\Util;
+use App\Services\LogService;
 use App\Services\PublicService;
 use App\Services\PublicService;
 use App\Services\QianBaoWithdrawService;
 use App\Services\QianBaoWithdrawService;
 use App\Services\SanJinRechargeService;
 use App\Services\SanJinRechargeService;
@@ -38,19 +39,12 @@ class TelegramWebHook extends BaseController
         parent::__construct();
         parent::__construct();
     }
     }
 
 
+    /**
+     * @throws TelegramSDKException
+     */
     public function handle(Request $request): JsonResponse
     public function handle(Request $request): JsonResponse
     {
     {
-        try {
-            $telegram = new Api(config('services.telegram.token'));
-        } catch (TelegramSDKException $e) {
-            return response()->json(['status' => 'ok']);
-        }
-
-
-
-
-
-
+        $telegram = new Api(config('services.telegram.token'));
 
 
         try {
         try {
             $update = $telegram->getWebhookUpdate(); // 获取更新数据
             $update = $telegram->getWebhookUpdate(); // 获取更新数据
@@ -88,15 +82,13 @@ class TelegramWebHook extends BaseController
                 }//
                 }//
                 catch (Exception $e) {
                 catch (Exception $e) {
                     DB::rollBack();
                     DB::rollBack();
-                    $json = json_encode(['line' => $e->getLine(), 'message' => $e->getMessage()]);
-                    Log::error('Telegram 处理消息异常: ');
-                    Log::error($json);
+                    LogService::error($e);
                     $telegram->sendMessage(['chat_id' => $chatId, 'text' => '‼️‼️系统发生了错误,请联系客服']);
                     $telegram->sendMessage(['chat_id' => $chatId, 'text' => '‼️‼️系统发生了错误,请联系客服']);
                 }
                 }
             } //
             } //
             else {
             else {
                 $update = $request->all();
                 $update = $request->all();
-                 if (isset($update['message'])) {
+                if (isset($update['message'])) {
                     $message = $update['message'];
                     $message = $update['message'];
                     $chatId = $message['chat']['id'];
                     $chatId = $message['chat']['id'];
                     $messageId = $message['message_id'];
                     $messageId = $message['message_id'];
@@ -120,9 +112,7 @@ class TelegramWebHook extends BaseController
                     }//
                     }//
                     catch (Exception $e) {
                     catch (Exception $e) {
                         DB::rollBack();
                         DB::rollBack();
-                        $json = json_encode(['line' => $e->getLine(), 'message' => $e->getMessage()]);
-                        Log::error('Telegram 处理消息异常: ');
-                        Log::error($json);
+                        LogService::error($e);
                         $telegram->sendMessage(['chat_id' => $chatId, 'text' => '‼️‼️系统发生了错误,请联系客服']);
                         $telegram->sendMessage(['chat_id' => $chatId, 'text' => '‼️‼️系统发生了错误,请联系客服']);
                     }
                     }
                 }
                 }
@@ -131,11 +121,7 @@ class TelegramWebHook extends BaseController
         } //
         } //
         catch (Exception $e) {
         catch (Exception $e) {
             if (!empty($chatId)) {
             if (!empty($chatId)) {
-                try {
-                    $telegram->sendMessage(['chat_id' => $chatId, 'text' => '‼️‼️系统发生了错误,请联系客服']);
-                } catch (TelegramSDKException $e) {
-
-                }
+                $telegram->sendMessage(['chat_id' => $chatId, 'text' => '‼️‼️系统发生了错误,请联系客服']);
             }
             }
         }
         }
         return response()->json(['status' => 'ok']);
         return response()->json(['status' => 'ok']);

+ 16 - 0
app/Services/LogService.php

@@ -0,0 +1,16 @@
+<?php
+
+namespace App\Services;
+
+use Exception;
+use Illuminate\Support\Facades\Log;
+
+class LogService
+{
+    public static function error(Exception $e): void
+    {
+        $json = json_encode(['line' => $e->getLine(), 'message' => $e->getMessage()]);
+        Log::error('Telegram 处理消息异常: ');
+        Log::error($json);
+    }
+}