├── README.md └── app ├── Http └── Controllers │ ├── Guest │ └── TelegramController.php │ └── User │ └── UserController.php ├── Plugins └── Telegram │ └── Commands │ ├── Bind.php │ ├── Invite.php │ ├── Kefu.php │ ├── MySubscribe.php │ ├── MyWallet.php │ ├── Start.php │ ├── Store.php │ ├── SubLink.php │ └── Traffic.php └── Services └── TelegramService.php /README.md: -------------------------------------------------------------------------------- 1 | # **v2board-bot 吱吱修改版 更新到1.5.5** 2 | 3 | ### v2board更改为按钮模式 4 | - 使用方法: 5 | - 替换上述文件即可 6 | - 如有bug,请联系吱吱反馈 7 | - `需修改 Kefu.php 中客服的链接` 8 | ### 交流群 9 | * [吱吱和她的朋友们](https://t.me/zhifriends) 10 | -------------------------------------------------------------------------------- /app/Http/Controllers/Guest/TelegramController.php: -------------------------------------------------------------------------------- 1 | input('access_token') !== md5(config('v2board.telegram_bot_token'))) { 17 | abort(401); 18 | } 19 | } 20 | 21 | public function webhook(Request $request) 22 | { 23 | $this->msg = $this->getMessage($request->input()); 24 | if (!$this->msg) return; 25 | $this->handle(); 26 | } 27 | 28 | public function handle() 29 | { 30 | $msg = $this->msg; 31 | try { 32 | foreach (glob(base_path('app//Plugins//Telegram//Commands') . '/*.php') as $file) { 33 | $command = basename($file, '.php'); 34 | $class = '\\App\\Plugins\\Telegram\\Commands\\' . $command; 35 | if (!class_exists($class)) continue; 36 | $instance = new $class(); 37 | if ($msg->message_type === 'message') { 38 | if (!isset($instance->command)) continue; 39 | if ($msg->command !== $instance->command) continue; 40 | $instance->handle($msg); 41 | return; 42 | } 43 | if ($msg->message_type === 'reply_message') { 44 | if (!isset($instance->regex)) continue; 45 | if (!preg_match($instance->regex, $msg->reply_text, $match)) continue; 46 | $instance->handle($msg, $match); 47 | return; 48 | } 49 | } 50 | } catch (\Exception $e) { 51 | $telegramService = new TelegramService(); 52 | $telegramService->sendMessage($msg->chat_id, $e->getMessage()); 53 | } 54 | } 55 | 56 | private function getMessage(array $data) 57 | { 58 | if (!isset($data['message']['text']) and !isset($data['callback_query']) )return false; 59 | $obj = new \StdClass(); 60 | if(isset($data['callback_query'])){ 61 | $obj->command =$data['callback_query']['data']; 62 | $obj->callback_query_id =$data['callback_query']['id']; 63 | $obj->chat_id = $data['callback_query']['message']['chat']['id']; 64 | $obj->user_id = $data['callback_query']['from']['id']; 65 | $obj->message_id = $data['callback_query']['message']['message_id']; 66 | $obj->text = $data['callback_query']['message']['text']; 67 | $obj->message_type = 'message'; 68 | $obj->is_private = $data['callback_query']['message']['chat']['type'] === 'private' ? true : false; 69 | }else{ 70 | $text = explode(' ', $data['message']['text']); 71 | $obj->command = $text[0]; 72 | $obj->args = array_slice($text, 1); 73 | $obj->chat_id = $data['message']['chat']['id']; 74 | $obj->message_id = $data['message']['message_id']; 75 | $obj->message_type = !isset($data['message']['reply_to_message']['text']) ? 'message' : 'reply_message'; 76 | $obj->text = $data['message']['text']; 77 | $obj->is_private = $data['message']['chat']['type'] === 'private'; 78 | $obj->user_id = $data['message']['from']['id']; 79 | $obj->text = $data['message']['text']; 80 | if ($obj->message_type === 'reply_message') { 81 | $obj->reply_text = $data['message']['reply_to_message']['text']; 82 | } 83 | } 84 | return $obj; 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /app/Http/Controllers/User/UserController.php: -------------------------------------------------------------------------------- 1 | session()->flush(); 23 | return response([ 24 | 'data' => true 25 | ]); 26 | } 27 | 28 | public function changePassword(UserChangePassword $request) 29 | { 30 | $user = User::find($request->session()->get('id')); 31 | if (!$user) { 32 | abort(500, __('The user does not exist')); 33 | } 34 | if (!Helper::multiPasswordVerify( 35 | $user->password_algo, 36 | $user->password_salt, 37 | $request->input('old_password'), 38 | $user->password) 39 | ) { 40 | abort(500, __('The old password is wrong')); 41 | } 42 | $user->password = password_hash($request->input('new_password'), PASSWORD_DEFAULT); 43 | $user->password_algo = NULL; 44 | $user->password_salt = NULL; 45 | if (!$user->save()) { 46 | abort(500, __('Save failed')); 47 | } 48 | $request->session()->flush(); 49 | return response([ 50 | 'data' => true 51 | ]); 52 | } 53 | 54 | public function info(Request $request) 55 | { 56 | $user = User::where('id', $request->session()->get('id')) 57 | ->select([ 58 | 'email', 59 | 'transfer_enable', 60 | 'last_login_at', 61 | 'created_at', 62 | 'banned', 63 | 'remind_expire', 64 | 'remind_traffic', 65 | 'expired_at', 66 | 'balance', 67 | 'commission_balance', 68 | 'plan_id', 69 | 'discount', 70 | 'commission_rate', 71 | 'telegram_id', 72 | 'uuid' 73 | ]) 74 | ->first(); 75 | if (!$user) { 76 | abort(500, __('The user does not exist')); 77 | } 78 | $user['avatar_url'] = 'https://cdn.v2ex.com/gravatar/' . md5($user->email) . '?s=64&d=identicon'; 79 | return response([ 80 | 'data' => $user 81 | ]); 82 | } 83 | 84 | public function getStat(Request $request) 85 | { 86 | $stat = [ 87 | Order::where('status', 0) 88 | ->where('user_id', $request->session()->get('id')) 89 | ->count(), 90 | Ticket::where('status', 0) 91 | ->where('user_id', $request->session()->get('id')) 92 | ->count(), 93 | User::where('invite_user_id', $request->session()->get('id')) 94 | ->count() 95 | ]; 96 | return response([ 97 | 'data' => $stat 98 | ]); 99 | } 100 | 101 | public function getSubscribe(Request $request) 102 | { 103 | $user = User::where('id', $request->session()->get('id')) 104 | ->select([ 105 | 'plan_id', 106 | 'token', 107 | 'expired_at', 108 | 'u', 109 | 'd', 110 | 'transfer_enable', 111 | 'email' 112 | ]) 113 | ->first(); 114 | if (!$user) { 115 | abort(500, __('The user does not exist')); 116 | } 117 | if ($user->plan_id) { 118 | $user['plan'] = Plan::find($user->plan_id); 119 | if (!$user['plan']) { 120 | abort(500, __('Subscription plan does not exist')); 121 | } 122 | } 123 | $user['subscribe_url'] = Helper::getSubscribeHost() . "/api/v1/client/subscribe?token={$user['token']}"; 124 | $user['reset_day'] = $this->getResetDay($user); 125 | return response([ 126 | 'data' => $user 127 | ]); 128 | } 129 | 130 | public function resetSecurity(Request $request) 131 | { 132 | $user = User::find($request->session()->get('id')); 133 | if (!$user) { 134 | abort(500, __('The user does not exist')); 135 | } 136 | $user->uuid = Helper::guid(true); 137 | $user->token = Helper::guid(); 138 | if (!$user->save()) { 139 | abort(500, __('Reset failed')); 140 | } 141 | return response([ 142 | 'data' => config('v2board.subscribe_url', config('v2board.app_url', env('APP_URL'))) . '/api/v1/client/subscribe?token=' . $user->token 143 | ]); 144 | } 145 | 146 | public function update(UserUpdate $request) 147 | { 148 | $updateData = $request->only([ 149 | 'remind_expire', 150 | 'remind_traffic' 151 | ]); 152 | 153 | $user = User::find($request->session()->get('id')); 154 | if (!$user) { 155 | abort(500, __('The user does not exist')); 156 | } 157 | try { 158 | $user->update($updateData); 159 | } catch (\Exception $e) { 160 | abort(500, __('Save failed')); 161 | } 162 | 163 | return response([ 164 | 'data' => true 165 | ]); 166 | } 167 | 168 | public function transfer(UserTransfer $request) 169 | { 170 | $user = User::find($request->session()->get('id')); 171 | if (!$user) { 172 | abort(500, __('The user does not exist')); 173 | } 174 | if ($request->input('transfer_amount') > $user->commission_balance) { 175 | abort(500, __('Insufficient commission balance')); 176 | } 177 | $user->commission_balance = $user->commission_balance - $request->input('transfer_amount'); 178 | $user->balance = $user->balance + $request->input('transfer_amount'); 179 | if (!$user->save()) { 180 | abort(500, __('Transfer failed')); 181 | } 182 | return response([ 183 | 'data' => true 184 | ]); 185 | } 186 | 187 | public function getResetDay(User $user) 188 | { 189 | if ($user->expired_at <= time() || $user->expired_at === NULL) return null; 190 | // if reset method is not reset 191 | if (isset($user->plan->reset_traffic_method) && $user->plan->reset_traffic_method === 2) return null; 192 | $day = date('d', $user->expired_at); 193 | $today = date('d'); 194 | $lastDay = date('d', strtotime('last day of +0 months')); 195 | 196 | if ((int)config('v2board.reset_traffic_method') === 0 || 197 | (isset($user->plan->reset_traffic_method) && $user->plan->reset_traffic_method === 0)) 198 | { 199 | return $lastDay - $today; 200 | } 201 | if ((int)config('v2board.reset_traffic_method') === 1 || 202 | (isset($user->plan->reset_traffic_method) && $user->plan->reset_traffic_method === 1)) 203 | { 204 | if ((int)$day >= (int)$today && (int)$day >= (int)$lastDay) { 205 | return $lastDay - $today; 206 | } 207 | if ((int)$day >= (int)$today) { 208 | return $day - $today; 209 | } else { 210 | return $lastDay - $today + $day; 211 | } 212 | } 213 | return null; 214 | } 215 | 216 | 217 | public function getQuickLoginUrl(Request $request) 218 | { 219 | $user = User::find($request->session()->get('id')); 220 | if (!$user) { 221 | abort(500, __('The user does not exist')); 222 | } 223 | 224 | $code = Helper::guid(); 225 | $key = CacheKey::get('TEMP_TOKEN', $code); 226 | Cache::put($key, $user->id, 60); 227 | $redirect = '/#/login?verify=' . $code . '&redirect=' . ($request->input('redirect') ? $request->input('redirect') : 'dashboard'); 228 | if (config('v2board.app_url')) { 229 | $url = config('v2board.app_url') . $redirect; 230 | } else { 231 | $url = url($redirect); 232 | } 233 | return response([ 234 | 'data' => $url 235 | ]); 236 | } 237 | } 238 | -------------------------------------------------------------------------------- /app/Plugins/Telegram/Commands/Bind.php: -------------------------------------------------------------------------------- 1 | is_private) return; 14 | if (!isset($message->args[0])) { 15 | abort(500, '参数有误,请携带订阅地址发送'); 16 | } 17 | $subscribeUrl = $message->args[0]; 18 | $subscribeUrl = parse_url($subscribeUrl); 19 | parse_str($subscribeUrl['query'], $query); 20 | $token = $query['token']; 21 | if (!$token) { 22 | abort(500, '订阅地址无效'); 23 | } 24 | $user = User::where('token', $token)->first(); 25 | if (!$user) { 26 | abort(500, '用户不存在'); 27 | } 28 | if ($user->telegram_id) { 29 | abort(500, '该账号已经绑定了Telegram账号'); 30 | } 31 | $user->telegram_id = $message->chat_id; 32 | if (!$user->save()) { 33 | abort(500, '设置失败'); 34 | } 35 | $telegramService = $this->telegramService; 36 | $telegramService->sendMessage($message->chat_id, '绑定成功'); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /app/Plugins/Telegram/Commands/Invite.php: -------------------------------------------------------------------------------- 1 | telegramService; 16 | if (!$message->is_private) return; 17 | $user = User::where('telegram_id', $message->chat_id)->first(); 18 | if (!$user) { 19 | $telegramService->answerCallbackQuery($message->callback_query_id,'没有查询到您的用户信息,请先绑定账号','true'); 20 | return; 21 | } 22 | $inviteCode = InviteCode::where('user_id', $user->id) 23 | ->where('status', 0) 24 | ->first(); 25 | $commission_rate = config('v2board.invite_commission', 10); 26 | if ($user->commission_rate) { 27 | $commission_rate = $user->commission_rate; 28 | } 29 | //邀请用户数 30 | $inviteusers = User::where('invite_user_id', $message->user_id)->count(); 31 | //有效的佣金 32 | $active_commission = Order::where('status', 3) 33 | ->where('commission_status', 2) 34 | ->where('invite_user_id', $message->user_id) 35 | ->sum('commission_balance') / 100; 36 | //确认中的佣金 37 | $process_commisson = Order::where('status', 3) 38 | ->where('commission_status', 0) 39 | ->where('invite_user_id', $message->user_id) 40 | ->sum('commission_balance') / 100; 41 | //可用佣金 42 | $commission_balance = $user->commission_balance / 100 ; 43 | //邀请链接 44 | if(!isset($inviteCode->code)){ 45 | $inviteCode = new InviteCode(); 46 | $inviteCode->user_id = $user->id; 47 | $inviteCode->code = Helper::randomChar(8); 48 | $inviteCode->save(); 49 | } 50 | $invite_url = Helper::getSubscribeHost() . "/register?code={$inviteCode->code}"; 51 | $text = "我的邀请\n————————————\n我邀请的人数:$inviteusers 人\n我的返利比例:$commission_rate %\n现有效的佣金:$active_commission 元\n确认中的佣金:$process_commisson 元\n目前可用佣金:$commission_balance 元\n您的推广链接: \n————————————\n`$invite_url`"; 52 | $reply_markup = json_encode([ 53 | 'inline_keyboard' => [ 54 | [ 55 | ['text' => "返回菜单", 'callback_data' => '/start'], 56 | ] 57 | ] 58 | ]); 59 | $telegramService->editMessageText($message->chat_id,$message->message_id, $text, $reply_markup); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /app/Plugins/Telegram/Commands/Kefu.php: -------------------------------------------------------------------------------- 1 | telegramService; 18 | if (!$message->is_private) return; 19 | $user = User::where('telegram_id', $message->user_id)->first(); 20 | $userplan = Plan::find($user->plan_id); 21 | if (!$userplan) { 22 | $plan_transfer = 0; 23 | $plan_name = "暂无订阅" ; 24 | $reset_day = 0; 25 | }else{ 26 | $plan_transfer = $userplan->transfer_enable ; 27 | $plan_name = $userplan->name ; 28 | $UserController = new UserController(); 29 | $reset_day = $UserController->getResetDay($user); 30 | } 31 | $expired_at = date("Y-m-d",$user->expired_at); 32 | $admin = User::where('id', 1)->first(); 33 | $text = "用户信息:\n————————————\nTG账户:$message->user_id\n用户余额:$user->balance\n返利金额:$user->commission_balance\n套餐名称:$plan_name\n套餐流量:$plan_transfer GB\n离重置流量还有:$reset_day 天\n到期时间:$expired_at"; 34 | $telegramService->sendMessage($admin->telegram_id, $text); 35 | $text = "点击下方按钮联系客服"; 36 | $reply_markup = json_encode([ 37 | 'inline_keyboard' => [ 38 | [ 39 | ['text' => "点击联系客服", 'url' => "https://t.me/zhizhizh"] 40 | ], 41 | [ 42 | ['text' => "返回菜单", 'callback_data' => '/start'], 43 | ] 44 | ] 45 | ]); 46 | $telegramService->editMessageText($message->chat_id,$message->message_id, $text, $reply_markup); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /app/Plugins/Telegram/Commands/MySubscribe.php: -------------------------------------------------------------------------------- 1 | telegramService; 18 | if (!$message->is_private) return; 19 | $user = User::where('telegram_id', $message->user_id)->first(); 20 | if (!$user) { 21 | $telegramService->answerCallbackQuery($message->callback_query_id,'没有查询到您的用户信息,请先绑定账号','true'); 22 | return; 23 | } 24 | $userplan = Plan::find($user->plan_id); 25 | if (!$userplan) { 26 | $telegramService->answerCallbackQuery($message->callback_query_id,'您暂无订阅','true'); 27 | return; 28 | } 29 | $plan_transfer = $userplan->transfer_enable ; 30 | $plan_name = $userplan->name ; 31 | $UserController = new UserController(); 32 | $reset_day = $UserController->getResetDay($user); 33 | $expired_at = date("Y-m-d",$user->expired_at); 34 | $text = "我的订阅\n————————————\n套餐名称:$plan_name\n套餐流量:$plan_transfer GB\n离重置流量还有:$reset_day 天\n到期时间:$expired_at"; 35 | $reply_markup = json_encode([ 36 | 'inline_keyboard' => [ 37 | [ 38 | ['text' => "返回菜单", 'callback_data' => '/start'], 39 | ] 40 | ] 41 | ]); 42 | $telegramService->editMessageText($message->chat_id,$message->message_id, $text, $reply_markup); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /app/Plugins/Telegram/Commands/MyWallet.php: -------------------------------------------------------------------------------- 1 | telegramService; 14 | if (!$message->is_private) return; 15 | $user = User::where('telegram_id', $message->chat_id)->first(); 16 | if (!$user) { 17 | $telegramService->answerCallbackQuery($msg->callback_query_id,'没有查询到您的用户信息,请先绑定账号'); 18 | return; 19 | } 20 | $commission_balance = $user->commission_balance / 100 ; 21 | $balance = $user->balance / 100 ; 22 | $total = $commission_balance + $balance ; 23 | $text = "💰我的钱包\n————————————\n钱包总额:$total 元\n账户余额:$balance 元\n推广佣金:$commission_balance 元"; 24 | $reply_markup = json_encode([ 25 | 'inline_keyboard' => [ 26 | [ 27 | ['text' => "返回菜单", 'callback_data' => '/start'], 28 | ] 29 | ] 30 | ]); 31 | $telegramService->editMessageText($message->chat_id,$message->message_id,$text, $reply_markup); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /app/Plugins/Telegram/Commands/Start.php: -------------------------------------------------------------------------------- 1 | telegramService; 16 | if (!$message->is_private) return; 17 | $user = User::where('telegram_id', $message->user_id)->first(); 18 | $app_url = sprintf( 19 | config('v2board.app_url') 20 | ); 21 | if($user){ 22 | $reply_markup = json_encode([ 23 | 'inline_keyboard' => [ 24 | [ 25 | ['text' => "💰我的钱包", 'callback_data' => '/mywallet'], ['text' => "🎫流量查询", 'callback_data' => '/traffic'] 26 | ], 27 | [ 28 | ['text' => "📖订阅链接", 'callback_data' => '/sublink'],['text' => "📝我的订阅", 'callback_data' => '/mysubscribe'] 29 | ], 30 | [ 31 | ['text' => "🏠购买套餐", 'callback_data' => '/store'], 32 | ], 33 | [ 34 | ['text' => "💲邀请返利", 'callback_data' => '/invite'],['text' => "💁最新官网", 'url' => $app_url] 35 | ], 36 | [ 37 | ['text' => "🌟在线客服", 'callback_data' => '/kefu'], 38 | ] 39 | ] 40 | ]); 41 | }else{ 42 | $reply_markup = json_encode([ 43 | 'inline_keyboard' => [ 44 | [ 45 | ['text' => "注册账户", 'url' => $app_url], 46 | ], 47 | [ 48 | ['text' => "绑定账户", 'callback_data' => '/bind'], 49 | ] 50 | ] 51 | ]); 52 | } 53 | $text = sprintf( 54 | "尊敬的用户,欢迎使用 %s\n%s", 55 | config('v2board.app_name', 'V2Board'), 56 | config('v2board.app_description') 57 | ); 58 | if(isset($message->callback_query_id)){ 59 | $telegramService->editMessageText($message->chat_id,$message->message_id, $text, $reply_markup); 60 | }else{ 61 | $telegramService->sendMessageMarkup($message->chat_id, $text, $reply_markup); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /app/Plugins/Telegram/Commands/Store.php: -------------------------------------------------------------------------------- 1 | telegramService; 14 | if (!$message->is_private) return; 15 | $telegramService->answerCallbackQuery($message->callback_query_id, '别着急,马上上线了','true'); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /app/Plugins/Telegram/Commands/SubLink.php: -------------------------------------------------------------------------------- 1 | telegramService; 15 | if (!$message->is_private) return; 16 | $user = User::where('telegram_id', $message->user_id)->first(); 17 | if (!$user) { 18 | $telegramService->answerCallbackQuery($message->callback_query_id,'没有查询到您的用户信息,请先绑定账号','true'); 19 | return; 20 | } 21 | $userplan = Plan::find($user->plan_id); 22 | if (!$userplan) { 23 | $telegramService->answerCallbackQuery($message->callback_query_id,'您暂无订阅','true'); 24 | return; 25 | } 26 | $subscribe_url = Helper::getSubscribeHost() . "/api/v1/client/subscribe?token={$user['token']}"; 27 | $text = "我的订阅链接(点击即可复制):\n————————————\n`$subscribe_url`"; 28 | $reply_markup = json_encode([ 29 | 'inline_keyboard' => [ 30 | [ 31 | ['text' => "订阅信息", 'callback_data' => '/mysubscribe'], 32 | ], 33 | [ 34 | ['text' => "返回菜单", 'callback_data' => '/start'], 35 | ] 36 | ] 37 | ]); 38 | $telegramService->editMessageText($message->chat_id,$message->message_id, $text, $reply_markup); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /app/Plugins/Telegram/Commands/Traffic.php: -------------------------------------------------------------------------------- 1 | telegramService; 14 | if (!$message->is_private) return; 15 | $user = User::where('telegram_id', $message->chat_id)->first(); 16 | if (!$user) { 17 | $telegramService->sendMessage($message->chat_id, '没有查询到您的用户信息,请先绑定账号', 'markdown'); 18 | return; 19 | } 20 | $transferEnable = Helper::trafficConvert($user->transfer_enable); 21 | $up = Helper::trafficConvert($user->u); 22 | $down = Helper::trafficConvert($user->d); 23 | $remaining = Helper::trafficConvert($user->transfer_enable - ($user->u + $user->d)); 24 | $text = "🚥流量查询\n———————————————\n计划流量:`$transferEnable`\n已用上行:`$up`\n已用下行:`$down`\n剩余流量:`$remaining`"; 25 | $reply_markup = json_encode([ 26 | 'inline_keyboard' => [ 27 | [ 28 | ['text' => "订阅信息", 'callback_data' => '/mysubscribe'], 29 | ], 30 | [ 31 | ['text' => "返回菜单", 'callback_data' => '/start'], 32 | ] 33 | ] 34 | ]); 35 | $telegramService->editMessageText($message->chat_id, $message->message_id, $text, $reply_markup); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /app/Services/TelegramService.php: -------------------------------------------------------------------------------- 1 | api = 'https://api.telegram.org/bot' . config('v2board.telegram_bot_token', $token) . '/'; 15 | } 16 | 17 | public function sendMessage(int $chatId, string $text, string $parseMode = '') 18 | { 19 | if ($parseMode === 'markdown') { 20 | $text = str_replace('_', '\_', $text); 21 | } 22 | $this->request('sendMessage', [ 23 | 'chat_id' => $chatId, 24 | 'text' => $text, 25 | 'parse_mode' => $parseMode 26 | ]); 27 | } 28 | public function sendMessageMarkup(int $chatId, string $text, string $reply_markup) 29 | { 30 | $this->request('sendMessage', [ 31 | 'chat_id' => $chatId, 32 | 'text' => $text, 33 | 'reply_markup' => $reply_markup, 34 | 'parse_mode' => 'markdown' 35 | ]); 36 | } 37 | public function answerCallbackQuery(int $callback_query_id, string $text, string $show_alert) 38 | { 39 | $this->request('answerCallbackQuery', [ 40 | 'callback_query_id' => $callback_query_id, 41 | 'text' => $text, 42 | 'show_alert' => $show_alert 43 | ]); 44 | } 45 | public function editMessageText(int $chatId, string $message_id, string $text, string $reply_markup) 46 | { 47 | $this->request('editMessageText', [ 48 | 'chat_id' => $chatId, 49 | 'message_id' => $message_id, 50 | 'text' => $text, 51 | 'reply_markup' => $reply_markup, 52 | 'parse_mode' => 'markdown' 53 | ]); 54 | } 55 | public function getMe() 56 | { 57 | return $this->request('getMe'); 58 | } 59 | 60 | public function setWebhook(string $url) 61 | { 62 | return $this->request('setWebhook', [ 63 | 'url' => $url 64 | ]); 65 | } 66 | 67 | private function request(string $method, array $params = []) 68 | { 69 | $curl = new Curl(); 70 | $curl->get($this->api . $method . '?' . http_build_query($params)); 71 | $response = $curl->response; 72 | $curl->close(); 73 | if (!isset($response->ok)) abort(500, '请求失败'); 74 | if (!$response->ok) { 75 | abort(500, '吱吱提醒:来自TG的错误:' . $response->description); 76 | } 77 | return $response; 78 | } 79 | 80 | public function sendMessageWithAdmin($message, $isStaff = false) 81 | { 82 | if (!config('v2board.telegram_bot_enable', 0)) return; 83 | $users = User::where(function ($query) use ($isStaff) { 84 | $query->where('is_admin', 1); 85 | if ($isStaff) { 86 | $query->orWhere('is_staff', 1); 87 | } 88 | }) 89 | ->where('telegram_id', '!=', NULL) 90 | ->get(); 91 | foreach ($users as $user) { 92 | SendTelegramJob::dispatch($user->telegram_id, $message); 93 | } 94 | } 95 | } 96 | --------------------------------------------------------------------------------