[英]telegram bot send message from server failed (PHP)
I need a simple bot to send message via telegram. 我需要一个简单的机器人来通过电报发送消息。 I use this php code for the reason: 我使用此php代码的原因是:
header('Content-Type: text/html; charset=utf-8');
$message= file_get_contents("php://input");
$arrayMessage= json_decode($message, true);
$token= "*********";
$chat_id= $arrayMessage['message']['from']['id'];
$command= $arrayMessage['message']['text'];
if($command == '/start'){
$text= "Hello";
$url= "https://api.telegram.org/bot".$token."/sendMessage?chat_id=".$chat_id."&text=".$text;
file_put_contents("message.txt", $url);
//file_get_contents ($url);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
}
any suggestion? 有什么建议吗?
i use cloudflare for ssl certificate and the webhook method is initiated. 我将cloudflare用于ssl证书,并启动了webhook方法。
Maybe you need to add 也许您需要添加
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
and other debugging code to find the error as follows: 和其他调试代码查找错误如下:
var_dump ( curl_getinfo ( $ch ) );
if (curl_errno ( $ch )) {
print curl_error ( $ch );
} else {
curl_close ( $ch );
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.