Skip to content

Commit

Permalink
feat:增加部分评论接口
Browse files Browse the repository at this point in the history
  • Loading branch information
overwriter committed Jan 20, 2024
1 parent 79f0154 commit e73cf64
Show file tree
Hide file tree
Showing 5 changed files with 191 additions and 13 deletions.
145 changes: 140 additions & 5 deletions QCloudMusicApi/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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() },
Expand All @@ -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) },
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -899,6 +1000,40 @@ APICPP(comment_video) {
);
}

// 发送与删除评论
APICPP(comment) {
QVariantMap cookie = query["cookie"].toMap();
cookie["os"] = "android";
query["cookie"] = cookie;
query["t"] = QMap<int, QString> {
{ 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 { };
Expand Down
12 changes: 12 additions & 0 deletions QCloudMusicApi/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
24 changes: 24 additions & 0 deletions Test/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
17 changes: 11 additions & 6 deletions Test/mainwindow.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#include "mainwindow.h"
#include "./ui_mainwindow.h"
#include <QMetaMethod>
#include <QMetaMethod>
#include <QTextEdit>
#include <QJsonDocument>
#include <QJsonObject>
#include <QFile>
#include <QDebug>

#include "mainwindow.h"
#include "./ui_mainwindow.h"

#include "../QCloudMusicApi/module.h"
#include "../QCloudMusicApi/util/index.h"
#include "../QCloudMusicApi/util/crypto.h"
Expand All @@ -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, "");
Expand Down Expand Up @@ -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())
Expand Down
6 changes: 4 additions & 2 deletions Test/mainwindow.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include "../QCloudMusicApi/module.h"

#include <QJsonDocument>
#include <QMainWindow>
#include <QObject>

#include "../QCloudMusicApi/module.h"

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE
Expand Down Expand Up @@ -45,5 +46,6 @@ private slots:
Ui::MainWindow *ui;
NeteaseCloudMusicApi api;
QVariantMap cookie;
QJsonDocument config;
};
#endif // MAINWINDOW_H

0 comments on commit e73cf64

Please sign in to comment.