add wx code.
Some checks failed
Deploy / Build (push) Failing after 13s

This commit is contained in:
2025-06-04 18:07:46 +08:00
parent 0c7e06f3db
commit edab6cfa30
7 changed files with 563 additions and 9 deletions

View File

@ -1,14 +1,18 @@
#include "Context.h"
#include "Base/HttpSession.h"
#include "Base/Messages.h"
#include "Core/Logger.h"
#include "Core/MessageManager.h"
#include "Http/Utility.h"
#include "WXBizMsgCrypt.h"
#include <boost/asio/defer.hpp>
#include <boost/beast/core.hpp>
#include <boost/beast/version.hpp>
#include <boost/format.hpp>
#include <boost/json/object.hpp>
#include <boost/json/parse.hpp>
#include <boost/json/serialize.hpp>
#include <boost/url/parse.hpp>
namespace WeChat {
namespace Corporation {
@ -127,13 +131,43 @@ void Context::updateAccessToken() {
void Context::registerMoneyNote() {
// 接口说明: https://developer.work.weixin.qq.com/document/10514
// https://amass.fun/api/v1/wx/moneynote
// /api/v1/wx/moneynote?msg_signature=1096371bf526609f8aaacc247b3bebf2fbe15969&timestamp=1749021023&nonce=1748464240&echostr=1jccl4g1jk%2FMqIHQ445D9yOikKpcKkYOCMCLxqPSpKBtkMuKAuLGe8c6dbsTN5LZmRy0a45mxGvpqntvb3Vvxg%3D%3D
using namespace Core;
using namespace Older;
using namespace boost::urls;
using namespace boost::beast;
auto manager = Singleton<MessageManager>::instance();
manager->publish<RegisterUrlHandler>(
"/api/v1/wx/moneynote",
[this](HttpSession &session, const HttpRequest &request, const matches &matches) { LOG(info) << request.target(); });
// clang-format off
manager->publish<RegisterUrlHandler>("/api/v1/wx/moneynote", [this](HttpSession &session, const HttpRequest &request, const matches &matches) {
auto path = boost::urls::parse_origin_form(request.target());
auto params = path->params();
auto msg_signature = params.find("msg_signature");
auto timestamp = params.find("timestamp");
auto nonce = params.find("nonce");
constexpr auto token = "BqnhzhsRqIJXO5k";
constexpr auto encodingAESKey = "XMZ74tSRRe9MtEsEc9ihBTmvXxOisDrrFsukmcoPJR4";
constexpr auto corpid = "ww1a786851749bdadc";
std::string reply;
Tencent::WXBizMsgCrypt wxcpt(token, encodingAESKey, corpid);
if (request.method() == http::verb::get) {
auto echostr = params.find("echostr");
wxcpt.VerifyURL((*msg_signature).value, (*timestamp).value, (*nonce).value, (*echostr).value, reply);
} else {
LOG(info) << "received: " << request.body();
}
LOG(info) << "reply: " << reply;
http::response<boost::beast::http::string_body> s{boost::beast::http::status::ok, request.version()};
s.set(http::field::server, BOOST_BEAST_VERSION_STRING);
s.set(http::field::content_type, "application/json;charset=UTF-8");
s.keep_alive(request.keep_alive());
s.body() = reply;
s.prepare_payload();
session.reply(std::move(s));
});
// clang-format on
}
} // namespace Corporation