lhhttpapi.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #pragma once
  2. #include <QString>
  3. #include <QObject>
  4. #include <QLibrary>
  5. #include <QDateTime>
  6. #include "Thread/threadcontroller.h"
  7. #define LH_HTTPAPI_SUCC 0
  8. const int LHHTTPAPI_BUFFER_SIZE = 1024*1024;
  9. // 用New
  10. #define LHAPI_BUFFER_SIZE_NEW 2048000
  11. #define LHAPI_BUFFER_SIZE_ARY 4096
  12. // token 超时
  13. #define TOKENTIME 20*60
  14. extern int g_nHttpTimeOut;
  15. // 操作类型【1查询 2更新 3删除 4插入 5存储过程】
  16. enum enDBOperatorType
  17. {
  18. EDBOT_Select = 1,
  19. EDBOT_Update,
  20. EDBOT_Delete,
  21. EDBOT_Insert,
  22. EDBOT_Procedure,
  23. };
  24. class lhhttpapi : public QObject
  25. {
  26. Q_OBJECT
  27. public:
  28. typedef void* (*FunDBInit)(const char* lpUrl,bool bismulti);
  29. typedef int (*FunDBLogin)(const char *plocalip,const char *pSerid, const char* CType, char *pszUserToken, int nSize,bool bismulti, void* phttpip);
  30. typedef int (*FunDBGetServerList)(char *pszList, int nSize,bool bismulti, void* phttpip);
  31. typedef int (*FunDBGetChannelList)(const char* pSerid,char *pszList, int nSize,bool bismulti, void* phttpip);
  32. typedef int (*FunDBDoInterface)(const char* pSerid,const char* CType,const char* strtoken,int nOperatorType, const char * strParamXml, char *strRetXml, int nSize,bool bismulti, void* phttpip);
  33. typedef int64_t (*FunDoGetHttpFileSize)(const char* pHttAddr);
  34. typedef int64_t (*FunDoGetHttpFileContent)(const char* lpHttpAddr, char *pszContent, int nSize);
  35. typedef int (*FunDoUploadFtpFile)(const char* pszLocalFilePath, const char* pszFtpFilePath);
  36. typedef int (*FunDoUploadFtpFileContent)(const char * szFileContent, int nSize, const char* strFtpFilePath);
  37. typedef int (*FunDoCurlDeleteFtpFile)(const char* user, const char* pwd, const char* pszFtpFile);
  38. typedef int (*FunDoCurlUploadFtpFile)(const char* user, const char* pwd, const char* pszLocalFilePath, const char* pszFtpFile);
  39. typedef int (*FunDoCurlUploadFtpFileContent)(const char* user, const char* pwd, const char* pszFileContent, int nSize, const char* pszFtpFile);
  40. // typedef int (*FunUnInit)();
  41. typedef int (*FunDoGetLastError)(char *pError, int nLen, int *nErrorCode);
  42. typedef int (*FunDoRelease)(bool bismulti, void* phttpip);
  43. public:
  44. explicit lhhttpapi(QObject *parent = nullptr);
  45. ~lhhttpapi();
  46. public:
  47. QLibrary *m_pQLib;
  48. FunDoRelease fnDoRelease;
  49. FunDBInit fnDBInit;
  50. FunDBLogin fnDBLogin;
  51. FunDBGetServerList fnDBGettServerList;
  52. FunDBGetChannelList fnDBGetChannelList;
  53. FunDBDoInterface fnDBDoInterface;
  54. FunDoGetHttpFileSize fnDoGetHttpFileSize;
  55. FunDoGetHttpFileContent fnDoGetHttpFileContent;
  56. FunDoUploadFtpFile fnDoUploadFtpFile;
  57. FunDoUploadFtpFileContent fnDoUploadFtpFileContent;
  58. FunDoCurlDeleteFtpFile fnDoCurlDeleteFtpFile;
  59. FunDoCurlUploadFtpFile fnDoCurlUploadFtpFile;
  60. FunDoCurlUploadFtpFileContent fnDoCurlUploadFtpFileContent;
  61. // FunUnInit fnUnInit;
  62. FunDoGetLastError fnGetLastError;
  63. QMutex m_mutexWorkerDestroy;
  64. QWaitCondition m_Condition;
  65. public:
  66. bool Load(QString file);
  67. bool UnLoad();
  68. int DoRelease(bool bismulti = false, void* phttpip=nullptr);
  69. int DBLogin(const QString& pLocalip,const QString &pSerid,const QString &appType, QString &pszUserToken,bool bismulti = false, void* phttpip=nullptr);
  70. int DoGetToken(QString &szToken,bool bismulti = false, void* phttpip=nullptr);
  71. // void DoGetTokenAgain();
  72. int DBGetServerList(char *pszList, int nSize,bool bismulti = false, void* phttpip=nullptr);
  73. int DBGetChannelList(const char* pSerid,char *pszList, int nSize,bool bismulti = false, void* phttpip=nullptr);
  74. int DBDoInterface(int nOperatorType, const QString &strParamXml, QString &strRetXml, bool wait = false,bool bismulti = false, void* phttpip=nullptr);
  75. void* DBInit (const char *lpUrl,bool bismulti = false);
  76. int DoGetLastError(char *pError, int nLen, int *nErrorCode);
  77. QString DoGetLastError(int *nErrorCode);
  78. int64_t DoGetHttpFileSize(const QString &url);
  79. int64_t DoGetHttpFileContent(const QString &url, char *pszContent, int nSize);
  80. // int64_t DoGetHttpPNGFile(const QString &url, QPixmap &outPixmap);
  81. bool DoUploadFtpFile(const QString &localFilePath, const QString &ftpFilePath);
  82. bool DoUploadFtpFileContent(const char * szFileContent, int nSize, const QString &ftpFilePath);
  83. bool DoCurlDeleteFtpFile(const QString &targetFilePath);
  84. bool DoCurlDeleteFtpFile(const QString &user, const QString &pwd, const QString &targetFilePath);
  85. bool DoCurlUploadFtpFile(const QString &localFilePath, const QString &destFilePath);
  86. bool DoCurlUploadFtpFile(const QString &user, const QString &pwd, const QString &localFilePath, const QString &destFilePath);
  87. bool DoCurlUploadFtpFileContent(const char * szFileContent, int nSize, const QString &destFilePath);
  88. bool DoCurlUploadFtpFileContent(const QString &user, const QString &pwd, const char * szFileContent, int nSize, const QString &destFilePath);
  89. private slots:
  90. void OnWorkerFinished();
  91. private:
  92. QString m_Localip; // localip
  93. QString m_Serid; // 当前服务数据库id
  94. QString m_appType; // 设备类型
  95. QString m_strtoken;// token
  96. QDateTime m_lasttimer; // 最后一个获取token的时间
  97. };
  98. class DoInterfaceObject : public ThreadWorker
  99. {
  100. Q_OBJECT
  101. public:
  102. explicit DoInterfaceObject(lhhttpapi *pApi, const QString &strToken, int nOperatorType, const QString &strParamXml,bool bismulti = false,void* phttpip=nullptr);
  103. virtual ~DoInterfaceObject() override {}
  104. QString GetRetXML() const {return m_strRetXml;}
  105. int GetResult() const {return m_nResult;}
  106. public slots:
  107. virtual void DoInit() override {}
  108. virtual void DoWork() override;
  109. signals:
  110. void sig_WorkFinished();
  111. public:
  112. lhhttpapi *m_pApi;
  113. QString m_strToken;
  114. int m_nOperatorType;
  115. QString m_strParamXml;
  116. QString m_strRetXml;
  117. int m_nResult;
  118. bool m_bismulti;
  119. void* m_phttpip;
  120. };