Skip to content

Commit

Permalink
Fixed upload certificate
Browse files Browse the repository at this point in the history
  • Loading branch information
mgp25 committed Sep 5, 2015
1 parent 6ae305d commit bd3a3ac
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/Telegram.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,15 +306,13 @@ public function getUserProfilePhotos($user_id, $offset = null, $limit = null)
*/
public function setWebhook($url, $certificate = null)
{
if (filter_var($url, FILTER_VALIDATE_URL) === false)
throw new TelegramException('Invalid URL provided');
if (filter_var($url, FILTER_VALIDATE_URL) === false)
throw new TelegramException('Invalid URL provided');

if (parse_url($url, PHP_URL_SCHEME) !== 'https')
throw new TelegramException('Invalid URL, it should be a HTTPS url.');
if (parse_url($url, PHP_URL_SCHEME) !== 'https')
throw new TelegramException('Invalid URL, it should be a HTTPS url.');

$params = compact('url', 'certificate');

return $this->sendRequest('setWebhook', $params);
return $this->uploadFile('setWebhook', compact('url', 'certificate'));
}

/**
Expand Down Expand Up @@ -391,12 +389,14 @@ private function uploadFile($method, $data)
'sendAudio' => 'audio',
'sendDocument' => 'document',
'sendSticker' => 'sticker',
'sendVideo' => 'video'
'sendVideo' => 'video',
'setWebhook' => 'certificate'
);

$file = __DIR__ . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . mt_rand(0, 9999);
if (filter_var($data[$key[$method]], FILTER_VALIDATE_URL))
{
$file = __DIR__ . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . mt_rand(0, 9999);

$url = true;
file_put_contents($file, file_get_contents($data[$key[$method]]));
$finfo = finfo_open(FILEINFO_MIME_TYPE);
Expand Down

0 comments on commit bd3a3ac

Please sign in to comment.