将带有 php 的 mp3 文件发送到电报

Send mp3 file with php to telegram

我用这个 Api 来管理机器人。

https://github.com/mgp25/Telegram-Bot-API

我想从 URL 发送 MP3 给电报用户,所以我像这样更改 class 并在第 399 行之后添加此行

'audio/mpeg'   =>  '.mp3',

mp3 发送成功,但我的问题是函数 return json 而不是将 json 转换为数组;我回显 returned 数据,我知道了在 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));

关于1在json的结尾,Whosebug上有很多问答(for example)。但是如果你什么都不改变,仍然想得到一个数组,你可以试试这个

$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')));