Home > php教程 > php手册 > 酷狗API,可根据关键字搜索歌曲及获取音乐原始路径

酷狗API,可根据关键字搜索歌曲及获取音乐原始路径

WBOY
Release: 2016-06-07 11:37:09
Original
2911 people have browsed it

酷狗API,可根据关键字搜索歌曲及获取音乐原始路径

附根据该API,做的一个简单的音乐网站:http://flc.ren/music

代码托管地址:https://code.csdn.net/flc1125/kugou-api/tree/master

demo文件,在代码下方。<?php <br /> /**<br>  * 酷狗API类<br>  * @author Flc <br>  */<br> require_once 'http.class.php';<br> <br> class kugou{<br>     const LIST_URL  = 'http://lib9.service.kugou.com/websearch/index.php?page={page}&keyword={keyword}&cmd=100&pagesize={pagesize}';<br>     const MUSIC_URL = 'http://m.kugou.com/app/i/getSongInfo.php?hash={hash}&cmd=playInfo';<br> <br>     protected static $http = null;<br> <br>     /**<br>      * 初始化<br>      */<br>     function __construct(){<br>         if(self::$http == null) self::$http = new http();<br>     }<br> <br>     /**<br>      * 获取列表<br>      * @param  string  $keyword  关键字<br>      * @param  integer $page     当前页<br>      * @param  integer $pagesize 每页获取数量<br>      * @return array|false            <br>      */<br>     public function getList($keyword, $page = 1, $pagesize = 10){<br>         $url  = str_replace(array('{page}', '{keyword}', '{pagesize}'), array($page, $keyword, $pagesize), self::LIST_URL);<br> <br>         $json = self::$http->http_gets($url);<br>         if(!$json) return false;<br>         $resp = json_decode($json, true);<br> <br>         return $resp;<br>     }<br> <br>     /**<br>      * 获取音乐地址<br>      * @param  string $hash 音乐hash码<br>      * @return string|false       <br>      */<br>     public function getMusic($hash){<br>         $url  = str_replace(array('{hash}'), array($hash), self::MUSIC_URL);<br> <br>         $json = self::$http->http_gets($url);<br>         if(!$json) return false;<br>         $resp = json_decode($json, true);<br> <br>         return $resp;<br>     }<br> }<br> ?>

附件 kugou.zip ( 2.13 KB 下载:124 次 )

AD:真正免费,域名+虚机+企业邮箱=0元

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template