Added the function of obtaining user information on the network

This commit is contained in:
xyz
2025-06-11 11:21:08 +08:00
parent 68cd53a80c
commit 24536ca80f
6 changed files with 116 additions and 28 deletions

View File

@ -42,6 +42,42 @@ namespace network {
//生成请求的Id
static QString makeRequestId();
//封装发送请求的逻辑
QNetworkReply* sendHttpRequest(const QString& apiPath, const QByteArray& body);
//封装处理响应的逻辑判定HTTP正确性反序列化判断业务的正确性
//由于不同的api返回的pb对象结构不同为了让一个函数能够处理多种不同的类型需要使用模板
//后面两个是输出型参数,用于表示这次的操作是成功还是失败
template <typename T>
std::shared_ptr<T> handleHttpResponse(QNetworkReply* httpResp, bool* ok, QString* reason) {
//判定HTTP层面上
if (httpResp->error() != QNetworkReply::NoError) {
*ok = false;
*reason = httpResp->errorString();
httpResp->deleteLater();
return std::shared_ptr<T>();
}
//说明并没有出错, 那就获取到响应的body
QByteArray respBody = httpResp->readAll();
//针对body反序列化
std::shared_ptr<T> respObj = std::make_shared<T>();
respObj->deserialize(&serializer, respBody);
//判定业务的结构是否正确
if (!respObj->success()) {
*ok = false;
*reason = respObj->errmsg();
httpResp->deleteLater();
return std::shared_ptr<T>();
}
//释放httpResp对象
httpResp->deleteLater();
return respObj;
}
void getMyself(const QString& loginSessionId);
private:
model::DataCenter* dataCenter;