seven 3 giorni fa
parent
commit
df00e94415
1 ha cambiato i file con 34 aggiunte e 34 eliminazioni
  1. 34 34
      app/Http/Controllers/api/TelegramWebHook.php

+ 34 - 34
app/Http/Controllers/api/TelegramWebHook.php

@@ -70,8 +70,8 @@ class TelegramWebHook extends Controller
                 $message = $update['message'];
                 $chatId = $message['chat']['id'];
                 $messageId = $message['message_id'];
-                // DB::beginTransaction();
-                // try {
+                DB::beginTransaction();
+                try {
                     $m = new Message();
                     $m->json = json_encode($update);
                     $m->save();
@@ -80,38 +80,38 @@ class TelegramWebHook extends Controller
                     if($returnMsg){
                         $this->telegram->sendMessage($returnMsg);
                     }
-
-                // } 
-                //  catch (MessageException $e) {
-                //     DB::rollBack();
-                //     $msg = $e->getMessage();
-                //     $msg = json_decode($msg, true);
-                //     $telegram->sendMessage($msg);
-                // } //
-                // catch (TelegramSDKException $e) {
-                //     DB::rollBack();
-                //     $m = new Message();
-                //     $m->json = $e->getMessage();
-                //     $m->save();
-                //     $telegram->sendMessage([
-                //         'chat_id' => $chatId,
-                //         'text' => '‼️‼️系统发生了错误,请联系客服'
-                //     ]);
-                // }//
-                // catch (\Exception $e) {
-                //     DB::rollBack();
-                //     $m = new Message();
-                //     $m->json = json_encode([
-                //         'line' => $e->getLine(),
-                //         'message' => $e->getMessage()
-                //     ]);
-                //     $m->save();
-                //     Log::error('Telegram 处理消息异常: ' . $e->getMessage());
-                //     $telegram->sendMessage([
-                //         'chat_id' => $chatId,
-                //         'text' => '‼️‼️系统发生了错误,请联系客服'
-                //     ]);
-                // }
+                    DB::commit();
+                } 
+                 catch (MessageException $e) {
+                    DB::rollBack();
+                    $msg = $e->getMessage();
+                    $msg = json_decode($msg, true);
+                    $telegram->sendMessage($msg);
+                } //
+                catch (TelegramSDKException $e) {
+                    DB::rollBack();
+                    $m = new Message();
+                    $m->json = $e->getMessage();
+                    $m->save();
+                    $telegram->sendMessage([
+                        'chat_id' => $chatId,
+                        'text' => '‼️‼️系统发生了错误,请联系客服'
+                    ]);
+                }//
+                catch (\Exception $e) {
+                    DB::rollBack();
+                    $m = new Message();
+                    $m->json = json_encode([
+                        'line' => $e->getLine(),
+                        'message' => $e->getMessage()
+                    ]);
+                    $m->save();
+                    Log::error('Telegram 处理消息异常: ' . $e->getMessage());
+                    $telegram->sendMessage([
+                        'chat_id' => $chatId,
+                        'text' => '‼️‼️系统发生了错误,请联系客服'
+                    ]);
+                }
             }
 
         }