Commit 6ede6a7f by 李维杰

增加日志

parent 8ddb3bac
#include "http_request.h" #include "http_request.h"
#include "http_client.h" #include "http_client.h"
#include "json/json.h" #include "json/json.h"
#include <map> #include <map>
#include <list> #include <list>
HttpRequest *HttpRequest::instance_ = nullptr; HttpRequest *HttpRequest::instance_ = nullptr;
HttpRequest *HttpRequest::GetInstance() HttpRequest *HttpRequest::GetInstance()
{ {
if (instance_ == nullptr) if (instance_ == nullptr)
{ {
instance_ = new HttpRequest(); instance_ = new HttpRequest();
} }
return instance_; return instance_;
} }
bool ParseJson(std::string message, Json::Value &root) bool ParseJson(std::string message, Json::Value &root)
{ {
Json::CharReaderBuilder readerBuilder; Json::CharReaderBuilder readerBuilder;
std::unique_ptr<Json::CharReader> const reader(readerBuilder.newCharReader()); std::unique_ptr<Json::CharReader> const reader(readerBuilder.newCharReader());
const char *start_pos = message.c_str(); const char *start_pos = message.c_str();
std::string err; std::string err;
if (!reader->parse(start_pos, start_pos + message.length(), &root, &err)) if (!reader->parse(start_pos, start_pos + message.length(), &root, &err))
{ {
return false; return false;
} }
return true; return true;
} }
bool HttpRequest::Init() bool HttpRequest::Init()
{ {
return HttpRequest::GetInstance()->Load(); return HttpRequest::GetInstance()->Load();
} }
bool HttpRequest::LogIn(std::string userid, std::string password, std::string &token, std::string &roomid) bool HttpRequest::LogIn(std::string userid, std::string password, std::string &token, std::string &roomid)
{ {
ZgHttpClient client; ZgHttpClient client;
std::string params; std::string params;
params = "nickname=" + userid + "&password=" + password + "&uuid=" + "{eae23299-d280-4be2-92a7-8494e18c799b}"; params = "nickname=" + userid + "&password=" + password + "&uuid=" + "{eae23299-d280-4be2-92a7-8494e18c799b}";
std::map<std::string, std::string> headers; std::map<std::string, std::string> headers;
headers["zgl-clienttype"] = "OffcnLiveLR"; headers["zgl-clienttype"] = "OffcnLiveLR";
headers["zgl-systemtype"] = "Windows"; headers["zgl-systemtype"] = "Windows";
headers["zgl-systemversion"] = "10"; headers["zgl-systemversion"] = "10";
headers["zgl-clientversion"] = "3.1.1"; headers["zgl-clientversion"] = "3.1.1";
//"https://test-api.live.offcncloud.com/api/v1/users" //"https://test-api.live.offcncloud.com/api/v1/users"
std::string req = HttpRequest::GetInstance()->web_server_url_ + "/api/v1/users";
std::string response; HttpRequest::GetInstance()->web_server_url_ = "https://api.live.offcncloud.com";
if (!client.Post(req, params, headers, response)) std::string req = HttpRequest::GetInstance()->web_server_url_ + "/api/v1/users";
{ std::string response;
return false; if (!client.Post(req, params, headers, response))
} {
return false;
Json::Value root; }
if (!ParseJson(response, root)) return false;
Json::Value root;
int code = root["code"].asInt(); if (!ParseJson(response, root)) return false;
if (code != 0) return false;
int code = root["code"].asInt();
if (!root["data"]) return false; if (code != 0) return false;
Json::Value data = root["data"]; if (!root["data"]) return false;
if (!data["access_token"] || !data["room_id"]) return false;
Json::Value data = root["data"];
token = data["access_token"].asString(); if (!data["access_token"] || !data["room_id"]) return false;
roomid = data["room_id"].asString();
token = data["access_token"].asString();
return true; roomid = data["room_id"].asString();
}
std::string HttpRequest::GetWebServerUrl() return true;
{ }
return HttpRequest::GetInstance()->web_server_url_; std::string HttpRequest::GetWebServerUrl()
} {
bool HttpRequest::Load() return HttpRequest::GetInstance()->web_server_url_;
{ }
FILE *file = fopen("./config", "r"); bool HttpRequest::Load()
if (file == NULL) return false; {
FILE *file = fopen("./config", "r");
long fileSize = 0; if (file == NULL) return false;
fseek(file, 0, SEEK_END);
fileSize = ftell(file); long fileSize = 0;
if (fileSize <= 0) return false; fseek(file, 0, SEEK_END);
fileSize = ftell(file);
char *p = new char[fileSize]; if (fileSize <= 0) return false;
rewind(file);
char *p = new char[fileSize];
long ret = fread(p, 1, fileSize, file); rewind(file);
if (ret <= 0)
{ long ret = fread(p, 1, fileSize, file);
delete p; if (ret <= 0)
fclose(file); {
return false; delete p;
} fclose(file);
return false;
std::string message(p); }
delete p;
std::string message(p);
Json::Value root; delete p;
Json::CharReaderBuilder readerBuilder;
Json::Value root;
std::unique_ptr<Json::CharReader> const reader(readerBuilder.newCharReader()); Json::CharReaderBuilder readerBuilder;
const char *start_pos = message.c_str(); std::unique_ptr<Json::CharReader> const reader(readerBuilder.newCharReader());
std::string err; const char *start_pos = message.c_str();
if (!reader->parse(start_pos, start_pos + message.length(), &root, &err))
{ std::string err;
return false; if (!reader->parse(start_pos, start_pos + message.length(), &root, &err))
} {
return false;
if (root["web_server_url"]) }
{
web_server_url_ = root["web_server_url"].asString(); if (root["web_server_url"])
} {
else web_server_url_ = root["web_server_url"].asString();
{ }
return false; else
} {
return true; return false;
} }
return true;
}
bool HttpRequest::GetPullUrl(std::string token, std::map<std::string, std::string> &urls) bool HttpRequest::GetPullUrl(std::string token, std::map<std::string, std::string> &urls)
{ {
ZgHttpClient client; ZgHttpClient client;
......
...@@ -138,7 +138,14 @@ void RebuildManager::CallBackWhiteBoardData(AVPacket &pkt) ...@@ -138,7 +138,14 @@ void RebuildManager::CallBackWhiteBoardData(AVPacket &pkt)
std::string req((char *)info.m_pData + 6, info.m_nDataSize - 6); std::string req((char *)info.m_pData + 6, info.m_nDataSize - 6);
int index = *(int *)(info.m_pData + 6 + 8); int index = *(int *)(info.m_pData + 6 + 8);
printf("whitebaord's data index = %d\n", index);
//canvas id
char *p = (char *)info.m_pData + 32;
char tmp[32] = { 0 };
memcpy(tmp, p, 24);
printf("whitebaord's data index = %d, canvasid = %s\n", index, tmp);
if (m_pMqtt) if (m_pMqtt)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment