我用这个 API 来管理机器人。
https://github.com/mgp25/Telegram-Bot-API
我想将 MP3 从 URL 发送到电报用户,所以我像这样更改类并在第 399 行之后添加此行
'audio/mpeg' => '.mp3',
mp3发送成功,但我的问题是函数返回json而不是将json转换为数组;Iecho 返回数据,我在 json 字符串的末尾得到了它,像这样添加一个 1
{"ok":true,"result":{"message_id":46328,"from":{"id":115910361,"first_name":"Persian Robot","username":"TPersian_bot"},"chat":{"id":133180682,"first_name":"Mohammad Reza","last_name":"Behzadfar","username":"Lifesoul","type":"private"},"date":1457607231,"audio":{"duration":176,"mime_type":"audio'/mpeg","title":"Mozoo Chiye","performer":"Yasin","file_id":"BQADBAADKwAD2aboBniCRUQ1WE48Ag","file_size":7137408}}}1
这是我的代码:
$Telegram = new Telegram(API);
$result = $Telegram->sendAudio(133180682, "https://rjmediamusic.com/media/mp3/Yasin-Mozoo-Chiye.mp3");
var_dump(json_decode(rtrim($result,'1'),TRUE));
在 json 的末尾大约 1,有很多关于 stackoverflow 的问答(例如)。但是,如果您不会更改任何内容并且仍然想获得一个数组,则可以尝试此操作
$json = '{"ok":true,"result":{"message_id":46328,"from":{"id":115910361,"first_name":"Persian Robot","username":"TPersian_bot"},"chat":{"id":133180682,"first_name":"Mohammad Reza","last_name":"Behzadfar","username":"Lifesoul","type":"private"},"date":1457607231,"audio":{"duration":176,"mime_type":"audio'/mpeg","title":"Mozoo Chiye","performer":"Yasin","file_id":"BQADBAADKwAD2aboBniCRUQ1WE48Ag","file_size":7137408}}}1';
var_dump(json_decode(trim($json, '1')));