CUserInfo.cpp 2.4 KB

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