Home >Backend Development >PHP Tutorial >Using Telegram's interface to implement free message notification function in PHP
Telegram’s notifications are just like text message reminders. Using Telegram’s interface, you can achieve very convenient message reminders. You don’t need to open the APP or scientifically connect to the Internet. The point is, it’s free, there is no limit on the number of uses, and you don’t have to worry about censorship of text message content. Post whatever you want. In this article, we mainly introduce the use of Telegram’s interface in PHP to implement free message notification functions.
The following is the code for sending notifications using PHP:
<?php $bot_api_key = 'CHANGE HERE'; function send_get($urlstring){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $urlstring); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); $result = curl_exec($ch); curl_close($ch); return $result; } $text = @$_GET["text"]; $tgid = @$_GET["tgid"]; if($text){ $url = "https://api.telegram.org/bot$bot_api_key/sendMessage?chat_id=$tgid&text=$text"; echo send_get($url); }else{ echo "Please Input"; } ?>
Pass in two parameters, text and tgid.
tgid is the tg account ID that needs to receive messages. You can search for my robot @libinbinBot, and then send /myid to get your id.
The telegram interface format used here is:
https://api.telegram.org/bot[bot_api_key]/sendMessage?chat_id=[tgid]&text=[text]
The interface is simple and the call is very easy, and it is free without any restrictions.
The picture below is my tg interface, with customized product price reduction reminders and project ISSSUES library reminders:
The above content is about using Telegram’s interface to implement free message notification function in PHP. I hope it can help everyone.
Related recommendations:
javascript - segmentfault message notification reminder
Message notification plug-in based on HTML5 Notifications API
Counter implementation tutorial for message notification in Python’s Django framework
The above is the detailed content of Using Telegram's interface to implement free message notification function in PHP. For more information, please follow other related articles on the PHP Chinese website!