Home.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <?php
  2. /*
  3. * @Author: Qing 948634023@qq.com
  4. * @Date: 2026-01-13 20:52:55
  5. * @LastEditors: Qing 948634023@qq.com
  6. * @LastEditTime: 2026-03-09 21:03:50
  7. * @FilePath: \bot-28\app\Http\Controllers\api\Home.php
  8. * @Description:
  9. * ${git_name}
  10. * Copyright (c) 2026 by ${git_name_email}, All Rights Reserved.
  11. */
  12. namespace App\Http\Controllers\api;
  13. use App\Http\Controllers\Controller;
  14. use App\Models\Message;
  15. use App\Models\PcIssue;
  16. use App\Services\BaseService;
  17. use App\Services\IssueService;
  18. use App\Services\PcIssueService;
  19. use Carbon\Carbon;
  20. use Illuminate\Support\Facades\DB;
  21. use Telegram\Bot\Api;
  22. use Telegram\Bot\Exceptions\TelegramSDKException;
  23. use Telegram\Bot\FileUpload\InputFile;
  24. use Telegram\Bot\Objects\BotCommand;
  25. use Illuminate\Support\Facades\Log;
  26. class Home extends Controller
  27. {
  28. public function index()
  29. {
  30. return view('login');
  31. }
  32. public function home()
  33. {
  34. $menu = [
  35. [
  36. 'icon' => 'layui-icon-user',
  37. 'name' => '会员管理',
  38. 'href' => url('/user/list'),
  39. 'children' => [
  40. // [
  41. // 'icon' => '',
  42. // 'name' => '会员列表',
  43. // 'href' => url('user/list'),
  44. // ],
  45. ],
  46. ],
  47. [
  48. 'icon' => 'layui-icon-user',
  49. 'name' => '充值管理',
  50. 'href' => url('/topup/list'),
  51. 'children' => [],
  52. ],
  53. [
  54. 'icon' => 'layui-icon-user',
  55. 'name' => '房间管理',
  56. 'href' => url('user/list'),
  57. 'children' => [],
  58. ],
  59. [
  60. 'icon' => 'layui-icon-user',
  61. 'name' => '提现管理',
  62. 'href' => url('user/list'),
  63. 'children' => [],
  64. ],
  65. [
  66. 'icon' => 'layui-icon-user',
  67. 'name' => '钱包记录',
  68. 'href' => url('user/list'),
  69. 'children' => [],
  70. ],
  71. [
  72. 'icon' => 'layui-icon-user',
  73. 'name' => '设置',
  74. 'href' => url('user/list'),
  75. 'children' => [
  76. [
  77. 'icon' => '',
  78. 'name' => '修改密码',
  79. 'href' => url('user/list'),
  80. ],
  81. ],
  82. ],
  83. ];
  84. return view('home', ['menu' => $menu]);
  85. }
  86. public function setMyCommands()
  87. {
  88. try {
  89. $telegram = new Api(config('services.telegram.token'));
  90. $commands = [
  91. new BotCommand(['command' => 'start', 'description' => lang('🤖开始使用')]),
  92. // new BotCommand(['command' => 'room', 'description' => '🏠创建房间']),
  93. // new BotCommand(['command' => 'online', 'description' => '🟢在线房间']),
  94. // new BotCommand(['command' => 'topup', 'description' => '🔋账户管理']),
  95. // new BotCommand(['command' => 'withdraw', 'description' => '🏦提现管理']),
  96. // new BotCommand(['command' => 'tutorial', 'description' => '💡教程帮助']),
  97. // new BotCommand(['command' => 'record', 'description' => '🏆我的战绩']),
  98. ];
  99. $telegram->setMyCommands(['commands' => $commands]);
  100. } catch (TelegramSDKException $e) {
  101. }
  102. return $this->success();
  103. }
  104. public function setMenuButton()
  105. {
  106. // try {
  107. // $telegram = new Api(config('services.telegram.token'));
  108. // $res = $telegram->setMenuButton(['text' => '菜单', 'web_app' => ['url' => url('/api/onMessage')]]);
  109. // } catch (TelegramSDKException $e) {
  110. // return $this->error($e->getCode(), $e->getMessage());
  111. // }
  112. $chatId = 6325700519; // 替换为实际的 chat_id
  113. $res = $this->setReplyKeyboard($chatId); // 替换为实际的 chat_id
  114. return $this->success($res);
  115. }
  116. public function setReplyKeyboard($chatId)
  117. {
  118. $telegram = new Api(config('services.telegram.token'));
  119. $keyboard = [
  120. ['近期注单', '今日流水', '联系客服'], // 第一排按钮
  121. ['开奖历史', '当期下注', '查看余额'], // 第二排按钮
  122. ['投注大群']
  123. ];
  124. $replyMarkup = [
  125. 'keyboard' => $keyboard,
  126. 'resize_keyboard' => true, // 自适应大小
  127. 'one_time_keyboard' => false, // 保持显示,不会点击后收起
  128. ];
  129. $telegram->sendMessage([
  130. 'chat_id' => $chatId,
  131. 'text' => '你好,请选择功能菜单',
  132. 'reply_markup' => json_encode($replyMarkup),
  133. ]);
  134. }
  135. public function setWebHook()
  136. {
  137. $this->setMyCommands();
  138. try {
  139. $telegram = new Api(config('services.telegram.token'));
  140. // 设置 Webhook
  141. $webhookUrl = url('/api/onMessage'); // Webhook URL,指向刚才定义的路由
  142. $allowed_updates = [
  143. 'message', 'callback_query',
  144. // 'message_reaction', 'message_reaction_count',
  145. // 'removed_chat_boost', 'chat_boost',
  146. // 'chat_join_request', 'chat_member'
  147. ];
  148. $res = $telegram->setWebhook(['url' => $webhookUrl, 'allowed_updates' => $allowed_updates, 'drop_pending_updates' => true]);
  149. } catch (TelegramSDKException $e) {
  150. return $this->error($e->getCode(), $e->getMessage());
  151. }
  152. Log::info('Telegram 回调数据(JSON): ' . json_encode([123454], JSON_UNESCAPED_UNICODE));
  153. return $this->success($res);
  154. }
  155. }