update telegram

This commit is contained in:
Tokumeikoi 2020-05-20 02:12:18 +08:00
parent de77170bdc
commit 11ca911d02
2 changed files with 27 additions and 36 deletions

View File

@ -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;
}
}

View File

@ -1,35 +0,0 @@
<?php
namespace Library;
use \Curl\Curl;
class Telegram {
protected $api;
public function __construct()
{
$this->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;
}
}