#pragma once #include #include #include #include #include using namespace std; class HepuGetSalt { private: public: const string cmd = "userSaltGet"; string username; HepuGetSalt(){}; ~HepuGetSalt(){}; void objectToJson(string& str){ rapidjson::StringBuffer strBuf; rapidjson::Writer writer(strBuf); this->objectToJson(writer); str = strBuf.GetString(); } void objectToJson(rapidjson::Writer& writer){ writer.StartObject(); writer.Key("cmd"); writer.String(cmd.c_str()); writer.Key("param"); writer.StartObject(); writer.Key("username"); writer.String(username.c_str()); writer.EndObject(); writer.EndObject(); } bool jsonToObject(std::string& json){ rapidjson::Document doc; doc.Parse(json.c_str()); if(!doc.IsObject()){ return false; } const auto end = doc.MemberEnd(); if(end == doc.FindMember("cmd") || !doc["cmd"].IsString()){ return false; }else{ if(cmd != doc["cmd"].GetString()) return false; } if(end == doc.FindMember("param") || !doc["param"].IsObject()) { return false; }else{ if(end == doc.FindMember("username") || !doc["username"].IsString()){ return false; }else{ username = doc["username"].GetString(); } } return true; } };