Home.php 6.0 KB

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