use*_*842 5 php audio telegram telegram-bot
我在 php telegram bot 中的 sendAudio() 函数遇到问题。
if (strtoupper($text) == "MUSIC") {
$voice = curl_file_create('audio.ogg');
$content = array('chat_id' => $chat_id, 'audio' => $voice);
$telegram->sendAudio($content);
}
Run Code Online (Sandbox Code Playgroud)
这不适用于 9 秒或更长的音频长度。我也尝试过使用 .mp3 但没有任何结果。音频长度为 6 秒或更短的情况下也可以使用相同的功能。我查看了文档,它说只有 50MB 的文件受到限制。请帮忙。这是我的 $telegram。
include("Telegram.php");
$bot_id = "xxxxxxx:yyyyyyyy_mytoken";
$telegram = new Telegram($bot_id);
Run Code Online (Sandbox Code Playgroud)
这里是 Telegram.php:
class Telegram {
private $bot_id = "mytoken";
private $data = array();
private $updates = array();
public function __construct($bot_id) {
$this->bot_id = $bot_id;
$this->data = $this->getData();
}
public function endpoint($api, array $content, $post = true) {
$url = 'https://api.telegram.org/bot' . $this->bot_id . '/' . $api;
if ($post)
$reply = $this->sendAPIRequest($url, $content);
else
$reply = $this->sendAPIRequest($url, array(), false);
return json_decode($reply, true);
}
public function sendAudio(array $content) {
return $this->endpoint("sendAudio", $content);
}
Run Code Online (Sandbox Code Playgroud)