linux版本中间件

main.cpp 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. SoftAuth::GetInstance()->getMachineCode(hardc);
  54. std::cout << "机器码:" << hardc << std::endl;
  55. std::string code;// = "MWEyZGZmYzctYTVjNC00OWEwLTgxNTgtMTQ3YjNmYTA3Zjc4CjIwMjAwNzE2";
  56. std::cout << "请输入授权码:" << std::endl;
  57. std::cin >> code;
  58. if (!SoftAuth::GetInstance()->AuthV2(code))
  59. {
  60. LOG_WARN("授权验证失败,自动关闭程序!");
  61. CFsProxy::GetInstance().release();
  62. //exit(EXIT_SUCCESS);
  63. return 0;
  64. }
  65. }
  66. AuthInfo aInfo;
  67. SoftAuth::GetInstance()->getAuthInfo(aInfo);
  68. LOG_INFO_S("授权到期时间:" + aInfo.data);
  69. LOG_INFO_S("授权中继数量:" + std::to_string(aInfo.trunkNum));
  70. LOG_INFO_S("授权坐席数量:" + std::to_string(aInfo.agentNum));
  71. if (!SoftAuth::GetInstance()->isExpire()) // 授权到期,关闭程序
  72. {
  73. LOG_WARN("授权到期,自动关闭程序!");
  74. return 0;
  75. }
  76. std::thread(std::bind(AuthFun)).detach();
  77. CConfig *cfg = CConfig::GetInstance();
  78. if (!cfg->load())
  79. {
  80. LOG_WARN_S("配置文件加载失败!");
  81. cfg->write();
  82. return 0;
  83. }
  84. if (CFsProxy::GetInstance().init())
  85. {
  86. LOG_INFO_S("程序初始化完成,开始运行...");
  87. CFsProxy::GetInstance().run();
  88. }
  89. else
  90. LOG_ERROR_S("程序初始化失败,程序即将关闭");
  91. CFsProxy::GetInstance().release();
  92. return 0;
  93. }