简体   繁体   English

使用 php 向电报机器人发送消息

[英]send message to telegram bot with php

<?php
$parameters = array(
    "chat_id" => "93501313",
    "text" => "Hello",
    "disable_web_page_preview" => "true",
    "parse_mode" => "Markdown"
);
send($parameters);
function send($parameters) {
$bot_token = "1409756432:AAGfblN66E888LKIUDUgVJt_dXtyFfFhGN0";
$url = "https://api.telegram.org/bot$bot_token/sendMessage";
if(!$ch = curl_init()){
    exit();
}
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $parameters);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$outpot = curl_exec($ch);
return $outpot;
}
?>

This is my code but not working这是我的代码但不起作用

I want to send some message to telegram bot.我想向电报机器人发送一些消息。

Thanks for help感谢帮助

Your code looks good, although, the chat ID you're using is not correct one.您的代码看起来不错,但您使用的聊天 ID 不正确。 You need to manually get the channel ID via bot getMessages endpoint API.您需要通过 bot getMessages端点 API 手动获取通道 ID。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM