音乐搜索
小明API 官方文档
根据音乐名称返回音乐详情
基本说明:
接口地址:https://api.apiopen.top/searchMusic
返回格式:json
请求方式:get/post
请求示例:https://api.apiopen.top/searchMusic?name=我爱你
请求参数说明:
名称 类型 必填 说明
name String 必填 音乐名称
返回参数说明:
名称 类型 说明
code int 状态码
message string 提示消息
result array 结果集合
JSON返回示例:
{
	"code": 200,
	"message": "成功!",
	"result": [{
		"author": "Ayasa绚沙",
		"link": "http://music.163.com/#/song?id=458231315",
		"pic": "http://p2.music.126.net/ZRTknw6EXU6XsCbjN8x1og==/109951163984548453.jpg?param=300x300",
		"type": "netease",
		"title": "我愛你",
		"lrc": "",
		"songid": 458231315,
		"url": "http://music.163.com/song/media/outer/url?id=458231315.mp3"
	}, {
		"author": "卢广仲",
		"link": "http://music.163.com/#/song?id=109628",
		"pic": "http://p2.music.126.net/dpHKvxD5RrDYk-2tY6NFWA==/109951163618701907.jpg?param=300x300",
		"type": "netease",
		"title": "我爱你",
		"lrc": "",
		"songid": 109628,
		"url": "http://music.163.com/song/media/outer/url?id=109628.mp3"
	}, {
		"author": "贺仙人,王晓夫,KAII",
		"link": "http://music.163.com/#/song?id=504652401",
		"pic": "http://p2.music.126.net/h2zkaSqvw3ufLilm2R1sQw==/109951163021924377.jpg?param=300x300",
		"type": "netease",
		"title": "我爱你 Luv Is Luv",
		"lrc": "",
		"songid": 504652401,
		"url": "http://music.163.com/song/media/outer/url?id=504652401.mp3"
	}, {
		"author": "新乐尘符",
		"link": "http://music.163.com/#/song?id=526307800",
		"pic": "http://p2.music.126.net/_LNk7rEEBSdAcnyHL8zi6Q==/109951163093399018.jpg?param=300x300",
		"type": "netease",
		"title": "123我爱你",
		"lrc": "",
		"songid": 526307800,
		"url": "http://music.163.com/song/media/outer/url?id=526307800.mp3"
	}, {
		"author": "S.H.E",
		"link": "http://music.163.com/#/song?id=374959",
		"pic": "http://p2.music.126.net/hwLmX8bjujh5rub3omKueg==/7968160766566527.jpg?param=300x300",
		"type": "netease",
		"title": "我爱你",
		"lrc": "",
		"songid": 374959,
		"url": "http://music.163.com/song/media/outer/url?id=374959.mp3"
	}, {
		"author": "王菲",
		"link": "http://music.163.com/#/song?id=191316",
		"pic": "http://p2.music.126.net/punwx3phmlbDx9EF3PBYmw==/109951163076925662.jpg?param=300x300",
		"type": "netease",
		"title": "我爱你",
		"lrc": "",
		"songid": 191316,
		"url": "http://music.163.com/song/media/outer/url?id=191316.mp3"
	}, {
		"author": "孙燕姿",
		"link": "http://music.163.com/#/song?id=287063",
		"pic": "http://p2.music.126.net/PehnaQ-BaAXeQg1d5s7leA==/6635552673699715.jpg?param=300x300",
		"type": "netease",
		"title": "我怀念的",
		"lrc": "",
		"songid": 287063,
		"url": "http://music.163.com/song/media/outer/url?id=287063.mp3"
	}, {
		"author": "腰乐队",
		"link": "http://music.163.com/#/song?id=28768121",
		"pic": "http://p2.music.126.net/vlAsuR_7xkGYlthG92Z81A==/109951164144451252.jpg?param=300x300",
		"type": "netease",
		"title": "我爱你",
		"lrc": "",
		"songid": 28768121,
		"url": "http://music.163.com/song/media/outer/url?id=28768121.mp3"
	}, {
		"author": "尹美莱",
		"link": "http://music.163.com/#/song?id=29011128",
		"pic": "http://p2.music.126.net/fAArmDSadIkxcWlJVDB96g==/18659811835355548.jpg?param=300x300",
		"type": "netease",
		"title": "너를 사랑해",
		"lrc": "",
		"songid": 29011128,
		"url": "http://music.163.com/song/media/outer/url?id=29011128.mp3"
	}, {
		"author": "尹吾",
		"link": "http://music.163.com/#/song?id=1294899028",
		"pic": "http://p2.music.126.net/Z-xRihOHD0B5_P91V_uRmg==/109951163414869168.jpg?param=300x300",
		"type": "netease",
		"title": "我爱你",
		"lrc": "",
		"songid": 1294899028,
		"url": "http://music.163.com/song/media/outer/url?id=1294899028.mp3"
	}]
}
服务级错误码参照
错误码 说明
400 参数错误
完整教学代码示例
<?php
/**
 * Created by PhpStorm.
 * User: FZS
 * Time: 2019/3/15 17:50
 */
//----------------------------------
// peakchao 音乐搜索 调用类
//----------------------------------
class freeApi{
    private $apiUrl = 'https://api.apiopen.top/searchMusic?name=%E6%88%91%E7%88%B1%E4%BD%A0';
    /**
     * 获取 音乐搜索 结果
     * @return array
     */
    public function getResult(){
        return $this->freeApiCurl($this->apiUrl);
    }
    /**
     * 请求接口返回内容
     * @param  string $url [请求的URL地址]
     * @param  string $params [请求的参数]
     * @param  int $ipost [是否采用POST形式]
     * @return  string
     */
    public function freeApiCurl($url,$params=false,$ispost=0){
        $ch = curl_init();
        curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
        curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
        curl_setopt( $ch, CURLOPT_USERAGENT , 'free-api' );
        curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );
        curl_setopt( $ch, CURLOPT_TIMEOUT , 60);
        curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );
        if( $ispost )
        {
            curl_setopt( $ch , CURLOPT_POST , true );
            curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );
            curl_setopt( $ch , CURLOPT_URL , $url );
        }
        else
        {
            if($params){
                curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );
            }else{
                curl_setopt( $ch , CURLOPT_URL , $url);
            }
        }
        $response = curl_exec( $ch );
        if ($response === FALSE) {
            return false;
        }
        curl_close( $ch );
        return $response;
    }
}
$res = new freeApi();
var_dump($res->getResult());