linux版本中间件

main.cpp 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #include <iostream>
  2. #include "Log.h"
  3. #include "FsProxy.h"
  4. #include "Config.h"
  5. #include "TimeScheduler.h"
  6. #include "TtsBaidu.h"
  7. #include "SqlWrite.h"
  8. #include "SoftAuth.h"
  9. #include <string>
  10. void AuthFun()
  11. {
  12. bool isStop = false;
  13. while (!isStop)
  14. {
  15. std::this_thread::sleep_for(std::chrono::hours(1));
  16. if (!SoftAuth::GetInstance()->isExpire()) // 授权到期,关闭程序
  17. {
  18. LOG_WARN("授权到期,自动关闭程序!");
  19. isStop = true;
  20. CFsProxy::GetInstance().release();
  21. exit(EXIT_SUCCESS);
  22. }
  23. }
  24. }
  25. int main()
  26. {
  27. MYLog::instance()->Init("log4cpp.conf");
  28. LOG_INFO_S("程序开始启动...");
  29. //if (!SoftAuth::GetInstance()->Auth())
  30. //{
  31. // std::cout << "该机器未授权,请授权后使用" << std::endl;
  32. // std::string hardc;
  33. // SoftAuth::GetInstance()->getMachineCode(hardc);
  34. // //std::cout << SoftAuth::GetInstance()->getMachineCode(hardc) << std::endl;
  35. // std::cout << "机器码:" << hardc << std::endl;
  36. // //SoftAuth::GetInstance()->MakeAuth(hardc);
  37. //
  38. // std::string code;// = "MWEyZGZmYzctYTVjNC00OWEwLTgxNTgtMTQ3YjNmYTA3Zjc4CjIwMjAwNzE2";
  39. // std::cout << "请输入授权码:" << std::endl;
  40. // std::cin >> code;
  41. // if (!SoftAuth::GetInstance()->Auth(code))
  42. // {
  43. // LOG_WARN("授权验证失败,自动关闭程序!");
  44. // CFsProxy::GetInstance().release();
  45. // //exit(EXIT_SUCCESS);
  46. // return 0;
  47. // }
  48. //}
  49. if (!SoftAuth::GetInstance()->AuthV2())
  50. {
  51. std::cout << "该机器未授权,请授权后使用" << std::endl;
  52. std::string hardc;
  53. if (!SoftAuth::GetInstance()->getMachineCode(hardc))
  54. {
  55. std::cout << "机器码获取失败,请用root权限运行!" << std::endl;
  56. return 0;
  57. }
  58. std::cout << "机器码:" << hardc << std::endl;
  59. std::string code;// = "MWEyZGZmYzctYTVjNC00OWEwLTgxNTgtMTQ3YjNmYTA3Zjc4CjIwMjAwNzE2";
  60. std::cout << "请输入授权码:" << std::endl;
  61. std::cin >> code;
  62. if (!SoftAuth::GetInstance()->AuthV2(code))
  63. {
  64. LOG_WARN("授权验证失败,自动关闭程序!");
  65. CFsProxy::GetInstance().release();
  66. //exit(EXIT_SUCCESS);
  67. return 0;
  68. }
  69. }
  70. AuthInfo aInfo;
  71. SoftAuth::GetInstance()->getAuthInfo(aInfo);
  72. LOG_INFO_S("授权到期时间:" + aInfo.data);
  73. LOG_INFO_S("授权中继数量:" + std::to_string(aInfo.trunkNum));
  74. LOG_INFO_S("授权坐席数量:" + std::to_string(aInfo.agentNum));
  75. if (!SoftAuth::GetInstance()->isExpire()) // 授权到期,关闭程序
  76. {
  77. LOG_WARN("授权到期,自动关闭程序!");
  78. return 0;
  79. }
  80. std::thread(std::bind(AuthFun)).detach();
  81. CConfig *cfg = CConfig::GetInstance();
  82. if (!cfg->load())
  83. {
  84. LOG_WARN_S("配置文件加载失败!");
  85. cfg->write();
  86. return 0;
  87. }
  88. if (CFsProxy::GetInstance().init())
  89. {
  90. LOG_INFO_S("程序初始化完成,开始运行...");
  91. CFsProxy::GetInstance().run();
  92. }
  93. else
  94. LOG_ERROR_S("程序初始化失败,程序即将关闭");
  95. CFsProxy::GetInstance().release();
  96. return 0;
  97. }