网易云API获取歌单歌曲链接

获取动态网易云歌单歌曲
如图:
`(2J8[Q@IHS02_M(VP9K6RR.png
~(7DZ)VEM4$%ZMS1B8V~8Q9.png

以下是php 代码

 *

    请输入<?php
    //获取歌单ID
     function getPlaylist($id){
        $return = file_get_contents('http://music.163.com/api/playlist/detail?id='.$id);
        return json_decode($return,true);
    }
    $api=getPlaylist('901252754');
    //var_dump($api);
    if(is_array($api)){
        foreach ($api as $value) {
    //var_dump($value);
    $str = "";
            if(is_array($value)){
                //var_dump($value['id']);
                foreach($value['tracks'] as $v){
                    $str.= $v['id'].',';   
                }
                $newstr = substr($str,0,strlen($str)-1); 
                 
            }
        }
    }
    //获取单个歌曲ID遍历
    function netease_AESECB($API)
        {
            $KEY='7246674226682325323F5E6544673A51';
            $body=json_encode($API['body']);
            if (function_exists('openssl_encrypt')) {
                $body=openssl_encrypt($body, 'aes-128-ecb', pack('H*', $KEY));
            } else {
                $PAD=16-(strlen($body)%16);
                $body=base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, hex2bin($KEY), $body.str_repeat(chr($PAD), $PAD), MCRYPT_MODE_ECB));
            }
            $body=strtoupper(bin2hex(base64_decode($body)));
            $API['body']=array(
                'eparams'=>$body,
            );
            return $API;
    }
    $br=320;
        $API=array(
                        'method' => 'POST',
                        'url'    => 'http://music.163.com/api/linux/forward',
                        'body'   => array(
                            'method' => 'POST',
                            'params' => array(
                                'ids' => array($newstr),
                                'br'  => $br*1000,
                            ),
                            'url' => 'http://music.163.com/api/song/enhance/player/url',
                        ),
                        'encode' => 'netease_AESECB',
                        'decode' => 'netease_url',
                    );
                    
        $API = netease_AESECB($API);
        
        $BASE = array(
                    'referer'   => 'https://music.163.com/',
                    'cookie'    => 'os=linux; appver=1.0.0.1026; osver=Ubuntu%2016.10; MUSIC_U=78d411095f4b022667bc8ec49e9a44cca088df057d987f5feaf066d37458e41c4a7d9447977352cf27ea9fee03f6ec4441049cea1c6bb9b6; __remember_me=true',
                    'useragent' => 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36',
                );
                
        $curl=curl_init();
        if ($API['method']=='POST') {
                if (is_array($API['body'])) {
                    $API['body']=http_build_query($API['body']);
                }
                
                curl_setopt($curl, CURLOPT_POST, 1);
                curl_setopt($curl, CURLOPT_POSTFIELDS, $API['body']);
            } elseif ($API['method']=='GET') {
                if (isset($API['body'])) {
                    $API['url']=$API['url'].'?'.http_build_query($API['body']);
                }
            }
            curl_setopt($curl, CURLOPT_HEADER, 0);
            curl_setopt($curl, CURLOPT_TIMEOUT, 20);
            curl_setopt($curl, CURLOPT_ENCODING, 'gzip');
            curl_setopt($curl, CURLOPT_IPRESOLVE, 1);
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
            curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10);
            curl_setopt($curl, CURLOPT_URL, $API['url']);
            curl_setopt($curl, CURLOPT_COOKIE, $BASE['cookie']);
            curl_setopt($curl, CURLOPT_REFERER, $BASE['referer']);
            curl_setopt($curl, CURLOPT_USERAGENT, $BASE['useragent']);
            $data=curl_exec($curl);
            curl_close($curl);
            //var_dump(json_decode($data));
            $arr=json_decode($data,TRUE);
            //var_dump($arr);
            $url = "";
            if(is_array($arr)){
                foreach ($arr as $value) {
                  if(is_array($value)){
                    foreach($value as $v){
                      $url.= $v['url'].',';        
                    }
                  }
            }
            }
             $url = substr($url,0,strlen($url)-1); 
           
    ?>

*

相关文章

此处评论已关闭

[player id="719102"/]