酷狗API,可根据关键字搜索歌曲及获取音乐原始路径。demo文件在附件中,下载后请将“.txt”后缀去掉,再进行解压。
附根据该API,做的一个简单的音乐网站:http://music.flc.ren/
<?php/**
* 酷狗API类
* @author Flc <2015-08-27 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;
/**
* 初始化
*/
function __construct(){
if(self::$http == null) self::$http = new http();
}
/**
* 获取列表
* @param string $keyword 关键字
* @param integer $page 当前页
* @param integer $pagesize 每页获取数量
* @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;
}
/**
* 获取音乐地址
* @param string $hash 音乐hash码
* @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;
}
}
?>
341704467 回复含违规内容 只看该作者 举报
341704467
好好