How to realize the function of online song ordering in Wechat public platform
This article mainly introduces how to achieve the function of online song ordering in Wechat public platform. It has a certain reference value. Interested friends can refer to it. I hope you will learn a lot after reading this article. Let the editor take you to know it.
Music news, the message interface of Wechat public platform, is a good news for Wechat public platform developers. According to this function, if we can make the function of ordering songs in Wechat, then we can listen to music without installing other APP and directly following an account in Wechat, which saves the trouble of installation and no longer takes up space. If the music resources are good enough, it is not impossible to kill all online music listening software on mobile phones.
Reply to music messages
12345678
Core code:
Public function getMusicInfo () {if ($this- > name = = "") {$content = array ("Title" = > "", "Description" = > "you haven't told me the music name yet?" , "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" = > "search 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 provides", "MusicUrl" = > $url_prefix.$url_suffix, "HQMusicUrl" = > $durl_prefix.$durl_suffix) } catch (Exception $e) {}} return $content;}
API call:
Include ('music.class.php'); $m = new MusicApi ($musicContent); $mArr = $m-> getMusicInfo (); return $this- > responseMusic ($mArr ["Title"], $mArr ["Description"], $mArr ["MusicUrl"], $mArr ["HQMusicUrl"], 0)
Demonstration of the effect:
Thank you for reading this article carefully. I hope the article "how to achieve online song ordering function in Wechat public platform" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!