diff --git a/Readme.md b/Readme.md index 7a435e5..0a4fc74 100644 --- a/Readme.md +++ b/Readme.md @@ -204,6 +204,20 @@ sysctl -w kernel.core_pattern=core_%t_%s_%d_%e 查看帮助`man 5 core`。 +## 企业微信 + +```xml + + + + 1749032507 + + + 7512037417818888268 + 1000003 + +``` + ## 微信公众号对接 1. 公众号管理网页:设置与开发→基本配置→服务器配置。 diff --git a/WeChat/Corporation/Context.cpp b/WeChat/Corporation/Context.cpp index c476d01..7d49346 100644 --- a/WeChat/Corporation/Context.cpp +++ b/WeChat/Corporation/Context.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include namespace WeChat { @@ -155,9 +156,21 @@ void Context::registerMoneyNote() { auto echostr = params.find("echostr"); wxcpt.VerifyURL((*msg_signature).value, (*timestamp).value, (*nonce).value, (*echostr).value, reply); } else { - LOG(info) << "received: " << request.body(); + std::string message; + wxcpt.DecryptMsg((*msg_signature).value, (*timestamp).value, (*nonce).value, request.body(), message); + boost::property_tree::ptree ptree; + std::istringstream iss(message); + boost::property_tree::read_xml(iss, ptree); + if (ptree.count("xml.Content") > 0) { + std::string content = ptree.get("xml.Content"); + LOG(info) << "content: " << content; + } + ptree.put("xml.Content","i hate you."); + std::ostringstream oss; + boost::property_tree::write_xml(oss,ptree); + wxcpt.EncryptMsg(oss.str(), (*timestamp).value, (*nonce).value, reply); } - + LOG(info) << "reply: " << reply; http::response s{boost::beast::http::status::ok, request.version()}; s.set(http::field::server, BOOST_BEAST_VERSION_STRING); diff --git a/WeChat/Corporation/WXBizMsgCrypt.cpp b/WeChat/Corporation/WXBizMsgCrypt.cpp index c6b13f4..1aa2757 100644 --- a/WeChat/Corporation/WXBizMsgCrypt.cpp +++ b/WeChat/Corporation/WXBizMsgCrypt.cpp @@ -76,7 +76,7 @@ int WXBizMsgCrypt::DecryptMsg(const std::string &sMsgSignature, const std::strin boost::property_tree::ptree ptree; std::istringstream iss(sPostData); boost::property_tree::read_xml(iss, ptree); - std::string sEncryptMsg = ptree.get("Encrypt"); + std::string sEncryptMsg = ptree.get("xml.Encrypt"); // 2.validate signature if (0 != ValidateSignature(sMsgSignature, sTimeStamp, sNonce, sEncryptMsg)) { @@ -390,10 +390,10 @@ void WXBizMsgCrypt::GenNeedEncryptData(const std::string &sReplyMsg, std::string int WXBizMsgCrypt::GenReturnXml(const std::string &sEncryptMsg, const std::string &sSignature, const std::string &sTimeStamp, const std::string &sNonce, std::string &sResult) { boost::property_tree::ptree ptree; - ptree.put("Encrypt", sEncryptMsg); - ptree.put("MsgSignature", sSignature); - ptree.put("TimeStamp", sTimeStamp); - ptree.put("Nonce", sNonce); + ptree.put("xml.Encrypt", sEncryptMsg); + ptree.put("xml.MsgSignature", sSignature); + ptree.put("xml.TimeStamp", sTimeStamp); + ptree.put("xml.Nonce", sNonce); std::ostringstream oss; boost::property_tree::write_xml(oss, ptree);