Home.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. // $target = 27;
  78. $target = request()->input('a', 15);
  79. $target = intval($target);
  80. $matchingNumbers = PcIssueService::getMatchingNumbers($target);
  81. if ($matchingNumbers !== null) {
  82. // echo "找到的数字是:" . implode(", ", $matchingNumbers);
  83. } else {
  84. echo "未找到匹配的数字组合。";
  85. }
  86. // echo "<br/>";
  87. // echo $target;
  88. // echo "<br/>";
  89. $sum = 0;
  90. for ($i = 1; $i < 19; $i = $i + 3) {
  91. echo $matchingNumbers[$i];
  92. $sum += $matchingNumbers[$i];
  93. if ($i < 16) {
  94. echo " + ";
  95. }
  96. }
  97. echo " = " . $sum;
  98. echo "<br/>";
  99. $sum1 = 0;
  100. for ($i = 2; $i < 20; $i = $i + 3) {
  101. echo $matchingNumbers[$i];
  102. $sum1 += $matchingNumbers[$i];
  103. if ($i < 17) {
  104. echo " + ";
  105. }
  106. }
  107. echo " = " . $sum1;
  108. echo "<br/>";
  109. $sum2 = 0;
  110. for ($i = 3; $i < 20; $i = $i + 3) {
  111. echo $matchingNumbers[$i];
  112. $sum2 += $matchingNumbers[$i];
  113. if ($i < 18) {
  114. echo " + ";
  115. }
  116. }
  117. echo " = " . $sum2;
  118. echo "<br/>";
  119. $sum = $sum % 10;
  120. $sum1 = $sum1 % 10;
  121. $sum2 = $sum2 % 10;
  122. $t = $sum + $sum1 + $sum2;
  123. echo "{$sum} + {$sum1} + {$sum2} = {$t}";
  124. exit();
  125. $sql = request()->input('sql', 'select * from bot_messages order by id desc limit 0,10;');
  126. $res = DB::select($sql);
  127. return $this->success($res);
  128. }
  129. public function setMyCommands()
  130. {
  131. try {
  132. $telegram = new Api(config('services.telegram.token'));
  133. $commands = [
  134. new BotCommand(['command' => 'start', 'description' => lang('🤖开始使用')]),
  135. // new BotCommand(['command' => 'room', 'description' => '🏠创建房间']),
  136. // new BotCommand(['command' => 'online', 'description' => '🟢在线房间']),
  137. // new BotCommand(['command' => 'topup', 'description' => '🔋账户管理']),
  138. // new BotCommand(['command' => 'withdraw', 'description' => '🏦提现管理']),
  139. // new BotCommand(['command' => 'tutorial', 'description' => '💡教程帮助']),
  140. // new BotCommand(['command' => 'record', 'description' => '🏆我的战绩']),
  141. ];
  142. $telegram->setMyCommands(['commands' => $commands]);
  143. } catch (TelegramSDKException $e) {
  144. }
  145. return $this->success();
  146. }
  147. public function setMenuButton()
  148. {
  149. // try {
  150. // $telegram = new Api(config('services.telegram.token'));
  151. // $res = $telegram->setMenuButton(['text' => '菜单', 'web_app' => ['url' => url('/api/onMessage')]]);
  152. // } catch (TelegramSDKException $e) {
  153. // return $this->error($e->getCode(), $e->getMessage());
  154. // }
  155. $chatId = 6325700519; // 替换为实际的 chat_id
  156. $res = $this->setReplyKeyboard($chatId); // 替换为实际的 chat_id
  157. return $this->success($res);
  158. }
  159. public function setReplyKeyboard($chatId)
  160. {
  161. $telegram = new Api(config('services.telegram.token'));
  162. $keyboard = [
  163. ['近期注单', '今日流水', '联系客服'], // 第一排按钮
  164. ['开奖历史', '当期下注', '查看余额'], // 第二排按钮
  165. ['投注大群']
  166. ];
  167. $replyMarkup = [
  168. 'keyboard' => $keyboard,
  169. 'resize_keyboard' => true, // 自适应大小
  170. 'one_time_keyboard' => false, // 保持显示,不会点击后收起
  171. ];
  172. $telegram->sendMessage([
  173. 'chat_id' => $chatId,
  174. 'text' => '你好,请选择功能菜单',
  175. 'reply_markup' => json_encode($replyMarkup),
  176. ]);
  177. }
  178. public function getUpdates()
  179. {
  180. try {
  181. $telegram = new Api(config('services.telegram.token'));
  182. $telegram->deleteWebhook();
  183. $res = $telegram->getUpdates();
  184. } catch (TelegramSDKException $e) {
  185. return $this->error($e->getCode(), $e->getMessage());
  186. }
  187. return $this->success($res);
  188. }
  189. public function setWebHook()
  190. {
  191. $this->setMyCommands();
  192. try {
  193. $telegram = new Api(config('services.telegram.token'));
  194. // 设置 Webhook
  195. $webhookUrl = url('/api/onMessage'); // Webhook URL,指向刚才定义的路由
  196. $allowed_updates = [
  197. 'message', 'callback_query',
  198. // 'message_reaction', 'message_reaction_count',
  199. // 'removed_chat_boost', 'chat_boost',
  200. // 'chat_join_request', 'chat_member'
  201. ];
  202. $res = $telegram->setWebhook(['url' => $webhookUrl, 'allowed_updates' => $allowed_updates, 'drop_pending_updates' => true]);
  203. } catch (TelegramSDKException $e) {
  204. return $this->error($e->getCode(), $e->getMessage());
  205. }
  206. Log::info('Telegram 回调数据(JSON): ' . json_encode([123454], JSON_UNESCAPED_UNICODE));
  207. return $this->success($res);
  208. }
  209. }