2025-02-27 12:57:55 +00:00

49 lines
1.4 KiB
C++

#ifndef __CORPORATIONCONTEXT_H__
#define __CORPORATIONCONTEXT_H__
#include "Core/Singleton.h"
#include <boost/asio/steady_timer.hpp>
#include <boost/beast/http/string_body.hpp>
namespace WeChat {
namespace Corporation {
class Context : public std::enable_shared_from_this<Context> {
friend class Core::Singleton<Context>;
public:
enum MessageType {
Text,
Markdown,
};
using RequestType = boost::beast::http::request<boost::beast::http::string_body>;
void sendMessage(MessageType type, const std::string &message);
void start();
/**
* @brief
*
* @param request
* @example curl -H "Content-Type: application/json" -X POST -d '{"user_id": "123", "msg":"OK!" }'
* https://amass.fun/notify
*/
void notify(const RequestType &request);
protected:
Context(boost::asio::io_context &ioContext);
void updateAccessToken();
private:
boost::asio::io_context &m_ioContext;
boost::asio::steady_timer m_timer;
std::string m_accessToken;
constexpr static auto host = "qyapi.weixin.qq.com";
constexpr static auto port = "443";
constexpr static auto corpid = "ww1a786851749bdadc";
constexpr static auto corpsecret = "LlyJmYLIBOxJkQxkhwyqNVf550AUQ3JT2MT4yuS31i0";
constexpr static auto agentid = 1000002;
};
} // namespace Corporation
} // namespace WeChat
#endif // __CORPORATIONCONTEXT_H__