Qt/C++ 網易雲api 線上播放音樂
之前用了一個私人的api,沒用到1個月就沒了,實在煩惱~無意間通過wireshark抓到網易雲音樂,然後解析了一下就Okay。解包裡有mp3url,就okay了。然後通過載入就okay。
至於歌詞部分是被加密了的。。實在找不到方法解密。就又呼叫了一個酷狗音樂的歌詞api。
一.請求搜尋歌曲:
QNetworkAccessManager*manger=newQNetworkAccessManager;
QNetworkRequest*request=newQNetworkRequest;
request->setRawHeader("Cookie","os=pc");
request->setRawHeader("Host","music.163.com");
request->setRawHeader("MUSIC_U","5339640232");
request->setRawHeader("Referer",);
manger->post(*request,"offset=0&total=true&limit=100&type=1&s="+byt);
connect(manger,SIGNAL(finished(QNetworkReply*)),this,SLOT(workfinished(QNetworkReply*)));
二.處理返回內容:
QJsonDocument doc=QJsonDocument::fromJson(byt);
QJsonObject obj0=doc.object();
QJsonObject obj1=obj0.value("result").toObject();
QJsonArray arry=obj1.value("songs").toArray();
int arrycount=arry.count();
for(int i=0;i<arrycount;i++)
{
QJsonObject obj2=arry.at(i).toObject();
QString songname=obj2.value("name").toString();//獲取音樂名字
QJsonArray arry1=obj2.value("artists").toArray();
QJsonObject obj3=arry1.at(0).toObject();
QString author= obj3.value("name").toString();//獲取歌手名字
connect(addnetplaybtn,SIGNAL(clicked()),this,SLOT(addplaynetListslot()));
connect(downbtn,SIGNAL(clicked()),this,SLOT(downloadnetsong()));
}
powered by:小烏龜在大烏龜背上