Ken vor 5 Tagen
Ursprung
Commit
f039e13055

+ 44 - 48
app/Http/Controllers/api/TelegramWebHook.php

@@ -16,8 +16,8 @@ use App\Services\TopUpService;
 use App\Services\TutorialService;
 use App\Services\UserService;
 use App\Services\WalletService;
-use App\Services\WithdrawService;   
-use App\Services\BalanceLogService;   
+use App\Services\WithdrawService;
+use App\Services\BalanceLogService;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\Cache;
 use Illuminate\Support\Facades\DB;
@@ -44,10 +44,10 @@ class TelegramWebHook extends Controller
     {
         Log::error('Telegram 日志写入测试: ' . json_encode([$request->ip()], JSON_UNESCAPED_UNICODE));
         // try {
-            $m = new Message();
-            $m->json = $request->ip();
-            $m->save();
-            $telegram = new Api(config('services.telegram.token'));
+        $m = new Message();
+        $m->json = $request->ip();
+        $m->save();
+        $telegram = new Api(config('services.telegram.token'));
         // } catch (TelegramSDKException $e) {
         //     return response()->json(['status' => 'ok']);
         // }
@@ -67,7 +67,7 @@ class TelegramWebHook extends Controller
             Util::delCache($message->chat->id);
             Log::error('Telegram 回调数据(JSON): ' . json_encode($update, JSON_UNESCAPED_UNICODE));
 
-             DB::beginTransaction();
+            DB::beginTransaction();
             try {
                 $chatId = $message->chat->id;
                 $firstName = $message->chat->firstName;
@@ -87,21 +87,21 @@ class TelegramWebHook extends Controller
                 //给每个用户生成一个专属的USDT钱包
                 WalletService::getUserWallet($chatId);
 
-                
+
                 // 查看余额弹窗
-                if($data === 'balanceAlert'){
+                if ($data === 'balanceAlert') {
                     $alertText = WalletService::getBalance($chatId)['text'];
-                    WalletService::alertNotice($callbackId , $alertText);
+                    WalletService::alertNotice($callbackId, $alertText);
                 }
                 // 今日流水弹窗
-                if($data === 'todayFlowAlert'){
+                if ($data === 'todayFlowAlert') {
                     $alertText = BalanceLogService::getTodayFlowing($chatId)['text'];
-                    BalanceLogService::alertNotice($callbackId , $alertText);
+                    BalanceLogService::alertNotice($callbackId, $alertText);
                 }
                 // 近期注单弹窗
-                if($data === 'betsAlert'){
+                if ($data === 'betsAlert') {
                     $alertText = BetService::recentlyRecord($chatId);
-                    BetService::alertNotice($callbackId , $alertText);
+                    BetService::alertNotice($callbackId, $alertText);
                 }
 
                 //点击充值按钮
@@ -131,7 +131,7 @@ class TelegramWebHook extends Controller
 //                    ]);
                 }
 
-                                //点击我已付款按钮
+                //点击我已付款按钮
                 //手动充值(后台审核后到账)
                 if ($data === 'topUp@@pay2') {
                     $telegram->deleteMessage([
@@ -160,7 +160,7 @@ class TelegramWebHook extends Controller
                         'message_id' => $messageId
                     ]);
                     $returnMsg = WalletService::getBalance($chatId);
-                    if($returnMsg){
+                    if ($returnMsg) {
                         $this->telegram->sendMessage($returnMsg);
                     }
                     // if ($data === "topUp@@home1") {
@@ -188,7 +188,6 @@ class TelegramWebHook extends Controller
                 }
 
 
-
                 //关闭本条消息
                 if ($data === 'message@@close') {
                     $telegram->deleteMessage([
@@ -211,7 +210,7 @@ class TelegramWebHook extends Controller
                         'message_id' => $messageId
                     ]);
                     $returnMsg = WalletService::getBalance($chatId);
-                    if($returnMsg){
+                    if ($returnMsg) {
                         $this->telegram->sendMessage($returnMsg);
                     }
                 }
@@ -268,7 +267,6 @@ class TelegramWebHook extends Controller
                     $telegram->editMessageText($res);
                 }
 
-                
 
                 //提现账单,下一页
                 $pattern = "/^withdrawBillNextPage@@\d+$/";
@@ -284,10 +282,10 @@ class TelegramWebHook extends Controller
                 if (preg_match($pattern, $data)) {
                     $page = preg_replace('/^betRecordNextPage@@/', '', $data);
                     $page = intval($page);
-                    $res = BetService::record($chatId ,$messageId ,$page );
+                    $res = BetService::record($chatId, $messageId, $page);
                     $telegram->editMessageText($res);
                 }
-                 DB::commit();
+                DB::commit();
             } //
             catch (MessageException $e) {
                 DB::rollBack();
@@ -319,7 +317,7 @@ class TelegramWebHook extends Controller
                 ]);
             }
 
-        }else {
+        } else {
             $update = $request->all();
             Log::error('Telegram 文字消息回复: ' . json_encode($update, JSON_UNESCAPED_UNICODE));
             if (isset($update['message'])) {
@@ -333,12 +331,11 @@ class TelegramWebHook extends Controller
                     $m->save();
 
                     $returnMsg = $this->processChatMessage($chatId, $messageId, $message, $message['from']);
-                    if($returnMsg){
+                    if ($returnMsg) {
                         $this->telegram->sendMessage($returnMsg);
                     }
                     DB::commit();
-                } 
-                 catch (MessageException $e) {
+                } catch (MessageException $e) {
                     DB::rollBack();
                     $msg = $e->getMessage();
                     $msg = json_decode($msg, true);
@@ -381,7 +378,7 @@ class TelegramWebHook extends Controller
      * @param {*} $message
      * @param {*} $from
      * @return {*}
-     */    
+     */
     public function processChatMessage($chatId, $messageId, $message, $from)
     {
         $returnMsg = [];
@@ -411,12 +408,7 @@ class TelegramWebHook extends Controller
             if ($message['chat']['type'] === 'private') {
                 switch ($text) {
                     case "/start":
-                        $telegram = new Api(config('services.telegram.token'));
-                        $telegram->sendMessage([
-                            'chat_id' => $chatId,
-                            'text' =>json_encode($message),
-                        ]);
-return;
+
 
                         Util::delCache($chatId);
                         $user = User::where('member_id', $chatId)->first();
@@ -425,6 +417,11 @@ return;
                             $user->member_id = $chatId;
                         }
                         $user->first_name = $message['chat']['first_name'];
+                        if (isset($message['chat']['username'])) {
+                            $user->username = $message['chat']['username'];
+                        }
+
+
                         $user->save();
                         //给每个用户生成一个专属的USDT钱包
                         WalletService::getUserWallet($chatId);
@@ -515,10 +512,10 @@ return;
                                 $res = WithdrawService::inputAlias($chatId, $text, $messageId);
                                 return $res;
                                 break;
-                            
+
                         }
-                        $returnMsg = BetService::bet($chatId,$text,$messageId);
-                        // $this->telegram->sendMessage($returnMsg);
+                        $returnMsg = BetService::bet($chatId, $text, $messageId);
+                    // $this->telegram->sendMessage($returnMsg);
                 }
 
                 return $returnMsg;
@@ -530,7 +527,7 @@ return;
      * @description: 设置 start 回复菜单
      * @param {*} $chatId
      * @return {*}
-     */    
+     */
     public function setReplyKeyboard($chatId)
     {
         $replyInfo = KeyboardService::findOne(['button' => '开始使用']);
@@ -551,32 +548,32 @@ return;
         ];
         $botMsg['reply_markup'] = json_encode($replyMarkup);
 
-        if($replyInfo){
+        if ($replyInfo) {
             $image = '';
-            if($replyInfo->image){
+            if ($replyInfo->image) {
                 $image = url($replyInfo->image);
 
             }
-            
-            if($image != ''){
+
+            if ($image != '') {
                 $botMsg['photo'] = InputFile::create($image);
                 $botMsg['caption'] = $replyInfo->reply;
                 $botMsg['protect_content'] = true;  // 防止转发
                 KeyboardService::telegram()->sendPhoto($botMsg);
-            }else{
+            } else {
                 $botMsg['text'] = $replyInfo->reply;
-                
+
                 KeyboardService::telegram()->sendMessage($botMsg);
             }
-        }else{
-             $telegram->sendMessage([
+        } else {
+            $telegram->sendMessage([
                 'chat_id' => $chatId,
                 'text' => '你好,请选择功能菜单',
                 'reply_markup' => json_encode($replyMarkup),
             ]);
         }
 
-       
+
     }
 
 
@@ -620,10 +617,10 @@ return;
                 WalletService::getUserWallet($chatId);
 
                 // 查看余额弹窗
-                if($data === 'balanceAlert'){
+                if ($data === 'balanceAlert') {
                     Log::error('查看余额弹窗 balanceAlert: ' . $callbackId);
                     // $alertText = WalletService::getBalance($chatId)['text'];
-                    WalletService::alertNotice($callbackId , '您好,您的余额为:');
+                    WalletService::alertNotice($callbackId, '您好,您的余额为:');
                 }
 
                 //取消创建游戏
@@ -880,7 +877,6 @@ return;
                     $telegram->editMessageText($res);
                 }
 
-                
 
                 //提现账单,下一页
                 $pattern = "/^withdrawBillNextPage@@\d+$/";

+ 2 - 0
composer.json

@@ -1,6 +1,8 @@
 {
   "name": "laravel/laravel",
   "type": "project",
+  "minimum-stability": "dev",
+  "prefer-stable": true,
   "description": "The Laravel Framework.",
   "keywords": [
     "framework",

+ 1 - 1
config/database.php

@@ -57,7 +57,7 @@ return [
             'prefix' => env('DB_PREFIX','forge_'),
             'prefix_indexes' => true,
             'strict' => true,
-            'engine' => null,
+            'engine' => "InnoDB",
             'options' => extension_loaded('pdo_mysql') ? array_filter([
                 PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
             ]) : [],

+ 2 - 1
database/migrations/2019_08_19_000000_create_failed_jobs_table.php

@@ -13,9 +13,10 @@ return new class extends Migration
      */
     public function up()
     {
+
         Schema::create('failed_jobs', function (Blueprint $table) {
             $table->id();
-            $table->string('uuid')->unique();
+            $table->string('uuid',50)->unique();
             $table->text('connection');
             $table->text('queue');
             $table->longText('payload');

+ 0 - 86
example.env

@@ -1,86 +0,0 @@
-# 以下配置仅为示例
-
-# APP配置
-APP_NAME=Bot
-APP_DEBUG=true
-APP_URL=
-
-# TG机器人
-TELEGRAM_BOT_TOKEN=
-TELEGRAM_BOT_USERNAME=
-
-# 平台归集地址
-USDT_ADDRESS=
-
-# TRX能量账户私钥
-TRX_PRIVATE_KEY=
-
-# TRON网络正式main或者测试test
-TRON_NETWORK=main
-
-# 数据库
-DB_CONNECTION=mysql
-DB_HOST=127.0.0.1
-DB_PORT=3306
-DB_DATABASE=bot
-DB_USERNAME=root
-DB_PASSWORD=123456
-DB_PREFIX=mf_
-
-# 邮件
-MAIL_MAILER=smtp
-MAIL_ENCRYPTION=tls
-MAIL_PORT=587
-MAIL_FROM_NAME="${APP_NAME}"
-MAIL_HOST=smtp.gmail.com
-MAIL_FROM_ADDRESS="your_email@gmail.com"
-MAIL_USERNAME=your_email@gmail.com
-MAIL_PASSWORD=your_email_password
-MAIL_EXP=600 # 邮件验证码有效期(秒)
-
-# JWT配置
-JWT_SECRET=881FrcXs
-JWT_EXP=86400
-
-
-
-
-# 以下为默认配置,酌情修改
-APP_ENV=local
-#APP_URL=http://127.0.0.1
-APP_KEY=base64:tXGso+GNVDKar7VfmDPejiXmpOnQerxUmlpQJMS5rZk=
-LOG_CHANNEL=stack
-LOG_DEPRECATIONS_CHANNEL=null
-LOG_LEVEL=error
-BROADCAST_DRIVER=log
-CACHE_DRIVER=file
-FILESYSTEM_DISK=local
-QUEUE_CONNECTION=sync
-SESSION_DRIVER=file
-SESSION_LIFETIME=120
-MEMCACHED_HOST=127.0.0.1
-REDIS_HOST=127.0.0.1
-REDIS_PASSWORD=null
-REDIS_PORT=6379
-AWS_ACCESS_KEY_ID=
-AWS_SECRET_ACCESS_KEY=
-AWS_DEFAULT_REGION=us-east-1
-AWS_BUCKET=
-AWS_USE_PATH_STYLE_ENDPOINT=false
-PUSHER_APP_ID=
-PUSHER_APP_KEY=
-PUSHER_APP_SECRET=
-PUSHER_HOST=
-PUSHER_PORT=443
-PUSHER_SCHEME=https
-PUSHER_APP_CLUSTER=mt1
-VITE_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
-VITE_PUSHER_HOST="${PUSHER_HOST}"
-VITE_PUSHER_PORT="${PUSHER_PORT}"
-VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
-VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
-
-
-
-
-