From f5882e7d3294549381ac8689bc79e59599fe7c99 Mon Sep 17 00:00:00 2001 From: overwriter Date: Sat, 13 Jan 2024 18:02:37 +0800 Subject: [PATCH 1/8] =?UTF-8?q?feat:=E5=A2=9E=E5=8A=A0=E9=83=A8=E5=88=86?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3feat:=E5=A2=9E=E5=8A=A0=E9=83=A8=E5=88=86?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ApiServer/main.cpp | 6 +++--- CApi/capi.cpp | 8 ++++---- QCloudMusicApi/module.cpp | 25 +++++++++++++++++++++++-- QCloudMusicApi/module.h | 6 ++++++ Test/config.json | 3 +++ 5 files changed, 39 insertions(+), 9 deletions(-) diff --git a/ApiServer/main.cpp b/ApiServer/main.cpp index 3c97d20..c121626 100644 --- a/ApiServer/main.cpp +++ b/ApiServer/main.cpp @@ -1,6 +1,4 @@ -#include "../QCloudMusicApi/module.h" - -#include +#include #include #include #include @@ -8,6 +6,8 @@ #include #include +#include "../QCloudMusicApi/module.h" + int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); diff --git a/CApi/capi.cpp b/CApi/capi.cpp index 85255bf..fd262d3 100644 --- a/CApi/capi.cpp +++ b/CApi/capi.cpp @@ -1,12 +1,12 @@ -#include "capi.h" -#include "../QCloudMusicApi/module.h" - -#include +#include #include #include #include #include +#include "capi.h" +#include "../QCloudMusicApi/module.h" + CAPI_EXPORT char* invoke(char* funName, char* value) { QString result; int argc = 1; diff --git a/QCloudMusicApi/module.cpp b/QCloudMusicApi/module.cpp index e256531..f6b41ea 100644 --- a/QCloudMusicApi/module.cpp +++ b/QCloudMusicApi/module.cpp @@ -1,5 +1,4 @@ -#include -#include +#include #include #include #include @@ -663,6 +662,28 @@ APICPP(check_music) { } } +// 云盘歌曲信息匹配纠正 +APICPP(cloud_match) { + QVariantMap cookie = query["cookie"].toMap(); + cookie["os"] = "ios"; + cookie["appver"] = "8.10.90"; + query["cookie"] = cookie; + const QVariantMap data { + { "userId", query["uid"] }, + { "songId", query["sid"] }, + { "adjustSongId", query["asid"] } + }; + return request( + POST, + "https://music.163.com/api/cloud/user/song/match", + data, + { + { "crypto", "weapi" }, + _PARAM + } + ); +} + // 搜索 APICPP(cloudsearch) { const QVariantMap data { diff --git a/QCloudMusicApi/module.h b/QCloudMusicApi/module.h index a6268e5..215c109 100644 --- a/QCloudMusicApi/module.h +++ b/QCloudMusicApi/module.h @@ -137,6 +137,12 @@ class QCLOUDMUSICAPI_EXPORT NeteaseCloudMusicApi: public QObject { // 歌曲可用性 APIH(check_music) + // 云盘歌曲信息匹配纠正 + APIH(cloud_match) + + // 云盘上传 + // APIH(cloud) + // 搜索 APIH(cloudsearch) diff --git a/Test/config.json b/Test/config.json index 7258371..384a551 100644 --- a/Test/config.json +++ b/Test/config.json @@ -208,5 +208,8 @@ }, "batch": { "/api/v2/banner/get": "{\"clientType\":\"pc\"}" + }, + "check_music": { + "id": "2058263032" } } \ No newline at end of file From e5b0aae80662f5fe30a9b66f5aee3fa4a2e61115 Mon Sep 17 00:00:00 2001 From: overwriter Date: Sat, 13 Jan 2024 18:50:42 +0800 Subject: [PATCH 2/8] =?UTF-8?q?feat:=E5=A2=9E=E5=8A=A0=E9=83=A8=E5=88=86?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- QCloudMusicApi/module.cpp | 44 ++++++++++++++++++++++++++++++++++++ QCloudMusicApi/module.h | 9 +++++--- QCloudMusicApi/util/config.h | 3 +-- QCloudMusicApi/util/crypto.h | 1 - QCloudMusicApi/util/index.h | 1 + Test/config.json | 9 ++++++++ 6 files changed, 61 insertions(+), 6 deletions(-) diff --git a/QCloudMusicApi/module.cpp b/QCloudMusicApi/module.cpp index f6b41ea..61afbbf 100644 --- a/QCloudMusicApi/module.cpp +++ b/QCloudMusicApi/module.cpp @@ -8,6 +8,7 @@ #include #include +#include "util/config.h" #include "request.h" #include "module.h" @@ -767,6 +768,49 @@ APICPP(comment_event) { ); } +// 楼层评论 +APICPP(comment_floor) { + query["type"] = Config::resourceTypeMap[query["type"].toString()]; + const QVariantMap data { + { "parentCommentId", query["parentCommentId"] }, + { "threadId", query["type"].toString() + query["id"].toString() }, + { "time", query.value("time", -1) }, + { "limit", query.value("limit", 20) } + }; + return request( + POST, + "https://music.163.com/api/resource/comment/floor/get", + data, + { + { "crypto", "weapi" }, + _PARAM + } + ); +} + +// 热门评论 +APICPP(comment_hot) { + QVariantMap cookie = query["cookie"].toMap(); + cookie["os"] = "pc"; + query["cookie"] = cookie; + query["type"] = Config::resourceTypeMap[query["type"].toString()]; + const QVariantMap data { + { "rid", query["id"] }, + { "limit", query.value("limit", 20) }, + { "offset", query.value("offset", 0) }, + { "beforeTime", query.value("before", 0) } + }; + return request( + POST, + "https://music.163.com/weapi/v1/resource/hotcomments/" + query["type"].toString() + query["id"].toString(), + data, + { + { "crypto", "weapi" }, + _PARAM + } + ); +} + // 歌曲评论 APICPP(comment_music) { QVariantMap cookie = query["cookie"].toMap(); diff --git a/QCloudMusicApi/module.h b/QCloudMusicApi/module.h index 215c109..a3d408f 100644 --- a/QCloudMusicApi/module.h +++ b/QCloudMusicApi/module.h @@ -2,9 +2,6 @@ #define MODULE_H #include -#include -#include -#include #if defined(QCLOUDMUSICAPI_LIBRARY) # define QCLOUDMUSICAPI_EXPORT Q_DECL_EXPORT @@ -155,6 +152,12 @@ class QCLOUDMUSICAPI_EXPORT NeteaseCloudMusicApi: public QObject { // 获取动态评论 APIH(comment_event) + // 楼层评论 + APIH(comment_floor) + + // 热门评论 + APIH(comment_hot) + // 歌曲评论 APIH(comment_music) diff --git a/QCloudMusicApi/util/config.h b/QCloudMusicApi/util/config.h index ca59bc9..67a7469 100644 --- a/QCloudMusicApi/util/config.h +++ b/QCloudMusicApi/util/config.h @@ -1,13 +1,12 @@ #ifndef CONFIG_H #define CONFIG_H -#include #include namespace Config { const static QString anonymous_token = QStringLiteral("de91e1f8119d32e01cc73efcb82c0a30c9137e8d4f88dbf5e3d7bf3f28998f21add2bc8204eeee5e56c0bbb8743574b46ca2c10c35dc172199bef9bf4d60ecdeab066bb4dc737d1c3324751bcc9aaf44c3061cd18d77b7a0"); -const static QVariantMap resourceTypeMap { +const static QMap resourceTypeMap { { "0", "R_SO_4_" }, { "1", "R_MV_5_" }, { "2", "A_PL_0_" }, diff --git a/QCloudMusicApi/util/crypto.h b/QCloudMusicApi/util/crypto.h index 9127246..2c2094e 100644 --- a/QCloudMusicApi/util/crypto.h +++ b/QCloudMusicApi/util/crypto.h @@ -1,7 +1,6 @@ #ifndef CRYPTO_H #define CRYPTO_H -#include #include #include #include diff --git a/QCloudMusicApi/util/index.h b/QCloudMusicApi/util/index.h index c4b1082..9de4261 100644 --- a/QCloudMusicApi/util/index.h +++ b/QCloudMusicApi/util/index.h @@ -1,5 +1,6 @@ #ifndef INDEX_H #define INDEX_H + #include #include diff --git a/Test/config.json b/Test/config.json index 384a551..0756153 100644 --- a/Test/config.json +++ b/Test/config.json @@ -211,5 +211,14 @@ }, "check_music": { "id": "2058263032" + }, + "comment_floor": { + "parentCommentId": "1438569889", + "id": "29764564", + "type": 0 + }, + "comment_hot": { + "id": "2058263032", + "type": "0" } } \ No newline at end of file From c2247331378c9842629985773cfbf6370aab52d2 Mon Sep 17 00:00:00 2001 From: overwriter Date: Sat, 13 Jan 2024 21:07:20 +0800 Subject: [PATCH 3/8] =?UTF-8?q?feat:=E6=B5=8B=E8=AF=95=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0aes=E5=8A=A0=E5=AF=86=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=EF=BC=9Bcookie=E8=BD=AC=E4=B8=BAQVariantMap=E5=AD=98=E5=82=A8?= =?UTF-8?q?=E8=80=8C=E4=B8=8D=E6=98=AFQString=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- QCloudMusicApi/request.cpp | 5 +--- QCloudMusicApi/request.h | 3 +-- Test/main.cpp | 11 ++++++++- Test/mainwindow.cpp | 47 ++++++++++++++++++++++++-------------- Test/mainwindow.h | 21 +++++++++++++---- 5 files changed, 59 insertions(+), 28 deletions(-) diff --git a/QCloudMusicApi/request.cpp b/QCloudMusicApi/request.cpp index 9b39adb..472ed9a 100644 --- a/QCloudMusicApi/request.cpp +++ b/QCloudMusicApi/request.cpp @@ -1,6 +1,4 @@ -#include -#include -#include +#include #include #include #include @@ -10,7 +8,6 @@ #include #include #include -#include #include #include #include diff --git a/QCloudMusicApi/request.h b/QCloudMusicApi/request.h index 054702b..c6c4d25 100644 --- a/QCloudMusicApi/request.h +++ b/QCloudMusicApi/request.h @@ -1,5 +1,4 @@ -#include -#include +#include namespace Request { diff --git a/Test/main.cpp b/Test/main.cpp index fd3e533..92aee3d 100644 --- a/Test/main.cpp +++ b/Test/main.cpp @@ -1,10 +1,19 @@ #include "mainwindow.h" - +#include "../QCloudMusicApi/util/crypto.h" #include int main(int argc, char *argv[]) { QApplication a(argc, argv); + []() {//测试aes加解密 + QString body = "This is a text"; + auto bodyEncrypt = Crypto::aesEncrypt(body.toUtf8(), EVP_aes_128_ecb, Crypto::eapiKey, ""); + auto bodyDecrypt = Crypto::aesDecrypt(bodyEncrypt, EVP_aes_128_ecb, Crypto::eapiKey, ""); + qDebug() << body; + qDebug() << bodyEncrypt; + qDebug() << bodyDecrypt; + qDebug() << (body == bodyDecrypt); + }(); MainWindow w; w.show(); return a.exec(); diff --git a/Test/mainwindow.cpp b/Test/mainwindow.cpp index 58b5197..81c2a33 100644 --- a/Test/mainwindow.cpp +++ b/Test/mainwindow.cpp @@ -24,33 +24,49 @@ MainWindow::~MainWindow() delete ui; } -void MainWindow::updateCookie(QVariantMap ret) { +void MainWindow::updateCookie(const QVariantMap ret) { auto newMap = Index::stringToMap(ret["cookie"].toString()); - auto map = Index::stringToMap(cookie); + cookie = Index::mergeMap(cookie, newMap);; if (ret["body"].toMap()["token"].isValid()) { - map["MUSIC_A"] = ret["body"].toMap()["token"]; + cookie["MUSIC_A"] = ret["body"].toMap()["token"]; } - Index::mergeMap(map, newMap); - cookie = Index::mapToString(map); } -QVariantMap MainWindow::invoke(QString funName, QVariantMap arg) { - arg["cookie"] = arg.value("cookie", cookie); - cookie = arg["cookie"].toString() + " SameSite=None; Secure"; +QVariantMap MainWindow::invoke(const QString funName, const QVariantMap arg) { QVariantMap ret; QMetaObject::invokeMethod(&api, funName.toUtf8() , Qt::DirectConnection , Q_RETURN_ARG(QVariantMap, ret) , Q_ARG(QVariantMap, arg)); - this->updateCookie(ret); return ret; } void MainWindow::on_pushButton_clicked() { - ui->textEdit_2->setText(QJsonDocument::fromJson(ui->textEdit_2->toPlainText().toUtf8()).toJson(QJsonDocument::Indented)); + auto JsonFormat = ui->checkBox->isChecked() ? QJsonDocument::Indented : QJsonDocument::Compact; + ui->textEdit_2->setText(QJsonDocument::fromJson(ui->textEdit_2->toPlainText().toUtf8()).toJson(JsonFormat)); + QVariantMap arg = QJsonDocument::fromJson(ui->textEdit_2->toPlainText().toUtf8()).toVariant().toMap(); + + //Api只能处理map类型的cookie + if(arg.contains("cookie")) { + //如果传入新的cookie,替换原有的cookie + if(arg["cookie"].userType() == QMetaType::QVariantMap) { + cookie = arg["cookie"].toMap()/* + " SameSite=None; Secure"*/; + } + else if(arg["cookie"].userType() == QMetaType::QString) { + cookie = Index::stringToMap(arg["cookie"].toString()); + } + } + else { + //使用存储的cookie + arg["cookie"] = arg.value("cookie", cookie); + } + QVariantMap ret = this->invoke(ui->comboBox->currentText(), arg); + + this->updateCookie(ret); + if(ui->checkBox->isChecked()) { ui->textEdit->setText(QJsonDocument::fromVariant(ret).toJson(QJsonDocument::Indented)); } @@ -65,20 +81,17 @@ void MainWindow::on_comboBox_currentTextChanged(const QString &arg1) QFile file(":/config.json"); file.open(QIODevice::ReadOnly); auto config = QJsonDocument::fromJson(file.readAll()); + auto JsonFormat = ui->checkBox->isChecked() ? QJsonDocument::Indented : QJsonDocument::Compact; ui->textEdit_2->setText( QJsonDocument(config[arg1].toObject()) - .toJson(QJsonDocument::Indented) + .toJson(JsonFormat) ); } void MainWindow::on_checkBox_stateChanged(int arg1) { - if(arg1) { - ui->textEdit->setText(QJsonDocument::fromJson(ui->textEdit->toPlainText().toUtf8()).toJson(QJsonDocument::Indented)); - } - else { - ui->textEdit->setText(QJsonDocument::fromJson(ui->textEdit->toPlainText().toUtf8()).toJson(QJsonDocument::Compact)); - } + auto JsonFormat = arg1 ? QJsonDocument::Indented : QJsonDocument::Compact; + ui->textEdit->setText(QJsonDocument::fromJson(ui->textEdit->toPlainText().toUtf8()).toJson(JsonFormat)); } diff --git a/Test/mainwindow.h b/Test/mainwindow.h index 4d1ad4f..ae44328 100644 --- a/Test/mainwindow.h +++ b/Test/mainwindow.h @@ -26,11 +26,24 @@ private slots: void on_checkBox_stateChanged(int arg1); private: + + /** + * @brief 反射调用API中的方法 + * @param funName 函数名称 + * @param arg 参数 + * @return QVariantMap 返回的数据 + */ + QVariantMap invoke(const QString funName, const QVariantMap arg); + + /** + * @brief 更新储存的cookie + * @param ret Api返回的数据 + * @return void + */ + void updateCookie(const QVariantMap ret); + Ui::MainWindow *ui; NeteaseCloudMusicApi api; - - QVariantMap invoke(QString funName, QVariantMap arg); - void updateCookie(QVariantMap ret); - QString cookie = ""; + QVariantMap cookie; }; #endif // MAINWINDOW_H From bd8e278a00dbceae5e096aff721dd2314c47cf02 Mon Sep 17 00:00:00 2001 From: overwriter Date: Sat, 13 Jan 2024 21:12:50 +0800 Subject: [PATCH 4/8] =?UTF-8?q?feat:=E8=A1=A5=E5=85=85=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Test/main.cpp | 11 +---------- Test/mainwindow.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Test/main.cpp b/Test/main.cpp index 92aee3d..fd3e533 100644 --- a/Test/main.cpp +++ b/Test/main.cpp @@ -1,19 +1,10 @@ #include "mainwindow.h" -#include "../QCloudMusicApi/util/crypto.h" + #include int main(int argc, char *argv[]) { QApplication a(argc, argv); - []() {//测试aes加解密 - QString body = "This is a text"; - auto bodyEncrypt = Crypto::aesEncrypt(body.toUtf8(), EVP_aes_128_ecb, Crypto::eapiKey, ""); - auto bodyDecrypt = Crypto::aesDecrypt(bodyEncrypt, EVP_aes_128_ecb, Crypto::eapiKey, ""); - qDebug() << body; - qDebug() << bodyEncrypt; - qDebug() << bodyDecrypt; - qDebug() << (body == bodyDecrypt); - }(); MainWindow w; w.show(); return a.exec(); diff --git a/Test/mainwindow.cpp b/Test/mainwindow.cpp index 81c2a33..e329b73 100644 --- a/Test/mainwindow.cpp +++ b/Test/mainwindow.cpp @@ -8,6 +8,7 @@ #include "../QCloudMusicApi/module.h" #include "../QCloudMusicApi/util/index.h" +#include "../QCloudMusicApi/util/crypto.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) @@ -17,6 +18,15 @@ MainWindow::MainWindow(QWidget *parent) for(int i = QObject().metaObject()->methodCount(); i < api.metaObject()->methodCount(); i++) { ui->comboBox->addItem(api.metaObject()->method(i).name()); } + []() {//测试aes加解密 + QString body = "This is a text"; + auto bodyEncrypt = Crypto::aesEncrypt(body.toUtf8(), EVP_aes_128_ecb, Crypto::eapiKey, ""); + auto bodyDecrypt = Crypto::aesDecrypt(bodyEncrypt, EVP_aes_128_ecb, Crypto::eapiKey, ""); + qDebug() << body; + qDebug() << bodyEncrypt; + qDebug() << bodyDecrypt; + qDebug() << (body == bodyDecrypt); + }(); } MainWindow::~MainWindow() From 79f015420a68185863932b28918cd4fa63ab5816 Mon Sep 17 00:00:00 2001 From: overwriter Date: Sat, 13 Jan 2024 21:15:31 +0800 Subject: [PATCH 5/8] =?UTF-8?q?feat:=E8=A1=A5=E5=85=85=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Test/mainwindow.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Test/mainwindow.cpp b/Test/mainwindow.cpp index e329b73..b844b85 100644 --- a/Test/mainwindow.cpp +++ b/Test/mainwindow.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include "../QCloudMusicApi/module.h" #include "../QCloudMusicApi/util/index.h" From e73cf6408d4b7b4e7b243dcc61c9e705da2d084d Mon Sep 17 00:00:00 2001 From: overwriter Date: Sat, 20 Jan 2024 20:51:32 +0800 Subject: [PATCH 6/8] =?UTF-8?q?feat:=E5=A2=9E=E5=8A=A0=E9=83=A8=E5=88=86?= =?UTF-8?q?=E8=AF=84=E8=AE=BA=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- QCloudMusicApi/module.cpp | 145 ++++++++++++++++++++++++++++++++++++-- QCloudMusicApi/module.h | 12 ++++ Test/config.json | 24 +++++++ Test/mainwindow.cpp | 17 +++-- Test/mainwindow.h | 6 +- 5 files changed, 191 insertions(+), 13 deletions(-) diff --git a/QCloudMusicApi/module.cpp b/QCloudMusicApi/module.cpp index 61afbbf..e3f4b54 100644 --- a/QCloudMusicApi/module.cpp +++ b/QCloudMusicApi/module.cpp @@ -22,9 +22,10 @@ const QVariantMap NeteaseCloudMusicApi::FUNCNAME(QVariantMap query) { "proxy", query["proxy"] }, \ { "realIP", query["realIP"] } \ -const static auto request = Request::createRequest; -const static auto POST = QNetworkAccessManager::PostOperation; -const static auto GET = QNetworkAccessManager::GetOperation; +const static auto &request = Request::createRequest; +const static auto &POST = QNetworkAccessManager::PostOperation; +const static auto &GET = QNetworkAccessManager::GetOperation; +const static auto &resourceTypeMap = Config::resourceTypeMap; // 初始化名字 APICPP(activate_init_profile) { @@ -770,7 +771,7 @@ APICPP(comment_event) { // 楼层评论 APICPP(comment_floor) { - query["type"] = Config::resourceTypeMap[query["type"].toString()]; + query["type"] = resourceTypeMap[query["type"].toString()]; const QVariantMap data { { "parentCommentId", query["parentCommentId"] }, { "threadId", query["type"].toString() + query["id"].toString() }, @@ -793,7 +794,7 @@ APICPP(comment_hot) { QVariantMap cookie = query["cookie"].toMap(); cookie["os"] = "pc"; query["cookie"] = cookie; - query["type"] = Config::resourceTypeMap[query["type"].toString()]; + query["type"] = resourceTypeMap[query["type"].toString()]; const QVariantMap data { { "rid", query["id"] }, { "limit", query.value("limit", 20) }, @@ -811,6 +812,59 @@ APICPP(comment_hot) { ); } +// 评论抱一抱列表 +APICPP(comment_hug_list) { + QVariantMap cookie = query["cookie"].toMap(); + cookie["os"] = "ios"; + cookie["appver"] = "8.10.90"; + query["cookie"] = cookie; + query["type"] = resourceTypeMap[query.value("type", "0").toString()]; + const QString threadId = query["type"].toString() + query["sid"].toString(); + const QVariantMap data { + { "targetUserId", query["uid"] }, + { "commentId", query["cid"] }, + { "cursor", query.value("cursor", "-1") }, + { "threadId", threadId }, + { "pageNo", query.value("page", 1) }, + { "idCursor", query.value("idCursor", -1) }, + { "pageSize", query.value("pageSize", 100) } + }; + return request( + POST, + "https://music.163.com/api/v2/resource/comments/hug/list", + data, + { + { "crypto", "api" }, + _PARAM + } + ); +} + +// 点赞与取消点赞评论 +APICPP(comment_like) { + QVariantMap cookie = query["cookie"].toMap(); + cookie["os"] = "pc"; + query["cookie"] = cookie; + query["t"] = query["t"].toInt() == 1 ? "like" : "unlike"; + query["type"] = resourceTypeMap[query["type"].toString()]; + QVariantMap data { + { "threadId", query["type"].toString() + query["sid"].toString() }, + { "commentId", query["cid"] } + }; + if(query["type"].toString() == "A_EV_2_") { + data["threadId"] = query["threadId"]; + } + return request( + POST, + "https://music.163.com/weapi/v1/comment/" + query["t"].toString(), + data, + { + { "crypto", "weapi" }, + _PARAM + } + ); +} + // 歌曲评论 APICPP(comment_music) { QVariantMap cookie = query["cookie"].toMap(); @@ -855,6 +909,53 @@ APICPP(comment_mv) { ); } +// 新版评论接口 +APICPP(comment_new) { + QVariantMap cookie = query["cookie"].toMap(); + cookie["os"] = "pc"; + query["cookie"] = cookie; + query["type"] = resourceTypeMap[query["type"].toString()]; + const QString threadId = query["type"].toString() + query["id"].toString(); + const int pageSize = query.value("pageSize", 20).toInt(); + const int pageNo = query.value("pageNo", 1).toInt(); + int sortType = query.value("sortType", 99).toInt(); + if(sortType == 1) { + sortType = 99; + } + QString cursor = ""; + switch (sortType) { + case 99: + cursor = QString::number((pageNo - 1) * pageSize); + break; + case 2: + cursor = "normalHot#" + QString::number((pageNo - 1) * pageSize); + break; + case 3: + cursor = query.value("cursor", "0").toString(); + break; + default: + break; + } + const QVariantMap data { + { "threadId", threadId }, + { "pageNo", pageNo }, + { "showInner", query.value("showInner", true) }, + { "pageSize", pageSize }, + { "cursor", cursor }, + { "sortType", sortType } //99:按推荐排序,2:按热度排序,3:按时间排序 + }; + return request( + POST, + "https://music.163.com/api/v2/resource/comments", + data, + { + { "crypto", "eapi" }, + _PARAM, + { "url", "/api/v2/resource/comments" } + } + ); +} + // 歌单评论 APICPP(comment_playlist) { QVariantMap cookie = query["cookie"].toMap(); @@ -899,6 +1000,40 @@ APICPP(comment_video) { ); } +// 发送与删除评论 +APICPP(comment) { + QVariantMap cookie = query["cookie"].toMap(); + cookie["os"] = "android"; + query["cookie"] = cookie; + query["t"] = QMap { + { 1, "add" }, + { 0, "delete" }, + { 2, "reply" } + }[query["t"].toInt()]; + query["type"] = resourceTypeMap[query["type"].toString()]; + QVariantMap data { + { "threadId", query["type"].toString() + query["id"].toString() } + }; + if(query["type"].toString() == "A_EV_2_") { + data["threadId"] = query["threadId"]; + } + if(query["t"].toString() == "add") data["content"] = query["content"]; + else if(query["t"].toString() == "delete") data["commentId"] = query["commentId"]; + else if(query["t"].toString() == "reply") { + data["commentId"] = query["commentId"]; + data["content"] = query["content"]; + } + return request( + POST, + "https://music.163.com/weapi/resource/comments/" + query["t"].toString(), + data, + { + { "crypto", "weapi" }, + _PARAM + } + ); +} + // 国家编码列表 APICPP(countries_code_list) { const QVariantMap data { }; diff --git a/QCloudMusicApi/module.h b/QCloudMusicApi/module.h index a3d408f..9da6219 100644 --- a/QCloudMusicApi/module.h +++ b/QCloudMusicApi/module.h @@ -158,18 +158,30 @@ class QCLOUDMUSICAPI_EXPORT NeteaseCloudMusicApi: public QObject { // 热门评论 APIH(comment_hot) + // 评论抱一抱列表 + APIH(comment_hug_list) + + // 点赞与取消点赞评论 + APIH(comment_like) + // 歌曲评论 APIH(comment_music) // MV评论 APIH(comment_mv) + // 新版评论接口 + APIH(comment_new) + // 歌单评论 APIH(comment_playlist) // 视频评论 APIH(comment_video) + // 发送与删除评论 + APIH(comment) + // 国家编码列表 APIH(countries_code_list) diff --git a/Test/config.json b/Test/config.json index 0756153..df608ab 100644 --- a/Test/config.json +++ b/Test/config.json @@ -220,5 +220,29 @@ "comment_hot": { "id": "2058263032", "type": "0" + }, + "comment_hug_list": { + "uid": "285516405", + "cid": "1167145843", + "sid": "863481066", + "pageSize": 2, + "page": 1 + }, + "comment_like": { + "id": "29178366", + "cid": "12840183", + "t": 1, + "type": "0" + }, + "comment_new": { + "id": "2058263032", + "sortType": 3, + "type": "0" + }, + "comment": { + "id": "5436712", + "t": 1, + "type": "1", + "content": "test" } } \ No newline at end of file diff --git a/Test/mainwindow.cpp b/Test/mainwindow.cpp index b844b85..ec728e9 100644 --- a/Test/mainwindow.cpp +++ b/Test/mainwindow.cpp @@ -1,12 +1,13 @@ -#include "mainwindow.h" -#include "./ui_mainwindow.h" -#include +#include #include #include #include #include #include +#include "mainwindow.h" +#include "./ui_mainwindow.h" + #include "../QCloudMusicApi/module.h" #include "../QCloudMusicApi/util/index.h" #include "../QCloudMusicApi/util/crypto.h" @@ -16,9 +17,16 @@ MainWindow::MainWindow(QWidget *parent) , ui(new Ui::MainWindow) { ui->setupUi(this); + //将Api中的方法名称取出 for(int i = QObject().metaObject()->methodCount(); i < api.metaObject()->methodCount(); i++) { ui->comboBox->addItem(api.metaObject()->method(i).name()); } + + //读取配置 + QFile file(":/config.json"); + file.open(QIODevice::ReadOnly); + config = QJsonDocument::fromJson(file.readAll()); + []() {//测试aes加解密 QString body = "This is a text"; auto bodyEncrypt = Crypto::aesEncrypt(body.toUtf8(), EVP_aes_128_ecb, Crypto::eapiKey, ""); @@ -89,9 +97,6 @@ void MainWindow::on_pushButton_clicked() void MainWindow::on_comboBox_currentTextChanged(const QString &arg1) { - QFile file(":/config.json"); - file.open(QIODevice::ReadOnly); - auto config = QJsonDocument::fromJson(file.readAll()); auto JsonFormat = ui->checkBox->isChecked() ? QJsonDocument::Indented : QJsonDocument::Compact; ui->textEdit_2->setText( QJsonDocument(config[arg1].toObject()) diff --git a/Test/mainwindow.h b/Test/mainwindow.h index ae44328..a7a0086 100644 --- a/Test/mainwindow.h +++ b/Test/mainwindow.h @@ -1,11 +1,12 @@ #ifndef MAINWINDOW_H #define MAINWINDOW_H -#include "../QCloudMusicApi/module.h" - +#include #include #include +#include "../QCloudMusicApi/module.h" + QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; } QT_END_NAMESPACE @@ -45,5 +46,6 @@ private slots: Ui::MainWindow *ui; NeteaseCloudMusicApi api; QVariantMap cookie; + QJsonDocument config; }; #endif // MAINWINDOW_H From eb1966ef894d94ffdcca160dbac2af19984cbef7 Mon Sep 17 00:00:00 2001 From: overwriter Date: Sun, 21 Jan 2024 09:18:14 +0800 Subject: [PATCH 7/8] =?UTF-8?q?refactor:=E7=A7=BB=E5=8A=A8request=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E8=87=B3util?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- QCloudMusicApi/module.cpp | 2 +- QCloudMusicApi/{ => util}/request.cpp | 6 +++--- QCloudMusicApi/{ => util}/request.h | 0 3 files changed, 4 insertions(+), 4 deletions(-) rename QCloudMusicApi/{ => util}/request.cpp (99%) rename QCloudMusicApi/{ => util}/request.h (100%) diff --git a/QCloudMusicApi/module.cpp b/QCloudMusicApi/module.cpp index e3f4b54..dfe70ca 100644 --- a/QCloudMusicApi/module.cpp +++ b/QCloudMusicApi/module.cpp @@ -9,7 +9,7 @@ #include #include "util/config.h" -#include "request.h" +#include "util/request.h" #include "module.h" //入参与返回值类型为QVariantMap diff --git a/QCloudMusicApi/request.cpp b/QCloudMusicApi/util/request.cpp similarity index 99% rename from QCloudMusicApi/request.cpp rename to QCloudMusicApi/util/request.cpp index 472ed9a..9aa11a7 100644 --- a/QCloudMusicApi/request.cpp +++ b/QCloudMusicApi/util/request.cpp @@ -15,9 +15,9 @@ #include #include -#include "util/crypto.h" -#include "util/config.h" -#include "util/index.h" +#include "crypto.h" +#include "config.h" +#include "index.h" namespace Request { diff --git a/QCloudMusicApi/request.h b/QCloudMusicApi/util/request.h similarity index 100% rename from QCloudMusicApi/request.h rename to QCloudMusicApi/util/request.h From e71c7ac713ee127603fd8c570c2065d95dc7cebc Mon Sep 17 00:00:00 2001 From: overwriter Date: Sun, 21 Jan 2024 09:22:55 +0800 Subject: [PATCH 8/8] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=8C=BF=E5=90=8D?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E4=B8=8B,=E9=83=A8=E5=88=86=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E6=8F=90=E7=A4=BA=E7=BD=91=E7=BB=9C=E5=A4=AA=E6=8B=A5?= =?UTF-8?q?=E6=8C=A4=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- QCloudMusicApi/util/config.h | 2 +- QCloudMusicApi/util/request.cpp | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/QCloudMusicApi/util/config.h b/QCloudMusicApi/util/config.h index 67a7469..c644443 100644 --- a/QCloudMusicApi/util/config.h +++ b/QCloudMusicApi/util/config.h @@ -5,7 +5,7 @@ namespace Config { -const static QString anonymous_token = QStringLiteral("de91e1f8119d32e01cc73efcb82c0a30c9137e8d4f88dbf5e3d7bf3f28998f21add2bc8204eeee5e56c0bbb8743574b46ca2c10c35dc172199bef9bf4d60ecdeab066bb4dc737d1c3324751bcc9aaf44c3061cd18d77b7a0"); +static QString anonymous_token = QStringLiteral("de91e1f8119d32e01cc73efcb82c0a30c9137e8d4f88dbf5e3d7bf3f28998f21add2bc8204eeee5e56c0bbb8743574b46ca2c10c35dc172199bef9bf4d60ecdeab066bb4dc737d1c3324751bcc9aaf44c3061cd18d77b7a0"); const static QMap resourceTypeMap { { "0", "R_SO_4_" }, { "1", "R_MV_5_" }, diff --git a/QCloudMusicApi/util/request.cpp b/QCloudMusicApi/util/request.cpp index 9aa11a7..94dfde0 100644 --- a/QCloudMusicApi/util/request.cpp +++ b/QCloudMusicApi/util/request.cpp @@ -111,6 +111,8 @@ QVariantMap createRequest(QNetworkAccessManager::Operation method, if(!cookie.contains("MUSIC_A")) { //options.cookie.MUSIC_A = config.anonymous_token cookie["MUSIC_A"] = Config::anonymous_token; + cookie["os"] = cookie.value("os", "ios"); + cookie["appver"] = cookie.value("appver", "8.10.90"); } } request.setHeader(QNetworkRequest::CookieHeader, QVariant::fromValue(Index::mapToCookie(cookie)));