CUserInfo.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. if (data.empty())
  13. {
  14. return false;
  15. }
  16. try
  17. {
  18. nlohmann::json j = nlohmann::json::parse(data.begin(), data.end());
  19. if (j["ret"].get<int>() == 1)
  20. {
  21. auto userinfo = j["data"]["user"];
  22. //
  23. this->id = userinfo.at("id").get<int>();
  24. this->username = userinfo.at("account").get<std::string>();
  25. this->expiretime = userinfo.at("expired_at").get<std::string>();
  26. this->password = userinfo.at("passwd").get<std::string>();
  27. this->unusedTraffic = userinfo.at("unusedTraffic").get<std::string>();
  28. this->uuid = userinfo.at("uuid").get<std::string>();
  29. this->level = userinfo.at("level").get<std::string>();
  30. this->port = userinfo.at("port").get<int>();
  31. //
  32. this->access_token = j["data"]["access_token"].get<std::string>();
  33. this->token_type = j["data"]["token_type"].get<std::string>();
  34. return true;
  35. }
  36. else
  37. {
  38. this->m_error_msg = S_CA2W(j["msg"].get<std::string>().c_str(),CP_UTF8).GetBuffer(0);
  39. return false;
  40. }
  41. }
  42. catch (...)
  43. {
  44. this->m_error_msg = L"½âÎöÊý¾Ý´íÎó";
  45. return false;
  46. }
  47. return false;
  48. }
  49. SStringA CUserInfo::GetLastErrorA()
  50. {
  51. return S_CW2A(m_error_msg,CP_UTF8);
  52. }
  53. SStringW CUserInfo::GetLastErrorW()
  54. {
  55. return m_error_msg.GetBuffer(0);
  56. }