#define CPPHTTPLIB_OPENSSL_SUPPORT #include #include #include #include #include #include #include "client.h" #include #include 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(); fan.distance = data["functions"]["headRoom"]["features"][0]["featureValue"].get(); } 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"); } }