CUserInfo.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include "stdafx.h"
  2. #include "CUserInfo.h"
  3. #include "FileOperate.h"
  4. CUserInfo::CUserInfo() : id(0), port(0), enable(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. //
  22. this->access_token = j["data"]["access_token"].get<std::string>();
  23. this->affurl = j["data"]["affurl"].get<std::string>();
  24. this->swoftdownload = j["data"]["swoftdownload"].get<std::string>();
  25. this->clash_config = j["data"]["clash_config"].get<std::string>();
  26. this->user_login_url = j["data"]["user_login_url"].get<std::string>();
  27. //
  28. this->id = j["data"]["user"].at("id").get<int>();
  29. this->username = j["data"]["user"].at("account").get<std::string>();
  30. this->expiretime = j["data"]["user"].at("expired_at").get<std::string>();
  31. this->password = j["data"]["user"].at("passwd").get<std::string>();
  32. this->unusedTraffic = j["data"]["user"].at("unusedTraffic").get<std::string>();
  33. this->uuid = j["data"]["user"].at("uuid").get<std::string>();
  34. this->level = j["data"]["user"].at("level").get<std::string>();
  35. this->port = j["data"]["user"].at("port").get<int>();
  36. this->enable = j["data"]["user"].at("enable").get<int>();
  37. return true;
  38. }
  39. else
  40. {
  41. this->m_error_msg = S_CA2W(j["msg"].get<std::string>().c_str(),CP_UTF8).GetBuffer(0);
  42. return false;
  43. }
  44. }
  45. catch (...)
  46. {
  47. this->m_error_msg = L"½âÎöÊý¾Ý´íÎó";
  48. return false;
  49. }
  50. return false;
  51. }