123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- #include "stdafx.h"
- #include "CUserInfo.h"
- #include "FileOperate.h"
- CUserInfo::CUserInfo() : id(0), port(0), enable(0)
- {
- }
- 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["ret"].get<int>() == 1)
- {
- //
- this->access_token = j["data"]["access_token"].get<std::string>();
- this->affurl = j["data"]["affurl"].get<std::string>();
- this->swoftdownload = j["data"]["swoftdownload"].get<std::string>();
- this->clash_config = j["data"]["clash_config"].get<std::string>();
- this->user_login_url = j["data"]["user_login_url"].get<std::string>();
- //
- this->id = j["data"]["user"].at("id").get<int>();
- this->username = j["data"]["user"].at("account").get<std::string>();
- this->expiretime = j["data"]["user"].at("expired_at").get<std::string>();
- this->password = j["data"]["user"].at("passwd").get<std::string>();
- this->unusedTraffic = j["data"]["user"].at("unusedTraffic").get<std::string>();
- this->uuid = j["data"]["user"].at("uuid").get<std::string>();
- this->level = j["data"]["user"].at("level").get<std::string>();
- this->port = j["data"]["user"].at("port").get<int>();
- this->enable = j["data"]["user"].at("enable").get<int>();
-
- return true;
- }
- else
- {
- this->m_error_msg = S_CA2W(j["msg"].get<std::string>().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<int>() == 1)
- {
-
- return 200;
- }
- else
- {
- this->m_error_msg = S_CA2W(j["msg"].get<std::string>().c_str(), CP_UTF8).GetBuffer(0);
- return j["ret"].get<int>();
- }
- }
- catch (...)
- {
- this->m_error_msg = L"解析数据错误";
- return -1;
- }
- return -1;
- }
-
|