Home.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. class Home extends Controller
  26. {
  27. public function index()
  28. {
  29. return view('login');
  30. }
  31. public function home()
  32. {
  33. $menu = [
  34. [
  35. 'icon' => 'layui-icon-user',
  36. 'name' => '会员管理',
  37. 'href' => url('/user/list'),
  38. 'children' => [
  39. // [
  40. // 'icon' => '',
  41. // 'name' => '会员列表',
  42. // 'href' => url('user/list'),
  43. // ],
  44. ],
  45. ],
  46. [
  47. 'icon' => 'layui-icon-user',
  48. 'name' => '充值管理',
  49. 'href' => url('/topup/list'),
  50. 'children' => [],
  51. ],
  52. [
  53. 'icon' => 'layui-icon-user',
  54. 'name' => '房间管理',
  55. 'href' => url('user/list'),
  56. 'children' => [],
  57. ],
  58. [
  59. 'icon' => 'layui-icon-user',
  60. 'name' => '提现管理',
  61. 'href' => url('user/list'),
  62. 'children' => [],
  63. ],
  64. [
  65. 'icon' => 'layui-icon-user',
  66. 'name' => '钱包记录',
  67. 'href' => url('user/list'),
  68. 'children' => [],
  69. ],
  70. [
  71. 'icon' => 'layui-icon-user',
  72. 'name' => '设置',
  73. 'href' => url('user/list'),
  74. 'children' => [
  75. [
  76. 'icon' => '',
  77. 'name' => '修改密码',
  78. 'href' => url('user/list'),
  79. ],
  80. ],
  81. ],
  82. ];
  83. return view('home', ['menu' => $menu]);
  84. }
  85. public function setMyCommands()
  86. {
  87. try {
  88. $telegram = new Api(config('services.telegram.token'));
  89. $commands = [
  90. new BotCommand(['command' => 'start', 'description' => lang('🤖开始使用')]),
  91. // new BotCommand(['command' => 'room', 'description' => '🏠创建房间']),
  92. // new BotCommand(['command' => 'online', 'description' => '🟢在线房间']),
  93. // new BotCommand(['command' => 'topup', 'description' => '🔋账户管理']),
  94. // new BotCommand(['command' => 'withdraw', 'description' => '🏦提现管理']),
  95. // new BotCommand(['command' => 'tutorial', 'description' => '💡教程帮助']),
  96. // new BotCommand(['command' => 'record', 'description' => '🏆我的战绩']),
  97. ];
  98. $telegram->setMyCommands(['commands' => $commands]);
  99. } catch (TelegramSDKException $e) {
  100. }
  101. return $this->success();
  102. }
  103. public function setMenuButton()
  104. {
  105. // try {
  106. // $telegram = new Api(config('services.telegram.token'));
  107. // $res = $telegram->setMenuButton(['text' => '菜单', 'web_app' => ['url' => url('/api/onMessage')]]);
  108. // } catch (TelegramSDKException $e) {
  109. // return $this->error($e->getCode(), $e->getMessage());
  110. // }
  111. $chatId = 6325700519; // 替换为实际的 chat_id
  112. $res = $this->setReplyKeyboard($chatId); // 替换为实际的 chat_id
  113. return $this->success($res);
  114. }
  115. public function setReplyKeyboard($chatId)
  116. {
  117. $telegram = new Api(config('services.telegram.token'));
  118. $keyboard = [
  119. ['近期注单', '今日流水', '联系客服'], // 第一排按钮
  120. ['开奖历史', '当期下注', '查看余额'], // 第二排按钮
  121. ['投注大群']
  122. ];
  123. $replyMarkup = [
  124. 'keyboard' => $keyboard,
  125. 'resize_keyboard' => true, // 自适应大小
  126. 'one_time_keyboard' => false, // 保持显示,不会点击后收起
  127. ];
  128. $telegram->sendMessage([
  129. 'chat_id' => $chatId,
  130. 'text' => '你好,请选择功能菜单',
  131. 'reply_markup' => json_encode($replyMarkup),
  132. ]);
  133. }
  134. public function setWebHook()
  135. {
  136. $this->setMyCommands();
  137. try {
  138. $telegram = new Api(config('services.telegram.token'));
  139. // 设置 Webhook
  140. $webhookUrl = url('/api/onMessage'); // Webhook URL,指向刚才定义的路由
  141. $res = $telegram->setWebhook([
  142. 'url' => $webhookUrl,
  143. 'allowed_updates' => ['message', 'edited_message', 'channel_post', 'edited_channel_post', 'callback_query'],
  144. ]);
  145. } catch (TelegramSDKException $e) {
  146. return $this->error($e->getCode(), $e->getMessage());
  147. }
  148. return $this->success($res);
  149. }
  150. }