[PHP源码]PHP获取网易云音乐mp3直链

释放双眼,带上耳机,听听看~!
大家好,今天给大家分享一个可以通过PHP直接获取网易云音乐的直链的代码,喜欢的就分享下吧~

部分音乐可能因为版权或者其他原因,用这个php脚本可能获取不到 请见谅!

http直链

<?
error_reporting(0);
function getMusic($MusicUrl) {
    $temp = explode('=',$MusicUrl);
    $id = $temp[1];
    $MusicUrl = "http://music.163.com/api/song/enhance/player/url?id=".$id."&ids=[".$id."]&br=3200000";
    $result = file_get_contents($MusicUrl);
    header('Content-Type:application/json; charset=utf-8');
    print_r($result);
}
$MusicUrl = $_POST['url'];
//$MusicUrl = "https://music.163.com/#/song?id=450795499";
getMusic($MusicUrl);
?>

访问php?url=(网易云地址)即可,若需要支持https可以用下面的代码

https 301跳转

就在前不久网易云直链获取地址突然从https变回成http了,这个是获取真实链接然后再替换成https,不知道能维持多久

<?php
$id=$_GET['id'];
$reg = '/^[0-9][0-9]*$/';
if(preg_match($reg,$id)){
$url_cxk = getrealurl('https://music.163.com/song/media/outer/url?id=' . $id . '.mp3');
$neturl = str_replace("http://","https://",$url_cxk);
  if($neturl=="https://music.163.com/404"){
  header("Location: https://music.163.com/song/media/outer/url?id=".$id.".mp3");
exit;
  }else{
header("Location: ".$neturl."");
exit;
  }
}else{
echo "非法参数";
}
function getrealurl($url){
$header = get_headers($url,1);
if (strpos($header[0],'301') || strpos($header[0],'302')) {
    if(is_array($header['Location'])) {
        return $header['Location'][count($header['Location'])-1];
    }else{
        return $header['Location'];
    }
}else {
    return $url;
}
}
exit;
?>

访问php?id=id即可302转到https渠道的音乐链接。(网易云的id)

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

给TA赞赏
共{{data.count}}人
人已赞赏
网站源码

[PHP源码]赞支付最新易支付系统 全新界面

2019-5-13 19:46:43

模板主题资源汇总

SEOFY V1.5.3 - 商务WordPress模板,原价$59现免费分享

2019-11-10 11:48:31

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索