Home > Article > Backend Development > PHP implements music on demand on WeChat public platform_PHP tutorial
1. Construct the music message in XML format provided by WeChat
The XML format of music is like this:
2. Construction parameter $musicArray
Copy code
You can go to w3c to check the specific function usage of string interception. I won’t go into details. The main thing is to obtain the contents of MusicUrl and HQMusicUrl. Baidu music interface http://box.zhangmen.baidu.com/x?op = 12&count=1&title=TITLE $$AUTHOR$$$$
You enter http://box.zhangmen.baidu in the browser. com/x?op=12&count=1&title=About winter $$Qiqin$$$$ observe the content of the XML data provided by the interface, mainly the data in encode and decode, these two data are connected together , the contents of the CDATA inside are taken up to the end of xcode, that is, &mid=0.74155984312224. These contents are not required. I have tried it, but it cannot be played if this part of the song is added. The spliced data is the required MusicUrl and HQMusicUrl.
3. The following is the key point, use PHP to parse XML data
Because I don’t understand PHP syntax, I spent a lot of time
}
function getHQMusicUrl($url)
{
//echo strripos($url,"&")."HQmusicURL";
return substr($url ,strripos($url,"http"),strripos($url,"&")-strripos($url,"http"));
}
I use DOM to do it Yes, Baidu knows and asks others. Of course, there is a better way to get the MusicUrl in the XML data:
Screenshot of the final achievement: