From 11ca911d024866ea51f3a412638d38928fcc83c8 Mon Sep 17 00:00:00 2001 From: Tokumeikoi Date: Wed, 20 May 2020 02:12:18 +0800 Subject: [PATCH] update telegram --- app/Services/UserService.php | 28 +++++++++++++++++++++++++++- library/Telegram.php | 35 ----------------------------------- 2 files changed, 27 insertions(+), 36 deletions(-) delete mode 100644 library/Telegram.php diff --git a/app/Services/UserService.php b/app/Services/UserService.php index 8f586a12..3459d284 100644 --- a/app/Services/UserService.php +++ b/app/Services/UserService.php @@ -76,7 +76,7 @@ class UserService return true; } - public function trafficFetch(int $u, int $d, int $userId) + public function trafficFetch(int $u, int $d, int $userId):bool { $user = User::find($userId); if (!$user) { @@ -90,4 +90,30 @@ class UserService } return true; } + + public function setTelegramId(int $userId, int $telegramId):bool + { + $user = User::find($userId); + if (!$user) { + return false; + } + $user->telegram_id = $telegramId; + if (!$user->save()) { + return false; + } + return true; + } + + public function delTelegramId(int $userId):bool + { + $user = User::find($userId); + if (!$user) { + return false; + } + $user->telegram_id = NULL; + if (!$user->save()) { + return false; + } + return true; + } } diff --git a/library/Telegram.php b/library/Telegram.php deleted file mode 100644 index fdbf9cc3..00000000 --- a/library/Telegram.php +++ /dev/null @@ -1,35 +0,0 @@ -api = 'https://api.telegram.org/bot' . config('v2board.telegram_bot_token') . '/'; - } - - public function sendMessage(int $chatId, string $text, string $parseMode = '') - { - $this->request('sendMessage', [ - 'chat_id' => $chatId, - 'text' => $text, - 'parse_mode' => $parseMode - ]); - } - - public function getMe() - { - dd($this->request('getMe')); - } - - private function request(string $method, array $params) - { - $curl = new Curl(); - $curl->get($this->api . $method, http_build_query($params)); - $curl->close(); - return $curl->response; - } -}