CUserInfo.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #include "stdafx.h"
  2. #include "CUserInfo.h"
  3. #include "FileOperate.h"
  4. CUserInfo::CUserInfo()
  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["code"].get<int>() == 0)
  20. {
  21. //this->affurl = j["data"]["affurl"].get<std::string>();
  22. //this->swoftdownload = j["data"]["swoftdownload"].get<std::string>();
  23. //this->clash_config = j["data"]["clash_config"].get<std::string>();
  24. //this->user_login_url = j["data"]["user_login_url"].get<std::string>();
  25. ////
  26. //this->id = j["data"]["user"].at("id").get<int>();
  27. //this->username = j["data"]["user"].at("account").get<std::string>();
  28. //this->expiretime = j["data"]["user"].at("expired_at").get<std::string>();
  29. //this->password = j["data"]["user"].at("passwd").get<std::string>();
  30. //this->unusedTraffic = j["data"]["user"].at("unusedTraffic").get<std::string>();
  31. //this->uuid = j["data"]["user"].at("uuid").get<std::string>();
  32. //this->level = j["data"]["user"].at("level").get<std::string>();
  33. //this->port = j["data"]["user"].at("port").get<int>();
  34. //this->enable = j["data"]["user"].at("enable").get<int>();
  35. return true;
  36. }
  37. else
  38. {
  39. this->m_error_msg = S_CA2W(j["message"].get<std::string>().c_str(),CP_UTF8).GetBuffer(0);
  40. return false;
  41. }
  42. }
  43. catch (...)
  44. {
  45. this->m_error_msg = L"解析数据错误";
  46. return false;
  47. }
  48. return false;
  49. }
  50. int CUserInfo::authInit(std::string data)
  51. {
  52. if (data.empty())
  53. {
  54. return -1;
  55. }
  56. try
  57. {
  58. nlohmann::json j = nlohmann::json::parse(data.begin(), data.end());
  59. if (j["ret"].get<int>() == 1)
  60. {
  61. return 200;
  62. }
  63. else
  64. {
  65. this->m_error_msg = S_CA2W(j["msg"].get<std::string>().c_str(), CP_UTF8).GetBuffer(0);
  66. return j["ret"].get<int>();
  67. }
  68. }
  69. catch (...)
  70. {
  71. this->m_error_msg = L"解析数据错误";
  72. return -1;
  73. }
  74. return -1;
  75. }