You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
3.2 KiB
C++

#define CPPHTTPLIB_OPENSSL_SUPPORT
#include <QString>
#include <codecvt>
#include <string>
#include <iostream>
#include <httplib.h>
#include <json.hpp>
#include "client.h"
#include <QDebug>
#include <QTextCodec>
using json = nlohmann::json;
using namespace std;
HTTPClient httpClient;
HTTPClient::HTTPClient() : client("https://121.36.33.250:9000") {
header = {{"GroupId", "dam"}};
loginIndex = "/services/application/api/fan_app/login";
fanListIndex = "/services/application/api/fan_app/fanList";
headroomDetailIndex = "/services/application/api/fan_app/headroomDetail";
gyroDetailIndex = "/services/application/api/fan_app/gyroDetail";
featureHistoryIndex = "/services/application/api/fan_app/featureHistory";
client.enable_server_certificate_verification(false); // 取消SSL验证
}
FanManage HTTPClient::getFanList(){
FanManage Fans;
if (auto res = client.Post(fanListIndex, header)) {
json resJson = json::parse(res->body);
for (const auto& data : resJson["data"]) {
FanClass fan;
fan.fanCode = QString::fromStdString(data["fanCode"]);
if (data["functions"]["gyro"]["features"][0]["featureValue"].is_number() && data["functions"]["headRoom"]["features"][0]["featureValue"].is_number()) {
fan.angle = data["functions"]["gyro"]["features"][0]["featureValue"].get<double>();
fan.distance = data["functions"]["headRoom"]["features"][0]["featureValue"].get<double>();
}
fan.gyroState = QString::fromStdString(data["functions"]["flange"]["state"]);
fan.flangeState = QString::fromStdString(data["functions"]["gyro"]["state"]);
fan.headroomState = QString::fromStdString(data["functions"]["headRoom"]["state"]);
Fans.allFans[fan.fanCode] = fan;
//std::cout << fan.angle << std::endl;
}
}
return Fans;
}
QString HTTPClient::getFlangeList(int fanId) {
json bodyJson = {{"fanId",fanId}};
std::string body = bodyJson.dump();
if (auto res = client.Post(headroomDetailIndex, header, body, "application/json")) {
QString body = QString::fromStdString(res->body);
return body;
}
else {
return QString("error");
}
}
QString HTTPClient::getHeadroomList(int fanId) {
json bodyJson = { {"fanId",fanId} };
std::string body = bodyJson.dump();
if (auto res = client.Post(headroomDetailIndex, header, body, "application/json")) {
QString body = QString::fromStdString(res->body);
return body;
}
else {
return QString("error");
}
}
QString HTTPClient::getGyroList(int fanId) {
json bodyJson = { {"fanId",fanId} };
std::string body = bodyJson.dump();
if (auto res = client.Post(gyroDetailIndex, header, body, "application/json")) {
QString body = QString::fromStdString(res->body);
return body;
}
else {
return QString("error");
}
}
QString HTTPClient::getHistoryList(int fanId) {
if (auto res = client.Post(gyroDetailIndex, header)) {
QString body = QString::fromStdString(res->body);
return body;
}
else {
return QString("error");
}
}