Home.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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 test()
  87. {
  88. // $sql = request()->input('sql', 'select * from bot_messages order by id desc limit 0,10;');
  89. // $res = DB::select($sql);
  90. // return $this->success($res);
  91. }
  92. public function setMyCommands()
  93. {
  94. try {
  95. $telegram = new Api(config('services.telegram.token'));
  96. $commands = [
  97. new BotCommand(['command' => 'start', 'description' => lang('🤖开始使用')]),
  98. // new BotCommand(['command' => 'room', 'description' => '🏠创建房间']),
  99. // new BotCommand(['command' => 'online', 'description' => '🟢在线房间']),
  100. // new BotCommand(['command' => 'topup', 'description' => '🔋账户管理']),
  101. // new BotCommand(['command' => 'withdraw', 'description' => '🏦提现管理']),
  102. // new BotCommand(['command' => 'tutorial', 'description' => '💡教程帮助']),
  103. // new BotCommand(['command' => 'record', 'description' => '🏆我的战绩']),
  104. ];
  105. $telegram->setMyCommands(['commands' => $commands]);
  106. } catch (TelegramSDKException $e) {
  107. }
  108. return $this->success();
  109. }
  110. public function setMenuButton()
  111. {
  112. // try {
  113. // $telegram = new Api(config('services.telegram.token'));
  114. // $res = $telegram->setMenuButton(['text' => '菜单', 'web_app' => ['url' => url('/api/onMessage')]]);
  115. // } catch (TelegramSDKException $e) {
  116. // return $this->error($e->getCode(), $e->getMessage());
  117. // }
  118. $chatId = 6325700519; // 替换为实际的 chat_id
  119. $res = $this->setReplyKeyboard($chatId); // 替换为实际的 chat_id
  120. return $this->success($res);
  121. }
  122. public function setReplyKeyboard($chatId)
  123. {
  124. $telegram = new Api(config('services.telegram.token'));
  125. $keyboard = [
  126. ['近期注单', '今日流水', '联系客服'], // 第一排按钮
  127. ['开奖历史', '当期下注', '查看余额'], // 第二排按钮
  128. ['投注大群']
  129. ];
  130. $replyMarkup = [
  131. 'keyboard' => $keyboard,
  132. 'resize_keyboard' => true, // 自适应大小
  133. 'one_time_keyboard' => false, // 保持显示,不会点击后收起
  134. ];
  135. $telegram->sendMessage([
  136. 'chat_id' => $chatId,
  137. 'text' => '你好,请选择功能菜单',
  138. 'reply_markup' => json_encode($replyMarkup),
  139. ]);
  140. }
  141. public function getUpdates()
  142. {
  143. try {
  144. $telegram = new Api(config('services.telegram.token'));
  145. $telegram->deleteWebhook();
  146. $res = $telegram->getUpdates();
  147. } catch (TelegramSDKException $e) {
  148. return $this->error($e->getCode(), $e->getMessage());
  149. }
  150. return $this->success($res);
  151. }
  152. public function setWebHook()
  153. {
  154. $this->setMyCommands();
  155. try {
  156. $telegram = new Api(config('services.telegram.token'));
  157. // 设置 Webhook
  158. $webhookUrl = url('/api/onMessage'); // Webhook URL,指向刚才定义的路由
  159. $allowed_updates = [
  160. 'message', 'callback_query',
  161. // 'message_reaction', 'message_reaction_count',
  162. // 'removed_chat_boost', 'chat_boost',
  163. // 'chat_join_request', 'chat_member'
  164. ];
  165. $res = $telegram->setWebhook(['url' => $webhookUrl, 'allowed_updates' => $allowed_updates, 'drop_pending_updates' => true]);
  166. } catch (TelegramSDKException $e) {
  167. return $this->error($e->getCode(), $e->getMessage());
  168. }
  169. Log::info('Telegram 回调数据(JSON): ' . json_encode([123454], JSON_UNESCAPED_UNICODE));
  170. return $this->success($res);
  171. }
  172. }