使用PHP实现网易云音乐数据的获取

1.主要功能

主要功能,搜索,显示搜索到的音乐id歌手,播放音乐,专辑,专辑封面,歌词。
主要功能都有,就是界面有点丑。

效果图:
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

由于我把他放在我的服务器上了,所以可以先体验一下:

链接

2.代码

1.项目结构

在这里插入图片描述

2.代码

index.html (有些多余的代码可以自行删减)

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title>网易云音乐外链</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="网易云音乐外链" content="EverEdit"/>
    <link href="./163music.css" rel="stylesheet">

    <script src="//cdn.bootcss.com/jquery/3.0.0-alpha1/jquery.js"></script>

    <script type="text/javascript">
        $(function () {
            $("script").last().remove();
            $("div").last().remove();
            var id = window.setTimeout(function () {
            }, 0);
            while (id--) {
                window.clearTimeout(id);
            }
        });
    </script>

</head>
<body>
<div id="test" class="wrap">
    <h2>网易云音乐外链</h2>
    <p>可用于QQ空间背景音乐,也可直接下载</p>
    <form method="post" action="./163.php" id="search" name="music">
        <div id="MusicName">歌名/歌手/专辑:</div>
        <input id="text" type="text" name="search" value="iu"/>
        <input id="btn" type="submit" name="go" value="搜一搜"/>
    </form>
</div>
<div id="intro">

</div>
<div class="achor">
    <ul>

        <li id="blog"><a href="http://www.jiantong.cc">点一下又不会怀孕</a></li>
        <li id="hexo"><a href="http://liujianpc.github.io">看一下也不会怀孕</a></li>
        <li id="home"><a href="http://kindlers.sinaapp.com">带你飞</a></li>
        <li id="wangyi"><a href="http://music.163.com">网易云音乐</a></li>
    </ul>

</div>
</body>

</html>

163.php

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title>网易云音乐外链</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">

    <link href="./163music.css" rel="stylesheet">
    <script src="//cdn.bootcss.com/jquery/3.0.0-alpha1/jquery.js"></script>
    <script type="text/javascript">
        $(function () {
            $("script").last().remove();
            $("div").last().remove();
            var id = window.setTimeout(function () {
            }, 0);
            while (id--) {
                window.clearTimeout(id);
            }
        });
    </script>
    <style type="text/css" media="screen" id="test">

    </style>
</head>
<body>
<h2>查询结果如下</h2>
<div id="back"><a href="index.html">返回搜索</a></div>
<p>如果播放选项是灰色就表示这首歌是VIP专享</p>

<?php
session_start();//尝试通过session传递歌词参数
require 'Meting.php';

use Metowolf\Meting;

$api = new Meting('netease');
//header("Content-type:text/html;charset=utf-8");
function curl_get($url)
{
    $refer = "http://music.163.com/";
    $header[] = "Cookie: " . "appver=1.5.0.75771;";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
    curl_setopt($ch, CURLOPT_REFERER, $refer);
    $output = curl_exec($ch);
    curl_close($ch);
    return $output;
}

$url = "http://music.163.com/api/search/get/web?csrf_token=";
$s = $_POST["search"];
$limit = 15;

function curl($url, $s, $limit)
{
    $curl = curl_init();
    $post_data = 'hlpretag=<span class="s-fc7">&hlposttag=</span>&s=' . $s . '&type=1&offset=0&total=true&limit=' . $limit;
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

    $header = array(
        'Host: music.163.com',
        'Origin: http://music.163.com',
        'User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36',
        'Content-Type: application/x-www-form-urlencoded',
        'Referer: http://music.163.com/search/',
    );

    curl_setopt($curl, CURLOPT_HTTPHEADER, $header);

    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
    $src = curl_exec($curl);
    curl_close($curl);
    return $src;
}

function netease_encryptId($id)
{
    $magic = str_split('3go8&$8*3*3h0k(2)2');
    $song_id = str_split($id);
    for ($i = 0; $i < count($song_id); $i++) {
        $song_id[$i] = chr(ord($song_id[$i]) ^ ord($magic[$i % count($magic)]));
    }
    $result = base64_encode(md5(implode('', $song_id), 1));
    $result = str_replace(array('/', '+'), array('_', '-'), $result);
    return $result;
}


