HttpClient.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * @Description:
  3. * @Version: 1.0
  4. * @Autor: lishengyin
  5. * @Date: 2022-02-23 09:31:32
  6. * @LastEditors: lishengyin
  7. * @LastEditTime: 2022-08-22 15:00:21
  8. */
  9. #ifndef __HTTPCLIENT_H_
  10. #define __HTTPCLIENT_H_
  11. #include <iostream>
  12. #include <time.h>
  13. #include <ctime>
  14. #include "Util/logger.h"
  15. #include "Util/NoticeCenter.h"
  16. #include "Poller/EventPoller.h"
  17. #include "Util/SqlPool.h"
  18. #include "Network/TcpClient.h"
  19. #include "Poller/Timer.h"
  20. #include "TCPClient.hpp"
  21. #include <httplib.h>
  22. #include "Notices.h"
  23. #include "md5.h"
  24. // dataType
  25. #include "NettyHttpResultMsg.h"
  26. #include "NettyHttpToken.h"
  27. #include "NettyHttpNull.h"
  28. #include "NettyExpelDevInfo.h"
  29. #include "NettyHttpDicCode.h"
  30. #include "UtilBase.hpp"
  31. using namespace std;
  32. namespace gsd{
  33. class HttpClient: public enable_shared_from_this<HttpClient>, public ModuleBase
  34. {
  35. private:
  36. // 用户名
  37. std::string account;
  38. std::string pwd = "sunwin20200507";
  39. // 固定16位私钥
  40. std::string privateKey = "mwWAH2eUAAHodlRt";
  41. // authToken
  42. std::string authToken = "";
  43. // refreshToken
  44. std::string refreshToken = "";
  45. public:
  46. HttpClient() {}
  47. ~HttpClient() {}
  48. /**
  49. * @description: Init
  50. * @return {*}
  51. */
  52. virtual bool Init(){
  53. return true;
  54. }
  55. /**
  56. * @description: Destroy
  57. * @return {*}
  58. */
  59. virtual void Destroy(){
  60. }
  61. /**
  62. * @description: 初始化
  63. * @param {string} account
  64. * @param {string} url
  65. * @param {int} port
  66. * @return {*}
  67. */
  68. int32_t Init(std::string account,std::string url, int port);
  69. /**
  70. * @description: 创建对象
  71. * @param {*}
  72. * @return {*}
  73. */
  74. static std::shared_ptr<HttpClient> CreateNew();
  75. /**
  76. * @description: 登录
  77. * @param {*}
  78. * @return {*}
  79. */
  80. int32_t LoginNetty();
  81. /**
  82. * @description: 判断是否获取到Token
  83. * @param {*}
  84. * @return {*}
  85. */
  86. bool alive();
  87. /**
  88. * @description: 获取时间
  89. * @param {char} *ctime
  90. * @return {*}
  91. */
  92. static void getDataTime(char *ctime);
  93. /**
  94. * @description: 获取驱鸟设备信息
  95. * @param {*}
  96. * @return {*}
  97. */
  98. int32_t getExpelInfo(std::string simCode, NettyHttpResultMsg<NettyExpelDevInfo,NettyHttpNull>& nettyHttpResultMsg);
  99. /**
  100. * @description: 获取派尔云的设备数据
  101. * @param {*}
  102. * @return {*}
  103. */
  104. int32_t getHttpDicCode(std::string dictCode,NettyHttpResultMsg<NettyHttpDicCode,NettyHttpNull>& nettyHttpResultMsg);
  105. };
  106. };
  107. #endif