Provides various official and user-released code examples. For code reference, you are welcome to exchange and learn the cool dog API. You can search for songs based on keywords and obtain the original music path.
A simple music website is provided based on this API:
Http://flc.ren/music
Code hosting address: https://code.csdn.net/flc1125/kugou-api/tree/master
Demo file, under the Code.
/**
* Cool dog API
* @ Author Flc <22:51:24>
*/
Require_once 'HTTP. class. php ';
Class kugou {
Const LIST_URL = 'HTTP: // lib9.service.kugou.com/websearch/index.php? Page = {page} & keyword = {keyword} & cmd = 100 & pagesize = {pagesize }';
Const MUSIC_URL = 'HTTP: // m.kugou.com/app/ I /getSongInfo.php? Hash = {hash} & cmd = playInfo ';
Protected static $ http = null;
/**
* Initialization
*/
Function _ construct (){
If (self ::$ http = null) self ::$ http = new http ();
}
/**
* Get the list
* @ Param string $ keyword
* @ Param integer $ page Current page
* @ Param integer $ pagesize the number of retrieved entries per page
* @ Return array | false
*/
Public function getList ($ keyword, $ page = 1, $ pagesize = 10 ){
$ Url = str_replace (array ('{page}', '{keyword}', '{pagesize}'), array ($ page, $ keyword, $ pagesize), self:: LIST_URL );
$ Json = self: $ http-> http_gets ($ url );
If (! $ Json) return false;
$ Resp = json_decode ($ json, true );
Return $ resp;
}
/**
* Obtain the music address
* @ Param string $ hash music hash code
* @ Return string | false
*/
Public function getMusic ($ hash ){
$ Url = str_replace (array ('{hash}'), array ($ hash), self: MUSIC_URL );
$ Json = self: $ http-> http_gets ($ url );
If (! $ Json) return false;
$ Resp = json_decode ($ json, true );
Return $ resp;
}
}
?>
Kugou.zip (2.13 KB download: 124 times)
AD: truly free, domain name + VM + enterprise mailbox = 0 RMB