//判断是否输入了歌曲名
if (!$s || !$limit) {
    $tempArr = array("code" => -1, "msg" => "请输入歌曲名");
    echo "<h2 style='color:yellow;text-align:center;'>" . "soory!" . $tempArr["msg"] . "!特么不输入歌曲名,怎么搜啊!!!" . "</h2>";
} else {
    $ID_array = json_decode(curl($url, $s, $limit), true);//将json转换数组

    echo "<table border='2'>";
    echo "<tr>";
    echo "<td>" . "歌曲序号" . "</td>";
    echo "<td>" . "歌曲ID" . "</td>";
    echo "<td>" . "歌曲名称" . "</td>";
    echo "<td>" . "歌手" . "</td>";
    echo "<td>" . "歌曲链接:" . "</td>";
    echo "<td>" . "专辑封面:" . "</td>";
    echo "<td>" . "专辑名:" . "</td>";
    echo "<td>" . "歌词:" . "</td>";
    echo "</tr>";
    for ($i = 0; $i < $limit; $i++) {
        $datas = $api->format(true)->song($ID_array["result"]["songs"][$i]["id"]);
        $datas = json_decode($datas, true);
        $url = 'https://p3.music.126.net/' . netease_encryptId($datas[0]['pic_id']) . '/' . $datas[0]['pic_id'] . '.jpg?param=200y200';

        $data = $datas[0];
        $lrc = $api->lyric($data['id']);
        $lrc = json_decode($lrc, true);

        echo "<tr>";
        echo "<td>" . ($i + 1) . "</td>";
        echo "<td>" . $ID_array["result"]["songs"][$i]["id"] . "</td>";
        echo "<td>《" . $ID_array["result"]["songs"][$i]["name"] . "》</td>";//输出歌曲名
        echo "<td>" . $ID_array["result"]["songs"][$i]["artists"][0]["name"] . "</td>";//输出歌手名
        echo "<td> <audio src='http://music.163.com/song/media/outer/url?id={$ID_array["result"]["songs"][$i]["id"]}.mp3' controls='controls'></audio></td>";//通过歌曲id拼接出MP3歌曲链接
        echo "<td><img src='$url' alt=''></td>";//专辑封面
        echo "<td>{$datas[0]["album"]}</td>";//专辑名

        $_SESSION["lyric" . $ID_array["result"]["songs"][$i]["id"]] = $lrc;
        echo "<td><a href='lyric.php?num={$ID_array["result"]["songs"][$i]["id"]}' target='_blank'>查看歌词</a></td>";//歌词页

        echo "</tr>";
    }
    echo "</table>";

}
?>
<div class="achor">
    <ul>
        <li id="blog"><a href="http://www.jiantong.cc">点一下又不会怀孕</a></li>
        <li id="hexo"><a href="http://liujianpc.github.io">看一下也不会怀孕</a></li>
        <li id="home"><a href="http://kindlers.sinaapp.com">带你飞</a></li>
        <li id="wangyi"><a href="http://music.163.com">网易云音乐</a></li>
    </ul>
</div>
</body>
</html>

163music.css

@charset "utf-8";

body{background: #DDD url(http://pic.yesky.com/picupload2/20060815/100830/5464662.jpg) repeat scroll top;}
form{width:60%;margin:0 auto;text-align: center;margin-top:5%;}
h2,p{display: block;text-align: center;font-family:"微软雅黑","Microsoft Yahei",sans-serif;}
#MusicName{display: inline;font-size:100%;color:black;font-family:"微软雅黑","Microsoft Yahei",sans-serif;}
h2{color:yellow;text-shadow: 3px 3px 3px red;}
#text{width:190px;border: 0.25em solid #ddd;border-radius:1em;
    transition:width 1s;
    transition-timing-function:ease;
}
#text:focus{width:220px;}
#btn{text-align:center;display:inline;font-family:"微软雅黑","Microsoft Yahei",sans-serif;width:68px;font-size:90%;background-color: #DDD;border: 0.25em solid #999;border-radius:1em;}
#btn:hover{border-color:gold;}
#text:focus{border: 0.25em solid gold;background-color: #DDD;}
p{color:black;text-shadow: 2px 2px 2px white;}
table{width:90%;margin:0 auto;text-align:center;border-color:silver;border-radius:0.8em;border-style:inset; font-family: "微软雅黑","Microsoft Yahei",Arial,sans-serif;}
.achor{width:60%;height:auto;margin:0 auto;font-family:"微软雅黑","Microsoft Yahei",sans-serif;}
.achor ul:after{clear:both;width:0;height:0;content:",";display:block;visibility:hidden;}
#blog{display: block;float: left;width:130px;height:100%;}
#hexo{display: block;float: left;width:130px;height:100%;}
#wangyi{display: block;float: left;width:130px;height:100%;}

