Introduction to online karaoke function developed on WeChat public platform

Source: Internet
Author: User
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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.