我使用这个Api来管理机器人。
https://github.com/mgp25/Telegram-Bot-API
我想将URL从URL发送给电报用户,所以我改变这样的类,并在第399行之后添加此行
'audio/mpeg' => '.mp3',
mp3发送成功,但我的问题是函数返回json而不是将json转换为数组;我回显返回的数据,我已经在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));
答案 0 :(得分:2)
关于 1 在json的末尾,stackoverflow(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')));