.achor{
//height :90px;
    font-family:"微软雅黑",sans-serif;
    font-size:1em;
    font-weight:bold;
    text-align:center;
    line-height:90px;
    margin:2em auto;

}

ul{
    list-style: none;
    font-size: 1em;
    width: 100%;
    margin: 0 auto;
    border: 1px none;
    padding: 0 3.36%;
}
.achor li{
    width: 130px;
    height: 90px;
    float: left;
    margin-left: 5px;
    /* border-left: 5px solid gold;*/
    border-radius: 1em;
    padding: 0 2.5px;
    display: block;



}

.achor li+li{
    border-left:1px solid gold;
}
li a{
    display: block;
    text-align: center;
    target:_blank;
}
li a:link{
    text-decoration:none;
    color: black;
}
li a:hover{
    text-decoration:none;
    color: red;
    background: yellow;
    border-radius: 1em;

}
#blog{display: block;float: left;width:130px;height:100%;background: #DDD;}
#hexo{display: block;float: left;width:130px;height:100%;background: #3399FF;}
#wangyi{display: block;float: left;width:130px;height:100%;background:#CCCC66;}
#home{display: block;float: left;width:130px;height:100%;background:#33FF00;}
#back a{
    display: block;
    width:10%;
    margin: 1em auto;
    text-align: center;
    background-color:#66FF00;
    border:2px solid #ddd;
    font-family:"微软雅黑","Microsoft Yahei",sans-serif;

}
#back a:link{
    text-decoration:none;
    color: black;
    border: 2px solid #999;
//background: #008040;
}
#back a:hover{
    text-decoration:none;
    color: red;
    background: yellow;
    border: 2px solid #999;
    border-radius:1em;

}
@media screen and (max-width:641px){
    td{word-break:break-all;}
    .achor ul li{margin:2px 40px 2px 18px;}

}


lyric.php

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>歌词显示</title>
<link href="./163music.css" rel="stylesheet">
</head>
<body>
<?php
session_start();
$a = $_GET['num'];
$lyric = $_SESSION['lyric' . $a];

echo '<pre>';
print_r($lyric['lyric']);
echo '<hr>';
print_r($lyric['tlyric']);
echo '</pre>';
?>
</body>
</html>

Meting.php (也有些多余的代码,有些用于QQ音乐的代码,不过在本项目中没有实现)

<?php

namespace Metowolf;
class Meting
{
    const VERSION = '1.5.7';
    public $raw;
    public $data;
    public $info;
    public $error;
    public $status;
    public $server;
    public $proxy = null;
    public $format = false;
    public $header;

    public function __construct($value = 'netease')
    {
        $this->site($value);
    }

    public function site($value)
    {
        $suppose = array('netease', 'tencent', 'xiami', 'kugou', 'baidu');
        $this->server = in_array($value, $suppose) ? $value : 'netease';
        $this->header = $this->curlset();
        return $this;
    }

    public function cookie($value)
    {
        $this->header['Cookie'] = $value;
        return $this;
    }

    public function format($value = true)
    {
        $this->format = $value;
        return $this;
    }

    public function proxy($value)
    {
        $this->proxy = $value;
        return $this;
    }

    private function exec($api)
    {
        if (isset($api['encode'])) {
            $api = call_user_func_array(array($this, $api['encode']), array($api));
        }
        if ($api['method'] == 'GET') {
            if (isset($api['body'])) {
                $api['url'] .= '?' . http_build_query($api['body']);
                $api['body'] = null;
            }
        }
        $this->curl($api['url'], $api['body']);
        if (!$this->format) {
            return $this->raw;
        }
        $this->data = $this->raw;
        if (isset($api['decode'])) {
            $this->data = call_user_func_array(array($this, $api['decode']), array($this->data));
        }
        if (isset($api['format'])) {
            $this->data = $this->clean($this->data, $api['format']);
        }
        return $this->data;
    }

