HttpToken.hpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * @Description:
  3. * @Version: 1.0
  4. * @Autor: lishengyin
  5. * @Date: 2021-11-04 09:39:46
  6. * @LastEditors: Your Name lishengyin@sz-sunwin.com
  7. * @LastEditTime: 2022-09-04 21:26:21
  8. */
  9. #ifndef __HTTPTOKEN_HPP_
  10. #define __HTTPTOKEN_HPP_
  11. #include <iostream>
  12. using namespace std;
  13. #include <rapidjson/document.h>
  14. #include <rapidjson/rapidjson.h>
  15. #include <rapidjson/stringbuffer.h>
  16. #include <rapidjson/writer.h>
  17. class HttpToken
  18. {
  19. public:
  20. std::string authToken = "";
  21. std::string expiration = "";
  22. std::string refreshToken = "";
  23. public:
  24. HttpToken() {}
  25. ~HttpToken() {}
  26. /**
  27. * @description: json反序列为对象
  28. * @param {*}
  29. * @return {*}
  30. */
  31. bool jsonToObject(const rapidjson::Value& object){
  32. const auto end = object.MemberEnd();
  33. if(end == object.FindMember("authToken") || !object["authToken"].IsString()){
  34. return false;
  35. }else{
  36. authToken = object["authToken"].GetString();
  37. }
  38. if(end == object.FindMember("expiration") || !object["expiration"].IsString()){
  39. return false;
  40. }else{
  41. expiration = object["expiration"].GetString();
  42. }
  43. if(end == object.FindMember("refreshToken") || !object["refreshToken"].IsString()){
  44. return false;
  45. }else{
  46. refreshToken = object["refreshToken"].GetString();
  47. }
  48. return true;
  49. }
  50. void ObjectToJson(rapidjson::Writer<rapidjson::StringBuffer>& writer){
  51. writer.StartObject();
  52. writer.EndObject();
  53. }
  54. };
  55. #endif