首先要獲取hash值是歌曲名的hash值
搜索歌曲接口
https://songsearch.kugou.com/song_search_v2?keyword=numb 關鍵詞 得到一個lists列表數據
歌曲的hash值 FileHash 和文件名
第二 獲取歌曲播放地址接口
mid不知道是什么意思 猜測是瀏覽器的編碼還是什么鬼 以下是示例接口
https://wwwapi.kugou.com/yy/index.php?r=play/getdata&hash=A9DC61CBFBC27F1F0BF63482D9469438&mid=407a9697947211b828f908950a4460ec
https://wwwapi.kugou.com/yy/index.php?r=play/getdata&hash=29AFE0B705056DE252ED0E5A6E4A5EE2&mid=407a9697947211b828f908950a4460ec
得到播放地址 play_url 此為歌曲播放地址
第三下載歌曲 可以替換名字
以下為測試代碼 使用第三方庫
```
composer require curl/curl
```
```
<?php
namespace app\index\controller;
use Curl\Curl;
use think\Controller;
use think\Request;
class Index extends Controller
{
public function test(Request $request)
{
$keyword = $request->param('keyword');
$url = "https://songsearch.kugou.com/song_search_v2";
$curl = new Curl();
$arr = ['keyword' => $keyword];
$curl->get($url,$arr);
$curl->close();
$result = $curl->response;
$res = json_decode($result, true);
$lists = $res['data']['lists'];
$arr = [];
foreach ($lists as $k => $v) { // 過濾數據
// $arr[$k]['name'] = $v['SongName'];
// $arr[$k]['hash'] = $v['FileHash'];
$this->getPlayUrl($v['FileHash'], $v['SongName']);
}
// 是否存數據庫 待定
// return json($arr);
}
public function getPlayUrl($hash, $song_name)
{
// $url = "https://wwwapi.kugou.com/yy/index.php?r=play/getdata&mid=407a9697947211b828f908950a4460ec&hash=A8136351BE3DA7D077E95B976EB723CB";
$url = "https://wwwapi.kugou.com/yy/index.php";
$curl = new Curl();
$curl->setOpt(CURLOPT_RETURNTRANSFER, FALSE);
// https接口需設置這個為false
$curl->setOpt(CURLOPT_SSL_VERIFYPEER, FALSE);
// https接口需設置這個為false
$curl->setOpt(CURLOPT_SSL_VERIFYHOST, FALSE);
// https接口需設置這個為false
$curl->setOpt(CURLOPT_RETURNTRANSFER, 1);
// 只獲取不顯示
$arr = [
'r' =>'play/getdata',
'mid' =>'407a9697947211b828f908950a4460ec',
'hash' =>$hash,
];
$curl->get($url,$arr);
$curl->close();
$result = $curl->response;
$res = json_decode($result, true);
$play_url = $res['data']['play_url'];// 音樂播放地址
$this->down($play_url, $song_name);
}
public function down($playUrl, $song_name)
{
$ch = new Curl();
$curl->setOpt(CURLOPT_RETURNTRANSFER, FALSE);
// https接口需設置這個為false
$curl->setOpt(CURLOPT_SSL_VERIFYPEER, FALSE);
// https接口需設置這個為false
$curl->setOpt(CURLOPT_SSL_VERIFYHOST, FALSE);
// https接口需設置這個為false
$curl->setOpt(CURLOPT_RETURNTRANSFER, 1);
// 只獲取不顯示
$ch->get($playUrl);
$ch->close();
// 打開文件夾
$path = '/www/wwwroot/www.kg.com/public/';
// 寫入文件處理
$file_name = $song_name . '.mp3';
$fp = fopen($path . $file_name, 'w+');
fwrite($fp, $ch->response);
}
}
```
- php ping 地址
- python調用php腳本和sh調用php腳本
- php隨機字符串
- redis操作
- 公共頁面文件
- 登錄
- 文章
- 文章管理
- 文章分類
- 圖片
- 圖片分類
- 圖片管理
- 配置文件
- ueditor配置遠程上傳
- django
- 安裝
- jinja2模板標簽
- 虛擬機
- centos寶塔面板安裝
- mysql主從搭建
- 虛擬機安裝centos7
- 2
- 主從復制
- uni-app
- 更新
- 直播簡單代碼
- 搞笑的注釋代碼
- jwt
- centos以太坊環境搭建
- thinkphp5.1下的redis使用
- redis的安裝
- tp5.1中使用
- tp5.1下載酷狗音樂
- 跨域
- tp5.1導出數據庫到excel
- 鉤子和行為
- 支付寶
- 申請支付寶app接入
- 視頻播放
- 模塊安裝
- 推流配置
- pc端網頁代碼
- srs
- 后臺布局
- 基礎布局文件
- 左邊
- 頭部
- css特效代碼
- 圖片旋轉
- 圖片放大
- 頂部
- 列表頁
- 更新數據表單頁
- 模型獲取器
- 上傳圖片
- mysql
- 一些常用
- 遠程授權
- 數據庫常用命令
- 忘記密碼
- webpack
- 一些亂七八糟的東西
- linux后臺運行腳本過大處理辦法
- sublime插件
- linux svn安裝
- 工具
- 查看進程
- 獲取微信公眾號文章
- 爬取微信公眾號文章
- 清空nohup
- 服務器上跨域配置
- sql語句生成orm模型寫法的工具
- centos換阿里源
- linux一些日志操作
- zsh