CUserInfo.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include "stdafx.h"
  2. #include "CUserInfo.h"
  3. #include "FileOperate.h"
  4. CUserInfo::CUserInfo() : id(0), port(0)
  5. {
  6. }
  7. CUserInfo::~CUserInfo()
  8. {
  9. }
  10. bool CUserInfo::Init(std::string data)
  11. {
  12. try
  13. {
  14. nlohmann::json j = nlohmann::json::parse(data.begin(), data.end());
  15. if (j["ret"].get<int>() == 1)
  16. {
  17. auto userinfo = j["data"]["user"];
  18. //
  19. this->id = userinfo.at("id").get<int>();
  20. this->username = userinfo.at("account").get<std::string>();
  21. this->expiretime = userinfo.at("expired_at").get<std::string>();
  22. this->password = userinfo.at("passwd").get<std::string>();
  23. this->unusedTraffic = userinfo.at("unusedTraffic").get<std::string>();
  24. this->uuid = userinfo.at("uuid").get<std::string>();
  25. this->level = userinfo.at("level").get<std::string>();
  26. this->port = userinfo.at("port").get<int>();
  27. //
  28. this->access_token = j["data"]["access_token"].get<std::string>();
  29. this->token_type = j["data"]["token_type"].get<std::string>();
  30. return true;
  31. }
  32. else
  33. {
  34. this->m_error_msg = j["msg"].get<std::string>();
  35. return false;
  36. }
  37. }
  38. catch (...)
  39. {
  40. this->m_error_msg = "½âÎöÊý¾Ý´íÎó";
  41. return false;
  42. }
  43. return false;
  44. }
  45. LPCSTR CUserInfo::GetLastErrorA()
  46. {
  47. return SStringA().Format("%s", m_error_msg.c_str()).GetBuffer(0);
  48. }
  49. LPCWSTR CUserInfo::GetLastErrorW()
  50. {
  51. return S_CA2W(m_error_msg.c_str(), CP_UTF8);
  52. }