-1,"msg"=>"歌曲ID为空"); echojson(json_encode($tempArr)); }else{ $url= "http://music.163.com/api/song/detail/?id={$id}&ids=%5B{$id}%5D&csrf_token="; //请求url $post_data = ''; echojson(curl($url,$post_data)); } break; case "lyric": //获取歌词 @$id = $_POST['id']?$_POST['id']:$_GET['id']; //歌曲ID if(!$id){ $tempArr = array("code"=>-1,"msg"=>"歌曲ID为空"); echojson(json_encode($tempArr)); }else{ $url = "http://music.163.com/api/song/lyric?os=pc&id=" . $id . "&lv=-1&kv=-1&tv=-1"; //请求url $post_data = ''; echojson(curl($url,$post_data)); } break; case "download": //下载歌曲 @$fileurl = $_POST['url']?$_POST['url']:$_GET['url']; //链接 @$musicname = $_POST['name']?$_POST['name']:$_GET['name']; //歌曲名字 if(!$fileurl){ $tempArr = array("code"=>-1,"msg"=>"歌曲链接为空"); echojson(json_encode($tempArr)); }else{ $ua = $_SERVER["HTTP_USER_AGENT"]; $filename = $musicname . ".mp3"; $encoded_filename = urlencode($filename); $encoded_filename = str_replace("+", "%20", $encoded_filename); header("Content-Type: application/force-download"); if (preg_match("/MSIE/", $ua)) { header('Content-Disposition: attachment; filename="' . $encoded_filename . '"'); } else if (preg_match("/Firefox/", $ua)) { //火狐浏览器 header('Content-Disposition: attachment; filename*="utf8\'\'' . $filename . '"'); } else if (preg_match("/Edge/", $ua)) { //edge浏览器 header('Content-Disposition: attachment; filename="' . $encoded_filename . '"'); } else { header('Content-Disposition: attachment; filename="' . $filename . '"'); } //echo $musicname; //header("Content-Type: application/force-download"); //header('Content-Disposition: attachment; filename="'.$musicname.'.mp3"'); //header('Content-Transfer-Encoding: binary'); $mp3file = file_get_contents($fileurl); echo $mp3file; } break; case "userlist": //获取用户歌单 //http://music.163.com/api/user/playlist/?offset=0&limit=1001&uid=275545417 break; case "search": //搜索歌曲 default: @$s = $_POST['name']?$_POST['name']:$_GET['name']; //歌名 @$limit = $_POST['count']?$_POST['count']:$_GET['count']; //每页显示数量 @$pages = $_POST['pages']?$_POST['pages']:$_GET['pages']; //页码 if($pages>1000 || $pages<1)$pages=1; //纠正错误的值 if($limit == "") $limit = 20; @$offset= ($pages-1) * $limit; //偏移量 if(!$s){ $tempArr = array("code"=>-1,"msg"=>"歌名为空"); echojson(json_encode($tempArr)); }else{ $url= "http://music.163.com/api/search/get/web?csrf_token="; //请求url $post_data = 'hlpretag=&hlposttag=&s='. $s . '&type=1&offset='. $offset . '&total=true&limit=' . $limit; echojson(curl($url,$post_data)); } } function echojson($data) //json和jsonp通用 { @$callback = $_POST['callback']?$_POST['callback']:$_GET['callback']; if($callback != "") //输出jsonp格式 { echo $callback."(".$data.")"; } else { echo $data; } }