#include "stdafx.h" #include "CUserInfo.h" #include "FileOperate.h" CUserInfo::CUserInfo() { } CUserInfo::~CUserInfo() { } bool CUserInfo::Init(std::string data) { if (data.empty()) { return false; } try { nlohmann::json j = nlohmann::json::parse(data.begin(), data.end()); if (j["code"].get() == 0) { this->username = j["data"]["email"].get(); this->expiretime = j["data"]["expiretime"].get(); this->unusedTraffic = j["data"]["unusedTraffic"].get(); this->uuid = j["data"]["uuid"].get(); this->clash_config = j["data"]["subscribe_url"].get(); this->enable = j["data"]["banned"].get(); auto plan = j["data"]["plan"]; this->planName = plan["name"].get(); //this->affurl = j["data"]["affurl"].get(); //this->swoftdownload = j["data"]["swoftdownload"].get(); //this->clash_config = j["data"]["clash_config"].get(); //this->user_login_url = j["data"]["user_login_url"].get(); //// //this->id = j["data"]["user"].at("id").get(); //this->username = j["data"]["user"].at("account").get(); //this->expiretime = j["data"]["user"].at("expired_at").get(); //this->password = j["data"]["user"].at("passwd").get(); //this->unusedTraffic = j["data"]["user"].at("unusedTraffic").get(); //this->uuid = j["data"]["user"].at("uuid").get(); //this->level = j["data"]["user"].at("level").get(); //this->port = j["data"]["user"].at("port").get(); //this->enable = j["data"]["user"].at("enable").get(); return true; } else { this->m_error_msg = S_CA2W(j["message"].get().c_str(),CP_UTF8).GetBuffer(0); return false; } } catch (...) { this->m_error_msg = L"解析数据错误"; return false; } return false; } int CUserInfo::authInit(std::string data) { if (data.empty()) { return -1; } try { nlohmann::json j = nlohmann::json::parse(data.begin(), data.end()); if (j["ret"].get() == 1) { return 200; } else { this->m_error_msg = S_CA2W(j["msg"].get().c_str(), CP_UTF8).GetBuffer(0); return j["ret"].get(); } } catch (...) { this->m_error_msg = L"解析数据错误"; return -1; } return -1; }