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