1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- #include "stdafx.h"
- #include "CUserInfo.h"
- #include "FileOperate.h"
- CUserInfo::CUserInfo() : id(0), port(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)
- {
- auto userinfo = j["data"]["user"];
- //
- this->id = userinfo.at("id").get<int>();
- this->username = userinfo.at("account").get<std::string>();
- this->expiretime = userinfo.at("expired_at").get<std::string>();
- this->password = userinfo.at("passwd").get<std::string>();
- this->unusedTraffic = userinfo.at("unusedTraffic").get<std::string>();
- this->uuid = userinfo.at("uuid").get<std::string>();
- this->level = userinfo.at("level").get<std::string>();
- this->port = userinfo.at("port").get<int>();
- //
- this->access_token = j["data"]["access_token"].get<std::string>();
- this->token_type = j["data"]["token_type"].get<std::string>();
- 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;
- }
- SStringA CUserInfo::GetLastErrorA()
- {
- return S_CW2A(m_error_msg,CP_UTF8);
- }
- SStringW CUserInfo::GetLastErrorW()
- {
- return m_error_msg.GetBuffer(0);
- }
|