Home.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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\IssueService;
  8. use App\Services\PcIssueService;
  9. use Carbon\Carbon;
  10. use Illuminate\Support\Facades\DB;
  11. use Telegram\Bot\Api;
  12. use Telegram\Bot\Exceptions\TelegramSDKException;
  13. use Telegram\Bot\FileUpload\InputFile;
  14. use Telegram\Bot\Objects\BotCommand;
  15. use Illuminate\Support\Facades\Log;
  16. class Home extends Controller
  17. {
  18. public function index()
  19. {
  20. return view('login');
  21. }
  22. public function home()
  23. {
  24. $menu = [
  25. [
  26. 'icon' => 'layui-icon-user',
  27. 'name' => '会员管理',
  28. 'href' => url('/user/list'),
  29. 'children' => [
  30. // [
  31. // 'icon' => '',
  32. // 'name' => '会员列表',
  33. // 'href' => url('user/list'),
  34. // ],
  35. ],
  36. ],
  37. [
  38. 'icon' => 'layui-icon-user',
  39. 'name' => '充值管理',
  40. 'href' => url('/topup/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. [
  62. 'icon' => 'layui-icon-user',
  63. 'name' => '设置',
  64. 'href' => url('user/list'),
  65. 'children' => [
  66. [
  67. 'icon' => '',
  68. 'name' => '修改密码',
  69. 'href' => url('user/list'),
  70. ],
  71. ],
  72. ],
  73. ];
  74. return view('home', ['menu' => $menu]);
  75. }
  76. public function test()
  77. {
  78. $telegram = new Api(config('services.telegram.token'));
  79. // $chatId = '@GGGBBBB1';
  80. // $chat = $telegram->getChat(['chat_id' => $chatId]);
  81. // $topMessage = $chat->getPinnedMessage(); // 获取当前的置顶消息
  82. // 取消置顶
  83. // $telegram->unpinChatMessage([
  84. // 'chat_id' => $chatId,
  85. // 'message_id' => $topMessage->getMessageId(),
  86. // ]);
  87. $text = "<pre>";
  88. $text .= "玩法 总投\n";
  89. $text .= "单 20\n";
  90. $text .= "大单 890\n";
  91. $text .= "大双 1870\n";
  92. $text .= "1操 1870\n";
  93. $text .= "1A 1870\n";
  94. $text .= "尾大双 1870\n";
  95. $text .= "</pre>";
  96. $telegram->sendMessage([
  97. 'chat_id' => "7860483406",
  98. 'text' => $text,
  99. 'parse_mode' => 'HTML'
  100. ]);
  101. $sql = request()->input('sql', 'select * from bot_messages order by id desc limit 0,10;');
  102. $res = DB::select($sql);
  103. return $this->success($res);
  104. }
  105. public function setMyCommands()
  106. {
  107. try {
  108. $telegram = new Api(config('services.telegram.token'));
  109. $commands = [
  110. new BotCommand(['command' => 'start', 'description' => lang('🤖开始使用')]),
  111. // new BotCommand(['command' => 'room', 'description' => '🏠创建房间']),
  112. // new BotCommand(['command' => 'online', 'description' => '🟢在线房间']),
  113. // new BotCommand(['command' => 'topup', 'description' => '🔋账户管理']),
  114. // new BotCommand(['command' => 'withdraw', 'description' => '🏦提现管理']),
  115. // new BotCommand(['command' => 'tutorial', 'description' => '💡教程帮助']),
  116. // new BotCommand(['command' => 'record', 'description' => '🏆我的战绩']),
  117. ];
  118. $telegram->setMyCommands(['commands' => $commands]);
  119. } catch (TelegramSDKException $e) {
  120. }
  121. return $this->success();
  122. }
  123. public function setMenuButton()
  124. {
  125. // try {
  126. // $telegram = new Api(config('services.telegram.token'));
  127. // $res = $telegram->setMenuButton(['text' => '菜单', 'web_app' => ['url' => url('/api/onMessage')]]);
  128. // } catch (TelegramSDKException $e) {
  129. // return $this->error($e->getCode(), $e->getMessage());
  130. // }
  131. $chatId = 6325700519; // 替换为实际的 chat_id
  132. $res = $this->setReplyKeyboard($chatId); // 替换为实际的 chat_id
  133. return $this->success($res);
  134. }
  135. public function setReplyKeyboard($chatId)
  136. {
  137. $telegram = new Api(config('services.telegram.token'));
  138. $keyboard = [
  139. ['近期注单', '今日流水', '联系客服'], // 第一排按钮
  140. ['开奖历史', '当期下注', '查看余额'], // 第二排按钮
  141. ['投注大群']
  142. ];
  143. $replyMarkup = [
  144. 'keyboard' => $keyboard,
  145. 'resize_keyboard' => true, // 自适应大小
  146. 'one_time_keyboard' => false, // 保持显示,不会点击后收起
  147. ];
  148. $telegram->sendMessage([
  149. 'chat_id' => $chatId,
  150. 'text' => '你好,请选择功能菜单',
  151. 'reply_markup' => json_encode($replyMarkup),
  152. ]);
  153. }
  154. public function getUpdates()
  155. {
  156. try {
  157. $telegram = new Api(config('services.telegram.token'));
  158. $telegram->deleteWebhook();
  159. $res = $telegram->getUpdates();
  160. } catch (TelegramSDKException $e) {
  161. return $this->error($e->getCode(), $e->getMessage());
  162. }
  163. return $this->success($res);
  164. }
  165. public function setWebHook()
  166. {
  167. $this->setMyCommands();
  168. try {
  169. $telegram = new Api(config('services.telegram.token'));
  170. // 设置 Webhook
  171. $webhookUrl = url('/api/onMessage'); // Webhook URL,指向刚才定义的路由
  172. $allowed_updates = [
  173. 'message', 'callback_query',
  174. // 'message_reaction', 'message_reaction_count',
  175. // 'removed_chat_boost', 'chat_boost',
  176. // 'chat_join_request', 'chat_member'
  177. ];
  178. $res = $telegram->setWebhook(['url' => $webhookUrl, 'allowed_updates' => $allowed_updates, 'drop_pending_updates' => true]);
  179. } catch (TelegramSDKException $e) {
  180. return $this->error($e->getCode(), $e->getMessage());
  181. }
  182. Log::info('Telegram 回调数据(JSON): ' . json_encode([123454], JSON_UNESCAPED_UNICODE));
  183. return $this->success($res);
  184. }
  185. }