PHP APIs for obtaining QQ Music

Source: Internet
Author: User
PHP APIs for obtaining QQ Music
QQ soso music search api demo address: http://www.ip62.com/qqmusic/ click mp3 address after the direct online playback

  1. Class music {
  2. Private $ musicname;
  3. Public function _ construct ($ musicname ){
  4. $ This-> musicname = $ musicname;
  5. }
  6. Private function map_url (){
  7. $ Url = "http://shopcgi.qqmusic.qq.com/fcgi-bin/shopsearch.fcg? Value = ". urlencode (iconv (" UTF-8 "," gb2312 ", $ this-> musicname ));
  8. If (! Function_exists ("file_get_contents "))
  9. {
  10. $ Ch = curl_init ();
  11. $ Timeout = 5;
  12. Curl_setopt ($ ch, CURLOPT_URL, $ url );
  13. Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 );
  14. Curl_setopt ($ ch, CURLOPT_CONNECTTIMEOUT, $ timeout );
  15. $ File_contents = curl_exec ($ ch );
  16. Curl_close ($ ch );
  17. } Else {
  18. $ File_contents = file_get_contents ($ url );
  19. }
  20. Return $ file_contents;
  21. }
  22. Public function getmusic (){
  23. $ Data = $ this-> map_url ();
  24. $ Data = substr ($ data, 15 );
  25. $ Data = substr ($ data, 0,-2 );
  26. Preg_match ("/songlist \:\[(? P . *) \] \}/I ", $ data, $ musicdata );
  27. $ Musicdata = explode (",", $ musicdata ['music']);
  28. $ Music = array ();
  29. Foreach ($ musicdata as $ v ){
  30. If (preg_match ("/\ {idx \:(? P . *)/I ", $ v, $ )){
  31. $ Id = trim ($ a [id], "\" ");
  32. }
  33. If (preg_match ("/song_id \:(? P . *)/I ", $ v, $ c )){
  34. $ Music [$ id] ['Song _ id']. = trim ($ c ['Song _ id'], "\" ");
  35. }
  36. If (preg_match ("/song_name \:(? P . *)/I ", $ v, $ s )){
  37. $ Music [$ id] ['Song _ name']. = trim ($ s ['Song _ name'], "\" ");
  38. }
  39. If (preg_match ("/album_name \:(? P. *)/I ", $ v, $ n )){
  40. $ Music [$ id] ['Album _ name']. = trim ($ n ['Album _ name'], "\" ");
  41. }
  42. If (preg_match ("/singer_name \:(? P . *)/I ", $ v, $ name )){
  43. $ Music [$ id] ['singer _ name']. = trim ($ name ['singer _ name'], "\" ");
  44. }
  45. If (preg_match ("/location \:(? P . *)/I ", $ v, $ l )){
  46. $ Music [$ id] ['location']. = trim ($ l ['location'], "\" ");
  47. }
  48. }
  49. Return $ music;
  50. }
  51. Public function getmusicurl (){
  52. $ Muiscurl = "";
  53. $ Result = $ this-> getmusic ();
  54. Foreach ($ result as $ id => $ v ){
  55. $ Muiscurl. = "song {$ id}, song name :". iconv ("gb2312", "UTF-8", $ v ['Song _ name']). ", artist :". iconv ('gb2312', 'utf-8', $ v ['singer _ name']). ", album :". iconv ('gb2312', 'utf-8', $ v ['Album _ name']). ", song address: http: // stream1 {$ v ['location']} .qqmusic.qq.com/3366?v='song_id '{}}
    ";
  56. }
  57. Return $ muiscurl;
  58. }
  59. }
  60. $ Music = new music ("Happy new Year ");
  61. $ Data = $ music-> getmusic ();
  62. // Var_dump ($ data );
  63. // Echo "http: // stream1 {$ data [1] ['localtion ']} .qqmusic.qq.com/3366?data=1='song_id ";
  64. Echo $ music-> getmusicurl ();
  65. // Demo address: http://www.ip62.com/qqmusic/
  66. ?>

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.