2020-04-30 16:08:26 +08:00
|
|
|
<?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
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2020-05-17 15:23:39 +08:00
|
|
|
public function getMe()
|
|
|
|
{
|
|
|
|
dd($this->request('getMe'));
|
|
|
|
}
|
|
|
|
|
2020-04-30 16:08:26 +08:00
|
|
|
private function request(string $method, array $params)
|
|
|
|
{
|
|
|
|
$curl = new Curl();
|
2020-05-17 15:23:39 +08:00
|
|
|
$curl->get($this->api . $method, http_build_query($params));
|
2020-04-30 16:08:26 +08:00
|
|
|
$curl->close();
|
2020-05-17 15:23:39 +08:00
|
|
|
return $curl->response;
|
2020-04-30 16:08:26 +08:00
|
|
|
}
|
|
|
|
}
|