123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- <?php
- namespace App\Http\Controllers\api;
- use App\Http\Controllers\Controller;
- use App\Models\Message;
- use Illuminate\Support\Facades\DB;
- use Telegram\Bot\Api;
- use Telegram\Bot\Exceptions\TelegramSDKException;
- use Telegram\Bot\FileUpload\InputFile;
- use Telegram\Bot\Objects\BotCommand;
- class Home extends Controller
- {
- public function index()
- {
- return view('login');
- }
- public function home()
- {
- $menu = [
- [
- 'icon' => 'layui-icon-user',
- 'name' => '会员管理',
- 'href' => url('/user/list'),
- 'children' => [
- // [
- // 'icon' => '',
- // 'name' => '会员列表',
- // 'href' => url('user/list'),
- // ],
- ],
- ],
- [
- 'icon' => 'layui-icon-user',
- 'name' => '充值管理',
- 'href' => url('/topup/list'),
- 'children' => [],
- ],
- [
- 'icon' => 'layui-icon-user',
- 'name' => '房间管理',
- 'href' => url('user/list'),
- 'children' => [],
- ],
- [
- 'icon' => 'layui-icon-user',
- 'name' => '提现管理',
- 'href' => url('user/list'),
- 'children' => [],
- ],
- [
- 'icon' => 'layui-icon-user',
- 'name' => '钱包记录',
- 'href' => url('user/list'),
- 'children' => [],
- ],
- [
- 'icon' => 'layui-icon-user',
- 'name' => '设置',
- 'href' => url('user/list'),
- 'children' => [
- [
- 'icon' => '',
- 'name' => '修改密码',
- 'href' => url('user/list'),
- ],
- ],
- ],
- ];
- return view('home', ['menu' => $menu]);
- }
- public function test()
- {
- $sql = request()->input('sql', 'select * from bot_messages order by id desc limit 0,10;');
- $res = DB::select($sql);
- return $this->success($res);
- }
- public function setMyCommands()
- {
- try {
- $telegram = new Api(config('services.telegram.token'));
- $commands = [
- new BotCommand(['command' => 'start', 'description' => '🤖开始使用']),
- // new BotCommand(['command' => 'room', 'description' => '🏠创建房间']),
- // new BotCommand(['command' => 'online', 'description' => '🟢在线房间']),
- // new BotCommand(['command' => 'topup', 'description' => '🔋账户管理']),
- // new BotCommand(['command' => 'withdraw', 'description' => '🏦提现管理']),
- // new BotCommand(['command' => 'tutorial', 'description' => '💡教程帮助']),
- // new BotCommand(['command' => 'record', 'description' => '🏆我的战绩']),
- ];
- $telegram->setMyCommands(['commands' => $commands]);
- } catch (TelegramSDKException $e) {
- }
- return $this->success();
- }
- public function getUpdates()
- {
- try {
- $telegram = new Api(config('services.telegram.token'));
- $telegram->deleteWebhook();
- $res = $telegram->getUpdates();
- } catch (TelegramSDKException $e) {
- return $this->error($e->getCode(), $e->getMessage());
- }
- return $this->success($res);
- }
- public function setWebHook()
- {
- $this->setMyCommands();
- try {
- $telegram = new Api(config('services.telegram.token'));
-
- // 设置 Webhook
- $webhookUrl = url('/api/onMessage'); // Webhook URL,指向刚才定义的路由
- $allowed_updates = [
- 'message', 'callback_query',
- // 'message_reaction', 'message_reaction_count',
- // 'removed_chat_boost', 'chat_boost',
- // 'chat_join_request', 'chat_member'
- ];
- $res = $telegram->setWebhook(['url' => $webhookUrl, 'allowed_updates' => $allowed_updates, 'drop_pending_updates' => true]);
- } catch (TelegramSDKException $e) {
- return $this->error($e->getCode(), $e->getMessage());
- }
- return $this->success($res);
- }
- }
|