Older/Server/WeChatContext/CorporationContext.h

45 lines
1.3 KiB
C
Raw Normal View History

2023-07-21 16:17:01 +08:00
#ifndef __CORPORATIONCONTEXT_H__
#define __CORPORATIONCONTEXT_H__
2024-11-10 18:33:39 +08:00
#include "Singleton.h"
2023-07-21 16:17:01 +08:00
#include <boost/asio/steady_timer.hpp>
#include <boost/beast/http/string_body.hpp>
2024-11-10 18:33:39 +08:00
class CorporationContext : public std::enable_shared_from_this<CorporationContext> {
friend class Amass::Singleton<CorporationContext>;
2023-07-21 16:17:01 +08:00
public:
enum MessageType {
Text,
Markdown,
};
using RequestType = boost::beast::http::request<boost::beast::http::string_body>;
2024-11-10 18:33:39 +08:00
void sendMessage(MessageType type, const std::string &message);
void start();
2023-07-21 16:17:01 +08:00
/**
* @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:
2024-11-10 18:33:39 +08:00
CorporationContext(boost::asio::io_context &ioContext);
2023-07-21 16:17:01 +08:00
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;
};
#endif // __CORPORATIONCONTEXT_H__