Last active
March 16, 2019 04:33
-
-
Save abcprintf/c5f81e78ff648b920ebb499ce6406cff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$apiToken = ""; // Your Token | |
$chat_id = ""; // Your Chat ID | |
$text = $_GET['text']; | |
// V1 | |
/* | |
$params = [ | |
'chat_id' => $chat_id, | |
'text' => $text | |
]; | |
$response = file_get_contents("https://api.telegram.org/bot$apiToken/sendMessage?" . http_build_query($params)); | |
echo $response; | |
*/ | |
// V2 | |
$url = "https://api.telegram.org/bot$apiToken/sendMessage?"; | |
$postfields = array( | |
'chat_id' => $chat_id, | |
'disable_notification' => "False", | |
'parse_mode' => "HTML", | |
'text' => "<b>$text</b> \n xxx \n <a href=\"https://url.png\" target=\"_blank\">link</a>", | |
); | |
if (!$curld = curl_init()) { | |
exit; | |
} | |
curl_setopt($curld, CURLOPT_POST, true); | |
curl_setopt($curld, CURLOPT_POSTFIELDS, $postfields); | |
curl_setopt($curld, CURLOPT_URL,$url); | |
curl_setopt($curld, CURLOPT_RETURNTRANSFER, true); | |
$output = curl_exec($curld); | |
curl_close ($curld); | |
// Handle the response | |
$result = explode(';',$output); | |
$result_array = json_decode($result[0]); | |
//echo "<pre>", print_r(json_decode($result[0])), "</pre>"; | |
if ($result[0] == "Error") { | |
echo "Error message: $result[0]"; | |
die; | |
} else { | |
echo "Message ID: $result[0];"; | |
} | |
// Simple | |
// http://localhost/Telegram_Send_Message_PHP.php?text=abcprintf | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
get chat_id