tokenDefine.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #pragma once
  2. #include "IHttpFunc.h"
  3. #include <string>
  4. #if defined(RVC_OS_WIN)
  5. #include "json.h"
  6. #else
  7. #include "json/json.h"
  8. #endif
  9. #include "SpSecureClient.h"
  10. #define TOKEN_GETURL_ERR 0x10A00001
  11. #define GET_CHANNELID_ERR 0x10A00002
  12. #define GET_TOKEN_ERR 0x10A00003
  13. struct QueryChannelIDHTTPReq : CHTTPReq {
  14. QueryChannelIDHTTPReq()
  15. {
  16. m_timeOut = 500;
  17. m_withToken = false;
  18. }
  19. std::string systemId;
  20. virtual string ToJson() {
  21. char reqcontent[512];
  22. sprintf(reqcontent, "{\"channelId\":\"\",\"systemId\":\"%s\",\"state\":\"\"}", systemId.c_str());
  23. return reqcontent;
  24. }
  25. };
  26. struct QueryChannelIDHTTPRet : CHTTPRet {
  27. QueryChannelIDHTTPRet() {}
  28. std::string m_channelId;
  29. std::string m_tokenSecret;
  30. virtual bool Parse(std::string strData) {
  31. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("QueryChannelIDHTTPRet: data = %s", strData.c_str());
  32. Json::Value root;
  33. Json::Reader reader;
  34. reader.parse(strData, root);
  35. if (root.isNull() || root["data"].isNull())
  36. return false;
  37. for (int i = 0; i < root["data"].size(); i++)
  38. {
  39. auto curObject = root["data"][i];
  40. if (!curObject["channelId"].isNull() && curObject["channelId"].isString())
  41. {
  42. m_channelId = curObject["channelId"].asString();
  43. return true;
  44. }
  45. else
  46. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("parse channelId failed");
  47. if (!curObject["clientSecret"].isNull() && curObject["clientSecret"].isString())
  48. {
  49. m_tokenSecret = curObject["clientSecret"].asString();
  50. return true;
  51. }
  52. else
  53. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("parse clientSecret failed");
  54. }
  55. return false;
  56. }
  57. };
  58. struct QueryTokenHTTPReq : CHTTPReq {
  59. QueryTokenHTTPReq()
  60. {
  61. m_timeOut = 500;
  62. m_withToken = false;
  63. }
  64. std::string channelId;
  65. std::string tokenSecret;
  66. std::string businessId;
  67. virtual string ToJson() {
  68. char reqcontent[512];
  69. sprintf(reqcontent, "{\"channelId\":\"%s\",\"businessId\":\"%s\",\"clientSecret\":\"%s\"}", channelId.c_str(), businessId.c_str(), tokenSecret.c_str());
  70. return reqcontent;
  71. }
  72. };
  73. struct QueryTokenHTTPRet : CHTTPRet {
  74. QueryTokenHTTPRet() {}
  75. std::string m_token;
  76. virtual bool Parse(std::string strData) {
  77. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("QueryTokenHTTPRet: data = %s", strData.c_str());
  78. Json::Value root;
  79. Json::Reader reader;
  80. reader.parse(strData, root);
  81. if (root.isNull() || root["data"].isNull())
  82. return false;
  83. m_token = root["data"].asString();
  84. return true;
  85. }
  86. };