WebAPIBase.h 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #ifndef WEBAPIBASE_H
  2. #define WEBAPIBASE_H
  3. #include <QString>
  4. #include "spdlog/spdlog.h"
  5. class lhhttpapi;
  6. #define nJsonCatch catch(const nJson::parse_error& e) \
  7. { \
  8. mCritical << "WebAPI parse failed: " << e.what();\
  9. return false;\
  10. }\
  11. catch(const nJson::type_error& e) \
  12. {\
  13. mCritical << "WebAPI type failed: " << e.what();\
  14. return false;\
  15. }catch (const std::exception& e)\
  16. {\
  17. mCritical << "WebAPI std failed: " << e.what();\
  18. return false;\
  19. }catch(...)\
  20. {\
  21. mCritical << "WebAPI Operated failed: unknown error";\
  22. return false;\
  23. }
  24. class WebAPIBase
  25. {
  26. public:
  27. WebAPIBase();
  28. virtual ~WebAPIBase();
  29. /* 初始化WebAPI */
  30. bool initWebApi(const QString& url, const QString& serID, const QString appType, const QString serverIP = "");
  31. private:
  32. std::shared_ptr<spdlog::logger> m_logger = nullptr;
  33. lhhttpapi* m_httpApi = nullptr;
  34. QString m_userToken;
  35. };
  36. #endif /* WEBAPIBASE_H */