sendPhoto命令需要一个定义为的参数。photo
InputFile or String
API文档告诉:
Photo to send. You can either pass a file_id as String to resend a photo
that is already on the Telegram servers, or upload a new photo using
multipart/form-data.
和
InputFile
This object represents the contents of a file to be uploaded. Must be
posted using multipart/form-data in the usual way that files are
uploaded via the browser.
所以我尝试了这个方法
$bot_url = "https://api.telegram.org/bot<bot_id>/";
$url = $bot_url . "sendPhoto?chat_id=" . $chat_id;
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type:multipart/form-data"
));
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
"photo" => "@/path/to/image.png",
));
curl_setopt($ch, CURLOPT_INFILESIZE, filesize("/root/dev/fe_new.png"));
$output = curl_exec($ch);
卷发已执行,但 Telegram 回复我:
Error: Bad Request: Wrong persistent file_id specified: contains wrong
characters or have wrong length
我也尝试用@/path...
a替换file_get_contents
,但在这种情况下 Telegram 给我一个空的回复(并且curl_error
是空的!)。
使用 php + curl 将照片发送到电报的方式是什么?