This article shares the news interface of the public platform-music message, which is a good news for developers of the public platform. Based on this function, if you can enable the function of playing songs in the middle, you will be able to listen to the song without installing other apps and directly following an account in it, it also saves the trouble of installation and does not need to occupy space. If the music resources are good enough, it is not impossible to flash all the online music listening software on mobile phones.
Reply music message
toUser
fromUser
12345678
music
<![CDATA[TITLE]]>
DESCRIPTION
MUSIC_Url
HQ_MUSIC_Url
media_id
Core code:
Public function getMusicInfo () {if ($ this-> name = "") {$ content = array ("Title" => "", "Description" => "have you told me the music name? "," MusicUrl "=>" "," HQMusicUrl "=>" ");} else {if (strpos ($ this-> name," + ")) {$ music = explode ("+", $ this-> name); $ url =" http://box.zhangmen.baidu.com/x?op=12&count=1&title= ". $ Music [1]." $ ". $ music [0]." $ ";} else {$ url =" http://box.zhangmen.baidu.com/x?op=12&count=1&title= ". $ This-> name. "$" ;}$ ch = curl_init (); curl_setopt ($ ch, CURLOPT_URL, $ url); curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, true ); $ data = curl_exec ($ ch); $ content = array ("Title" => "song 【". $ this-> name. "]", "Description" => "retrieval failed", "MusicUrl" => "", "HQMusicUrl" => ""); try {@ $ menus = simplexml_load_string ($ data, 'simplexmlelement', LIBXML_NOCDATA); if ($ menus-> count> 0 & isset ($ menus-> url [0]) & isset ($ menus-> durl [0]) {$ url_prefix = substr ($ menus-> url [0]-> encode, 0, strripos ($ menus-> url [0]-> encode, '/') + 1); $ url_suffix = substr ($ menus-> url [0]-> decode, 0, strripos ($ menus-> url [0]-> decode, '&'); $ durl_prefix = substr ($ menus-> durl [0]-> encode, 0, strripos ($ menus-> durl [0]-> encode, '/') + 1 ); $ durl_suffix = substr ($ menus-> durl [0]-> decode, 0, strripos ($ menus-> durl [0]-> decode ,'&')); if (strpos ($ this-> name, "+") {$ content = array ("Title" => $ music [1], "Description" => $ music [0], "MusicUrl" => $ url_prefix. $ url_suffix, "HQMusicUrl" => $ durl_prefix. $ durl_suffix);} else {$ content = array ("Title" => $ this-> name, "Description" => "Baidu Music ", "MusicUrl" => $ url_prefix. $ url_suffix, "HQMusicUrl" => $ durl_prefix. $ durl_suffix) ;}} catch (Exception $ e) {}} return $ content ;}
Interface call:
include ('music.class.php');$m = new MusicApi($musicContent);$mArr = $m->getMusicInfo();return $this->responseMusic($mArr["Title"], $mArr["Description"], $mArr["MusicUrl"], $mArr["HQMusicUrl"], 0);
Demo:
The above is a detailed introduction to the online karaoke feature developed by the public platform. For more information, see other related articles on php Chinese network!