This commit is contained in:
14
Readme.md
14
Readme.md
@ -204,6 +204,20 @@ sysctl -w kernel.core_pattern=core_%t_%s_%d_%e
|
|||||||
|
|
||||||
查看帮助`man 5 core`。
|
查看帮助`man 5 core`。
|
||||||
|
|
||||||
|
## 企业微信
|
||||||
|
|
||||||
|
```xml
|
||||||
|
<xml>
|
||||||
|
<ToUserName><![CDATA[ww1a786851749bdadc]]></ToUserName>
|
||||||
|
<FromUserName><![CDATA[LuoCai]]></FromUserName>
|
||||||
|
<CreateTime>1749032507</CreateTime>
|
||||||
|
<MsgType><![CDATA[text]]></MsgType>
|
||||||
|
<Content><![CDATA[今天去哪里?]]></Content>
|
||||||
|
<MsgId>7512037417818888268</MsgId>
|
||||||
|
<AgentID>1000003</AgentID>
|
||||||
|
</xml>
|
||||||
|
```
|
||||||
|
|
||||||
## 微信公众号对接
|
## 微信公众号对接
|
||||||
|
|
||||||
1. 公众号管理网页:设置与开发→基本配置→服务器配置。
|
1. 公众号管理网页:设置与开发→基本配置→服务器配置。
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include <boost/json/object.hpp>
|
#include <boost/json/object.hpp>
|
||||||
#include <boost/json/parse.hpp>
|
#include <boost/json/parse.hpp>
|
||||||
#include <boost/json/serialize.hpp>
|
#include <boost/json/serialize.hpp>
|
||||||
|
#include <boost/property_tree/xml_parser.hpp>
|
||||||
#include <boost/url/parse.hpp>
|
#include <boost/url/parse.hpp>
|
||||||
|
|
||||||
namespace WeChat {
|
namespace WeChat {
|
||||||
@ -155,7 +156,19 @@ void Context::registerMoneyNote() {
|
|||||||
auto echostr = params.find("echostr");
|
auto echostr = params.find("echostr");
|
||||||
wxcpt.VerifyURL((*msg_signature).value, (*timestamp).value, (*nonce).value, (*echostr).value, reply);
|
wxcpt.VerifyURL((*msg_signature).value, (*timestamp).value, (*nonce).value, (*echostr).value, reply);
|
||||||
} else {
|
} 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<std::string>("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;
|
LOG(info) << "reply: " << reply;
|
||||||
|
@ -76,7 +76,7 @@ int WXBizMsgCrypt::DecryptMsg(const std::string &sMsgSignature, const std::strin
|
|||||||
boost::property_tree::ptree ptree;
|
boost::property_tree::ptree ptree;
|
||||||
std::istringstream iss(sPostData);
|
std::istringstream iss(sPostData);
|
||||||
boost::property_tree::read_xml(iss, ptree);
|
boost::property_tree::read_xml(iss, ptree);
|
||||||
std::string sEncryptMsg = ptree.get<std::string>("Encrypt");
|
std::string sEncryptMsg = ptree.get<std::string>("xml.Encrypt");
|
||||||
|
|
||||||
// 2.validate signature
|
// 2.validate signature
|
||||||
if (0 != ValidateSignature(sMsgSignature, sTimeStamp, sNonce, sEncryptMsg)) {
|
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,
|
int WXBizMsgCrypt::GenReturnXml(const std::string &sEncryptMsg, const std::string &sSignature, const std::string &sTimeStamp,
|
||||||
const std::string &sNonce, std::string &sResult) {
|
const std::string &sNonce, std::string &sResult) {
|
||||||
boost::property_tree::ptree ptree;
|
boost::property_tree::ptree ptree;
|
||||||
ptree.put("Encrypt", sEncryptMsg);
|
ptree.put("xml.Encrypt", sEncryptMsg);
|
||||||
ptree.put("MsgSignature", sSignature);
|
ptree.put("xml.MsgSignature", sSignature);
|
||||||
ptree.put("TimeStamp", sTimeStamp);
|
ptree.put("xml.TimeStamp", sTimeStamp);
|
||||||
ptree.put("Nonce", sNonce);
|
ptree.put("xml.Nonce", sNonce);
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
boost::property_tree::write_xml(oss, ptree);
|
boost::property_tree::write_xml(oss, ptree);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user