#pragma once #include "IHttpFunc.h" #include #include "json/json.h" #include "SpSecureClient.h" #define TOKEN_GETURL_ERR 0x10A00001 #define GET_CHANNELID_ERR 0x10A00002 #define GET_TOKEN_ERR 0x10A00003 struct QueryChannelIDHTTPReq : CHTTPReq { QueryChannelIDHTTPReq() { m_timeOut = 500; m_withToken = false; } std::string systemId; virtual string ToJson() { char reqcontent[512]; sprintf(reqcontent, "{\"channelId\":\"\",\"systemId\":\"%s\",\"state\":\"\"}", systemId.c_str()); return reqcontent; } }; struct QueryChannelIDHTTPRet : CHTTPRet { QueryChannelIDHTTPRet() {} std::string m_channelId; std::string m_tokenSecret; virtual bool Parse(std::string strData) { DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("QueryChannelIDHTTPRet: data = %s", strData.c_str()); Json::Value root; Json::Reader reader; reader.parse(strData, root); if (root.isNull() || root["data"].isNull()) return false; for (int i = 0; i < root["data"].size(); i++) { auto curObject = root["data"][i]; if (!curObject["channelId"].isNull() && curObject["channelId"].isString()) { m_channelId = curObject["channelId"].asString(); return true; } else DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("parse channelId failed"); if (!curObject["clientSecret"].isNull() && curObject["clientSecret"].isString()) { m_tokenSecret = curObject["clientSecret"].asString(); return true; } else DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("parse clientSecret failed"); } return false; } }; struct QueryTokenHTTPReq : CHTTPReq { QueryTokenHTTPReq() { m_timeOut = 500; m_withToken = false; } std::string channelId; std::string tokenSecret; std::string businessId; virtual string ToJson() { char reqcontent[512]; sprintf(reqcontent, "{\"channelId\":\"%s\",\"businessId\":\"%s\",\"clientSecret\":\"%s\"}", channelId.c_str(), businessId.c_str(), tokenSecret.c_str()); return reqcontent; } }; struct QueryTokenHTTPRet : CHTTPRet { QueryTokenHTTPRet() {} std::string m_token; virtual bool Parse(std::string strData) { DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("QueryTokenHTTPRet: data = %s", strData.c_str()); Json::Value root; Json::Reader reader; reader.parse(strData, root); if (root.isNull() || root["data"].isNull()) return false; m_token = root["data"].asString(); return true; } };