PhmsRequest.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #include "PhmsRequest.h"
  2. #include "Poco/MD5Engine.h"
  3. #include "Util.h"
  4. #include "GlobalTerminalLogoString.h"
  5. using namespace Poco;
  6. string CPhmsRequest::m_stringUsername = "";
  7. string CPhmsRequest::m_stringPassword = "";
  8. CPhmsRequest::CPhmsRequest(void)
  9. {
  10. }
  11. CPhmsRequest::~CPhmsRequest(void)
  12. {
  13. }
  14. CPhmsRequest::CPhmsRequest(CPhmsRequest& phmsRequest)
  15. {
  16. this->m_phmsRequestHead = phmsRequest.GetPhmsRequestHead();
  17. this->m_phmsRequestBody = phmsRequest.GetPhmsRequestBody();
  18. this->m_stringFilePath = phmsRequest.GetFilePath();
  19. }
  20. CPhmsRequest::CPhmsRequest(CPhmsRequestHead& phmsRequestHead, CPhmsRequestBody& phmsRequestBody, string stringFilePath)
  21. :m_phmsRequestHead(phmsRequestHead), m_phmsRequestBody(phmsRequestBody), m_stringFilePath(stringFilePath)
  22. {
  23. }
  24. CPhmsRequest& CPhmsRequest::operator=(CPhmsRequest& phmsRequest)
  25. {
  26. this->m_phmsRequestHead = phmsRequest.GetPhmsRequestHead();
  27. this->m_phmsRequestBody = phmsRequest.GetPhmsRequestBody();
  28. this->m_stringFilePath = phmsRequest.GetFilePath();
  29. return *this;
  30. }
  31. CPhmsRequestHead& CPhmsRequest::GetPhmsRequestHead()
  32. {
  33. return this->m_phmsRequestHead;
  34. }
  35. CPhmsRequestBody& CPhmsRequest::GetPhmsRequestBody()
  36. {
  37. return this->m_phmsRequestBody;
  38. }
  39. string CPhmsRequest::GetFilePath()
  40. {
  41. return this->m_stringFilePath;
  42. }
  43. string CPhmsRequest::GetUsername()
  44. {
  45. return CPhmsRequest::m_stringUsername;
  46. }
  47. string CPhmsRequest::GetPassword()
  48. {
  49. return CPhmsRequest::m_stringPassword;
  50. }
  51. //Setter
  52. void CPhmsRequest::SetPhmsRequestHead(CPhmsRequestHead& phmsRequestHead)
  53. {
  54. m_phmsRequestHead = phmsRequestHead;
  55. }
  56. void CPhmsRequest::SetPhmsRequestBody(CPhmsRequestBody& phmsRequestBody)
  57. {
  58. m_phmsRequestBody = phmsRequestBody;
  59. }
  60. void CPhmsRequest::SetFilePath(string stringFilePath)
  61. {
  62. m_stringFilePath = stringFilePath;
  63. }
  64. void CPhmsRequest::SetUsername(string stringUsername)
  65. {
  66. CPhmsRequest::m_stringUsername = stringUsername;
  67. }
  68. void CPhmsRequest::SetPassword(string stringPassword)
  69. {
  70. CPhmsRequest::m_stringPassword = stringPassword;
  71. }
  72. //用户名和密码具体保存到哪里以后再说
  73. string CPhmsRequest::GenerateAndSetSign()
  74. {
  75. string username;
  76. string password;
  77. //获得用户名和密码
  78. {
  79. username = CPhmsRequest::GetUsername();
  80. password = CPhmsRequest::GetPassword();
  81. if(username.size()==0 || password.size()==0)
  82. {
  83. username = g_stringUsername;
  84. password = g_stringPassword;
  85. }
  86. }
  87. string md5_1;
  88. string stringSrc1 = username+password;
  89. md5_1 = CUtil::GetMd5(stringSrc1.c_str(), stringSrc1.size());
  90. string stringSrc2;
  91. stringSrc2 = md5_1 + m_phmsRequestHead.GetVersion() + m_phmsRequestHead.GetOperationCode() + m_phmsRequestHead.GetSessionId() +
  92. m_phmsRequestHead.GetMessageFormat() + m_phmsRequestBody.GetXmlContent();
  93. string md5_2 ;
  94. md5_2 = CUtil::GetMd5(stringSrc2.c_str(), stringSrc2.size());
  95. m_phmsRequestHead.SetSign(md5_2);
  96. // cout<<username<<":"<<password<<endl;
  97. // cout<<m_phmsRequestHead.GetSessionId()<<endl;
  98. // cout<<m_phmsRequestHead.GetVersion()<<endl;
  99. // cout<<m_phmsRequestHead.GetOperationCode()<<endl;
  100. // cout<<m_phmsRequestHead.GetMessageFormat()<<endl;
  101. // cout<<m_phmsRequestBody.GetXmlContent()<<endl;
  102. // cout<<"md5_1:"<<md5_1<<endl;
  103. // cout<<"md5_2:"<<md5_2<<endl;
  104. return md5_2;
  105. }
  106. bool CPhmsRequest::ValidataPhmsRequest()
  107. {
  108. if(!m_phmsRequestHead.ValidatePhmsRequestHead())
  109. {
  110. return false;
  111. }
  112. if(m_phmsRequestHead.GetPhmsRequestMessageFormat()==WRONG_PHMS_REQUEST_MESSAGE_FORMAT)
  113. {
  114. return false;
  115. }
  116. if(m_phmsRequestHead.GetPhmsRequestMessageFormat()==HAVE_PHMS_REQUEST_BODY && m_phmsRequestBody.GetXmlContent().size()==0)
  117. {
  118. return false;
  119. }
  120. if(m_phmsRequestHead.GetPhmsRequestMessageFormat()==NO_PHMS_REQUEST_BODY && m_phmsRequestBody.GetXmlContent().size()!=0)
  121. {
  122. return false;
  123. }
  124. return true;
  125. }
  126. string CPhmsRequest::ToString()
  127. {
  128. return m_phmsRequestHead.ToString()+m_phmsRequestBody.ToString();
  129. }