Home.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. namespace App\Http\Controllers\api;
  3. use App\Http\Controllers\Controller;
  4. use App\Models\Message;
  5. use Illuminate\Support\Facades\DB;
  6. use Telegram\Bot\Api;
  7. use Telegram\Bot\Exceptions\TelegramSDKException;
  8. use Telegram\Bot\FileUpload\InputFile;
  9. use Telegram\Bot\Objects\BotCommand;
  10. class Home extends Controller
  11. {
  12. public function index()
  13. {
  14. return view('login');
  15. }
  16. public function home()
  17. {
  18. $menu = [
  19. [
  20. 'icon' => 'layui-icon-user',
  21. 'name' => '会员管理',
  22. 'href' => url('/user/list'),
  23. 'children' => [
  24. // [
  25. // 'icon' => '',
  26. // 'name' => '会员列表',
  27. // 'href' => url('user/list'),
  28. // ],
  29. ],
  30. ],
  31. [
  32. 'icon' => 'layui-icon-user',
  33. 'name' => '充值管理',
  34. 'href' => url('/topup/list'),
  35. 'children' => [],
  36. ],
  37. [
  38. 'icon' => 'layui-icon-user',
  39. 'name' => '房间管理',
  40. 'href' => url('user/list'),
  41. 'children' => [],
  42. ],
  43. [
  44. 'icon' => 'layui-icon-user',
  45. 'name' => '提现管理',
  46. 'href' => url('user/list'),
  47. 'children' => [],
  48. ],
  49. [
  50. 'icon' => 'layui-icon-user',
  51. 'name' => '钱包记录',
  52. 'href' => url('user/list'),
  53. 'children' => [],
  54. ],
  55. [
  56. 'icon' => 'layui-icon-user',
  57. 'name' => '设置',
  58. 'href' => url('user/list'),
  59. 'children' => [
  60. [
  61. 'icon' => '',
  62. 'name' => '修改密码',
  63. 'href' => url('user/list'),
  64. ],
  65. ],
  66. ],
  67. ];
  68. return view('home', ['menu' => $menu]);
  69. }
  70. public function test()
  71. {
  72. $sql = request()->input('sql', 'select * from bot_messages order by id desc limit 0,10;');
  73. $res = DB::select($sql);
  74. return $this->success($res);
  75. }
  76. public function setMyCommands()
  77. {
  78. try {
  79. $telegram = new Api(config('services.telegram.token'));
  80. $commands = [
  81. new BotCommand(['command' => 'room', 'description' => '🏠创建房间']),
  82. new BotCommand(['command' => 'online', 'description' => '🟢在线房间']),
  83. new BotCommand(['command' => 'topup', 'description' => '🔋账户管理']),
  84. new BotCommand(['command' => 'withdraw', 'description' => '🏦提现管理']),
  85. new BotCommand(['command' => 'tutorial', 'description' => '💡教程帮助']),
  86. new BotCommand(['command' => 'record', 'description' => '🏆我的战绩']),
  87. ];
  88. $telegram->setMyCommands(['commands' => $commands]);
  89. } catch (TelegramSDKException $e) {
  90. }
  91. return $this->success();
  92. }
  93. public function getUpdates()
  94. {
  95. try {
  96. $telegram = new Api(config('services.telegram.token'));
  97. $telegram->deleteWebhook();
  98. $res = $telegram->getUpdates();
  99. } catch (TelegramSDKException $e) {
  100. return $this->error($e->getCode(), $e->getMessage());
  101. }
  102. return $this->success($res);
  103. }
  104. public function setWebHook()
  105. {
  106. $this->setMyCommands();
  107. try {
  108. $telegram = new Api(config('services.telegram.token'));
  109. // 设置 Webhook
  110. $webhookUrl = url('/api/onMessage'); // Webhook URL,指向刚才定义的路由
  111. $allowed_updates = [
  112. 'message', 'callback_query',
  113. // 'message_reaction', 'message_reaction_count',
  114. // 'removed_chat_boost', 'chat_boost',
  115. // 'chat_join_request', 'chat_member'
  116. ];
  117. $res = $telegram->setWebhook(['url' => $webhookUrl, 'allowed_updates' => $allowed_updates, 'drop_pending_updates' => true]);
  118. var_dump($res);
  119. } catch (TelegramSDKException $e) {
  120. return $this->error($e->getCode(), $e->getMessage());
  121. }
  122. return $this->success($res);
  123. }
  124. }