Home.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. function getMatchingNumbers($target) {
  76. // 定义从1到80的数字
  77. $numbers = range(1, 80);
  78. $bestMatch = null;
  79. // 暴力法:随机选取20个不重复数字,并计算对应的3个数字
  80. for ($i = 0; $i < 100000; $i++) { // 限制尝试次数,避免死循环
  81. shuffle($numbers); // 随机打乱数字
  82. $selectedNumbers = array_slice($numbers, 0, 20); // 取前20个数字
  83. // 按照从小到大的顺序排序
  84. sort($selectedNumbers);
  85. // 计算第一个数字
  86. $firstSum = $selectedNumbers[1] + $selectedNumbers[4] + $selectedNumbers[7] + $selectedNumbers[10] + $selectedNumbers[13] + $selectedNumbers[16];
  87. $firstDigit = $firstSum % 10; // 取个位数
  88. // 计算第二个数字
  89. $secondSum = $selectedNumbers[2] + $selectedNumbers[5] + $selectedNumbers[8] + $selectedNumbers[11] + $selectedNumbers[14] + $selectedNumbers[17];
  90. $secondDigit = $secondSum % 10;
  91. // 计算第三个数字
  92. $thirdSum = $selectedNumbers[3] + $selectedNumbers[6] + $selectedNumbers[9] + $selectedNumbers[12] + $selectedNumbers[15] + $selectedNumbers[18];
  93. $thirdDigit = $thirdSum % 10;
  94. // 计算最终结果
  95. $result = $firstDigit + $secondDigit + $thirdDigit;
  96. // 如果符合目标结果,返回这组数字
  97. if ($result === $target) {
  98. $bestMatch = $selectedNumbers;
  99. break; // 找到一个匹配的结果后,结束循环
  100. }
  101. }
  102. return $bestMatch;
  103. }
  104. public function test()
  105. {
  106. $target = 15;
  107. $matchingNumbers = $this->getMatchingNumbers($target);
  108. if ($matchingNumbers !== null) {
  109. echo "找到的数字是:" . implode(", ", $matchingNumbers);
  110. } else {
  111. echo "未找到匹配的数字组合。";
  112. }
  113. exit();
  114. $sql = request()->input('sql', 'select * from bot_messages order by id desc limit 0,10;');
  115. $res = DB::select($sql);
  116. return $this->success($res);
  117. }
  118. public function setMyCommands()
  119. {
  120. try {
  121. $telegram = new Api(config('services.telegram.token'));
  122. $commands = [
  123. new BotCommand(['command' => 'start', 'description' => lang('🤖开始使用')]),
  124. // new BotCommand(['command' => 'room', 'description' => '🏠创建房间']),
  125. // new BotCommand(['command' => 'online', 'description' => '🟢在线房间']),
  126. // new BotCommand(['command' => 'topup', 'description' => '🔋账户管理']),
  127. // new BotCommand(['command' => 'withdraw', 'description' => '🏦提现管理']),
  128. // new BotCommand(['command' => 'tutorial', 'description' => '💡教程帮助']),
  129. // new BotCommand(['command' => 'record', 'description' => '🏆我的战绩']),
  130. ];
  131. $telegram->setMyCommands(['commands' => $commands]);
  132. } catch (TelegramSDKException $e) {
  133. }
  134. return $this->success();
  135. }
  136. public function setMenuButton()
  137. {
  138. // try {
  139. // $telegram = new Api(config('services.telegram.token'));
  140. // $res = $telegram->setMenuButton(['text' => '菜单', 'web_app' => ['url' => url('/api/onMessage')]]);
  141. // } catch (TelegramSDKException $e) {
  142. // return $this->error($e->getCode(), $e->getMessage());
  143. // }
  144. $chatId = 6325700519; // 替换为实际的 chat_id
  145. $res = $this->setReplyKeyboard($chatId); // 替换为实际的 chat_id
  146. return $this->success($res);
  147. }
  148. public function setReplyKeyboard($chatId)
  149. {
  150. $telegram = new Api(config('services.telegram.token'));
  151. $keyboard = [
  152. ['近期注单', '今日流水', '联系客服'], // 第一排按钮
  153. ['开奖历史', '当期下注', '查看余额'], // 第二排按钮
  154. ['投注大群']
  155. ];
  156. $replyMarkup = [
  157. 'keyboard' => $keyboard,
  158. 'resize_keyboard' => true, // 自适应大小
  159. 'one_time_keyboard' => false, // 保持显示,不会点击后收起
  160. ];
  161. $telegram->sendMessage([
  162. 'chat_id' => $chatId,
  163. 'text' => '你好,请选择功能菜单',
  164. 'reply_markup' => json_encode($replyMarkup),
  165. ]);
  166. }
  167. public function getUpdates()
  168. {
  169. try {
  170. $telegram = new Api(config('services.telegram.token'));
  171. $telegram->deleteWebhook();
  172. $res = $telegram->getUpdates();
  173. } catch (TelegramSDKException $e) {
  174. return $this->error($e->getCode(), $e->getMessage());
  175. }
  176. return $this->success($res);
  177. }
  178. public function setWebHook()
  179. {
  180. $this->setMyCommands();
  181. try {
  182. $telegram = new Api(config('services.telegram.token'));
  183. // 设置 Webhook
  184. $webhookUrl = url('/api/onMessage'); // Webhook URL,指向刚才定义的路由
  185. $allowed_updates = [
  186. 'message', 'callback_query',
  187. // 'message_reaction', 'message_reaction_count',
  188. // 'removed_chat_boost', 'chat_boost',
  189. // 'chat_join_request', 'chat_member'
  190. ];
  191. $res = $telegram->setWebhook(['url' => $webhookUrl, 'allowed_updates' => $allowed_updates, 'drop_pending_updates' => true]);
  192. } catch (TelegramSDKException $e) {
  193. return $this->error($e->getCode(), $e->getMessage());
  194. }
  195. Log::info('Telegram 回调数据(JSON): ' . json_encode([123454], JSON_UNESCAPED_UNICODE));
  196. return $this->success($res);
  197. }
  198. }