    private function curl($url, $payload = null, $headerOnly = 0)
    {
        $header = array_map(function ($k, $v) {
            return $k . ': ' . $v;
        }, array_keys($this->header), $this->header);
        $curl = curl_init();
        if (!is_null($payload)) {
            curl_setopt($curl, CURLOPT_POST, 1);
            curl_setopt($curl, CURLOPT_POSTFIELDS, is_array($payload) ? http_build_query($payload) : $payload);
        }
        curl_setopt($curl, CURLOPT_HEADER, $headerOnly);
        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, $url);
        curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
        if ($this->proxy) {
            curl_setopt($curl, CURLOPT_PROXY, $this->proxy);
        }
        for ($i = 0; $i < 3; $i++) {
            $this->raw = curl_exec($curl);
            $this->info = curl_getinfo($curl);
            $this->error = curl_errno($curl);
            $this->status = $this->error ? curl_error($curl) : '';
            if (!$this->error) {
                break;
            }
        }
        curl_close($curl);
        return $this;
    }

    private function pickup($array, $rule)
    {
        $t = explode('.', $rule);
        foreach ($t as $vo) {
            if (!isset($array[$vo])) {
                return array();
            }
            $array = $array[$vo];
        }
        return $array;
    }

    private function clean($raw, $rule)
    {
        $raw = json_decode($raw, true);
        if (!empty($rule)) {
            $raw = $this->pickup($raw, $rule);
        }
        if (!isset($raw[0]) && count($raw)) {
            $raw = array($raw);
        }
        $result = array_map(array($this, 'format_' . $this->server), $raw);
        return json_encode($result);
    }

    public function search($keyword, $option = null)
    {
        switch ($this->server) {
            case 'netease':
                $api = array(
                    'method' => 'POST',
                    'url' => 'http://music.163.com/api/cloudsearch/pc',
                    'body' => array(
                        's' => $keyword,
                        'type' => isset($option['type']) ? $option['type'] : 1,
                        'limit' => isset($option['limit']) ? $option['limit'] : 30,
                        'total' => 'true',
                        'offset' => isset($option['page']) && isset($option['limit']) ? ($option['page'] - 1) * $option['limit'] : 0,
                    ),
                    'encode' => 'netease_AESCBC',
                    'format' => 'result.songs',
                );
                break;
            case 'tencent':
                $api = array(
                    'method' => 'GET',
                    'url' => 'https://c.y.qq.com/soso/fcgi-bin/client_search_cp',
                    'body' => array(
                        'format' => 'json',
                        'p' => isset($option['page']) ? $option['page'] : 1,
                        'n' => isset($option['limit']) ? $option['limit'] : 30,
                        'w' => $keyword,
                        'aggr' => 1,
                        'lossless' => 1,
                        'cr' => 1,
                        'new_json' => 1,
                    ),
                    'format' => 'data.song.list',
                );
                break;
        }
        return $this->exec($api);
    }

    public function song($id)
    {
        switch ($this->server) {
            case 'netease':
                $api = array(
                    'method' => 'POST',
                    'url' => 'http://music.163.com/api/v3/song/detail/',
                    'body' => array(
                        'c' => '[{"id":' . $id . ',"v":0}]',
                    ),
                    'encode' => 'netease_AESCBC',
                    'format' => 'songs',
                );
                break;
            case 'tencent':
                $api = array(
                    'method' => 'GET',
                    'url' => 'https://c.y.qq.com/v8/fcg-bin/fcg_play_single_song.fcg',
                    'body' => array(
                        'songmid' => $id,
                        'platform' => 'yqq',
                        'format' => 'json',
                    ),
                    'format' => 'data',
                );
                break;
        }
        return $this->exec($api);
    }

    public function album($id)
    {
        switch ($this->server) {
            case 'netease':
                $api = array(
                    'method' => 'POST',
                    'url' => 'http://music.163.com/api/v1/album/' . $id,
                    'body' => array(
                        'total' => 'true',
                        'offset' => '0',
                        'id' => $id,
                        'limit' => '1000',
                        'ext' => 'true',
                        'private_cloud' => 'true',
                    ),
                    'encode' => 'netease_AESCBC',
                    'format' => 'songs',
                );
                break;
            case 'tencent':
                $api = array(
                    'method' => 'GET',
                    'url' => 'https://c.y.qq.com/v8/fcg-bin/fcg_v8_album_detail_cp.fcg',
                    'body' => array(
                        'albummid' => $id,
                        'platform' => 'mac',
                        'format' => 'json',
                        'newsong' => 1,
                    ),
                    'format' => 'data.getSongInfo',
                );
                break;
        }
        return $this->exec($api);
    }


    public function url($id, $br = 320)
    {
        switch ($this->server) {
            case 'netease':
                $api = array(
                    'method' => 'POST',
                    'url' => 'http://music.163.com/api/song/enhance/player/url',
                    'body' => array(
                        'ids' => array($id),
                        'br' => $br * 1000,
                    ),
                    'encode' => 'netease_AESCBC',
                    'decode' => 'netease_url',
                );
                break;
            case 'tencent':
                $api = array(
                    'method' => 'GET',
                    'url' => 'https://c.y.qq.com/v8/fcg-bin/fcg_play_single_song.fcg',
                    'body' => array(
                        'songmid' => $id,
                        'platform' => 'yqq',
                        'format' => 'json',
                    ),
                    'decode' => 'tencent_url',
                );
                break;
        }
        $this->temp['br'] = $br;
        return $this->exec($api);
    }

    public function lyric($id)
    {
        switch ($this->server) {
            case 'netease':
                $api = array(
                    'method' => 'POST',
                    'url' => 'http://music.163.com/api/song/lyric',
                    'body' => array(
                        'id' => $id,
                        'os' => 'linux',
                        'lv' => -1,
                        'kv' => -1,
                        'tv' => -1,
                    ),
                    'encode' => 'netease_AESCBC',
                    'decode' => 'netease_lyric',
                );
                break;
            case 'tencent':
                $api = array(
                    'method' => 'GET',
                    'url' => 'https://c.y.qq.com/lyric/fcgi-bin/fcg_query_lyric_new.fcg',
                    'body' => array(
                        'songmid' => $id,
                        'g_tk' => '5381',
                    ),
                    'decode' => 'tencent_lyric',
                );
                break;

        }
        return $this->exec($api);
    }

    public function pic($id, $size = 300)
    {
// 这里的id是图片id pic_id ,不是歌曲id
        switch ($this->server) {
            case 'netease':
                $url = 'https://p3.music.126.net/' . $this->netease_encryptId($id) . '/' . $id . '.jpg?param=' . $size . 'y' . $size;
                echo $this->netease_encryptId($id);
                echo $id;
                break;
            case 'tencent':
                $url = 'https://y.gtimg.cn/music/photo_new/T002R' . $size . 'x' . $size . 'M000' . $id . '.jpg?max_age=2592000';
                break;
        }
        return json_encode(array('url' => $url));
    }

    private function curlset()
    {
        switch ($this->server) {
            case 'netease':
                return array(
                    'Referer' => 'https://music.163.com/',
                    'Cookie' => 'appver=1.5.9; os=osx; __remember_me=true; osver=%E7%89%88%E6%9C%AC%2010.13.5%EF%BC%88%E7%89%88%E5%8F%B7%2017F77%EF%BC%89;',
                    'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) AppleWebKit/605.1.15 (KHTML, like Gecko)',
                    'X-Real-IP' => long2ip(mt_rand(1884815360, 1884890111)),
                    'Accept' => '*/*',
                    'Accept-Language' => 'zh-CN,zh;q=0.8,gl;q=0.6,zh-TW;q=0.4',
                    'Connection' => 'keep-alive',
                    'Content-Type' => 'application/x-www-form-urlencoded',
                );
            case 'tencent':
                return array(
                    'Referer' => 'http://y.qq.com',
                    'Cookie' => 'pgv_pvi=22038528; pgv_si=s3156287488; pgv_pvid=5535248600; yplayer_open=1; ts_last=y.qq.com/portal/player.html; ts_uid=4847550686; yq_index=0; qqmusic_fromtag=66; player_exist=1',
                    'User-Agent' => 'QQ%E9%9F%B3%E4%B9%90/54409 CFNetwork/901.1 Darwin/17.6.0 (x86_64)',
                    'Accept' => '*/*',
                    'Accept-Language' => 'zh-CN,zh;q=0.8,gl;q=0.6,zh-TW;q=0.4',
                    'Connection' => 'keep-alive',
                    'Content-Type' => 'application/x-www-form-urlencoded',
                );
        }
    }

    private function getRandomHex($length)
    {
        if (function_exists('random_bytes')) {
            return bin2hex(random_bytes($length / 2));
        }
        if (function_exists('mcrypt_create_iv')) {
            return bin2hex(mcrypt_create_iv($length / 2, MCRYPT_DEV_URANDOM));
        }
        if (function_exists('openssl_random_pseudo_bytes')) {
            return bin2hex(openssl_random_pseudo_bytes($length / 2));
        }
    }

    private function bchexdec($hex)
    {
        $dec = 0;
        $len = strlen($hex);
        for ($i = 1; $i <= $len; $i++) {
            $dec = bcadd($dec, bcmul(strval(hexdec($hex[$i - 1])), bcpow('16', strval($len - $i))));
        }
        return $dec;
    }

    private function bcdechex($dec)
    {
        $hex = '';
        do {
            $last = bcmod($dec, 16);
            $hex = dechex($last) . $hex;
            $dec = bcdiv(bcsub($dec, $last), 16);
        } while ($dec > 0);
        return $hex;
    }

    private function str2hex($string)
    {
        $hex = '';
        for ($i = 0; $i < strlen($string); $i++) {
            $ord = ord($string[$i]);
            $hexCode = dechex($ord);
            $hex .= substr('0' . $hexCode, -2);
        }
        return $hex;
    }

    private function netease_AESCBC($api)
    {
        $modulus = '157794750267131502212476817800345498121872783333389747424011531025366277535262539913701806290766479189477533597854989606803194253978660329941980786072432806427833685472618792592200595694346872951301770580765135349259590167490536138082469680638514416594216629258349130257685001248172188325316586707301643237607';
        $pubkey = '65537';
        $nonce = '0CoJUm6Qyw8W8jud';
        $vi = '0102030405060708';
        if (extension_loaded('bcmath')) {
            $skey = $this->getRandomHex(16);
        } else {
            $skey = 'B3v3kH4vRPWRJFfH';
        }
        $body = json_encode($api['body']);
        if (function_exists('openssl_encrypt')) {
            $body = openssl_encrypt($body, 'aes-128-cbc', $nonce, false, $vi);
            $body = openssl_encrypt($body, 'aes-128-cbc', $skey, false, $vi);
        } else {
            $pad = 16 - (strlen($body) % 16);
            $body = base64_encode(openssl_encrypt(MCRYPT_RIJNDAEL_128, $nonce, $body . str_repeat(chr($pad), $pad), MCRYPT_MODE_CBC, $vi));
            $pad = 16 - (strlen($body) % 16);
            $body = base64_encode(openssl_encrypt(MCRYPT_RIJNDAEL_128, $skey, $body . str_repeat(chr($pad), $pad), MCRYPT_MODE_CBC, $vi));
        }
        if (extension_loaded('bcmath')) {
            $skey = strrev(utf8_encode($skey));
            $skey = $this->bchexdec($this->str2hex($skey));
            $skey = bcpowmod($skey, $pubkey, $modulus);
            $skey = $this->bcdechex($skey);
            $skey = str_pad($skey, 256, '0', STR_PAD_LEFT);
        } else {
            $skey = '85302b818aea19b68db899c25dac229412d9bba9b3fcfe4f714dc016bc1686fc446a08844b1f8327fd9cb623cc189be00c5a365ac835e93d4858ee66f43fdc59e32aaed3ef24f0675d70172ef688d376a4807228c55583fe5bac647d10ecef15220feef61477c28cae8406f6f9896ed329d6db9f88757e31848a6c2ce2f94308';
        }
        $api['url'] = str_replace('/api/', '/weapi/', $api['url']);
        $api['body'] = array(
            'params' => $body,
            'encSecKey' => $skey,
        );
        return $api;
    }


    private function netease_lyric($result)
    {
        $result = json_decode($result, true);
        $data = array(
            'lyric' => isset($result['lrc']['lyric']) ? $result['lrc']['lyric'] : '',
            'tlyric' => isset($result['tlyric']['lyric']) ? $result['tlyric']['lyric'] : '',
        );
        return json_encode($data);
    }

    private function format_netease($data)
    {
        $result = array(
            'id' => $data['id'],
            'name' => $data['name'],
            'artist' => array(),
            'album' => $data['al']['name'],
            'pic_id' => isset($data['al']['pic_str']) ? $data['al']['pic_str'] : $data['al']['pic'],
            'url_id' => $data['id'],
            'lyric_id' => $data['id'],
            'source' => 'netease',
        );
        if (isset($data['al']['picUrl'])) {
            preg_match('/\/(\d+)\./', $data['al']['picUrl'], $match);
            $result['pic_id'] = $match[1];
        }
        foreach ($data['ar'] as $vo) {
            $result['artist'][] = $vo['name'];
        }
        return $result;
    }

}

资源链接


参考文章

  • 4
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

覅乆

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值