-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.h
39 lines (30 loc) · 1.08 KB
/
common.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#ifndef _COMMON_H
#define _COMMON_H
#include <iostream>
#include "httplib.h"
#include "nlohmann/json.hpp"
#include "spdlog/sinks/basic_file_sink.h"
#include "spdlog/sinks/daily_file_sink.h"
#include "spdlog/spdlog.h"
using namespace httplib;
using json = nlohmann::json;
// https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=<token id>
const std::string kWechatRobotWebhookUrl = "https://qyapi.weixin.qq.com";
class WeChatRobot : public httplib::Server {
public:
WeChatRobot(int port);
void GitLabWebhookHandler(const Request &req, Response &res);
void GrafanaWebhookHandler(const Request &req, Response &res);
void BuildPushEventAndSendWechat(std::string type, std::string id, json body);
void BuildMergeEventAndSendWechat(std::string id, json body);
void Run();
private:
inline std::vector<std::string> _split(const std::string &s, char delim);
private:
std::string _ip; // webhook http server bind ip
int _port; // webhook http server port
std::string _url; // wechat robot url;
std::shared_ptr<spdlog::logger> _logger;
httplib::Server _svr;
};
#endif