我可以使用以下代码将照片发送到带有聊天id的telegram聊天:
<?php
$bot_url = "https://api.telegram.org/bot<token-bot>/";
$ch = curl_init($bot_url.'SendPhoto');
$cfile = new CURLFile(realpath('file.png'),'image/png','photo.png');
$data = array(
'chat_id' => '118186395',
'photo' => $cfile ,
'caption' => 'testing'
);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
echo curl_exec($ch);
?>
但是,如果我将chat_id
值更改为我的频道id,我会从电报中收到一个空的答复,并且照片不会发送。
您的频道应该是公共的,并且chat_id
的格式必须是@channelusername
。
源