如果可能的话,我需要一些帮助,如果可能的话,我一直在我的sendPhoto服务器上使用sendPhoto方法将图像自动发送到电报中,我已经使用了将近6-7个月的相同方法,从几天前开始,api方法突然停止了工作。我尝试使用url中文件的绝对路径和使用directory+filename文件在php中传递文件的绝对路径,但是我从api发送了一个错误msg,如下所示,第一部分是我的php方法,它不返回任何错误,只显示为空白。
# my php telegram code
$dir = "Attachments/2022/04/09/imagename.jpeg";
$chat_id = '(groupchatid)';
$bot_url = "https://api.telegram.org/bot(mybotapi)/";
$url = $bot_url . "sendPhoto?chat_id=" . $chat_id ;
$post_fields = array('chat_id' => $chat_id,
'photo' => new CURLFile(realpath($dir)),
'caption' =>'Test Image', );
$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, $post_fields);
$output = curl_exec($ch);
当我像以前一样执行这个脚本时,这是我从API获得的响应。
{
"ok": false,
"error_code": 400,
"description": "Bad Request: invalid file HTTP URL specified: Unsupported URL protocol"
}
如果我将图像URL替换到另一台服务器,它成功地发送了图像,但我无法仅从服务器发送任何东西,如果我尝试使用服务器图像文件的URL直接访问该文件,我可以从任何pc上访问它,没有问题,唯一的问题是电报获取图像,请帮助,欣赏它
发布于 2022-06-27 06:19:57
对不起,我通常不使用卷发,所以我可以给你另一个选择:
function sendPhoto($id, $photo, $text = null){
GLOBAL $token;
$url = 'https://api.telegram.org/bot'.$token."/sendPhoto?
chat_id=$id&photo=$photo&parse_mode=HTML&caption=".urlencode($text);
file_get_contents($url);
}
只需以这种方式声明sendPhoto函数,将存储令牌的变量放入其中而不是"$token“,并以这种方式使用参数:
https://stackoverflow.com/questions/71835685
复制