wxserver
ver v0.3.4
C++ Header-only 企业微信消息推送服务器
ws::Server server;
server.load_config("config.czh");
server.add_msg_handle(
[&server](const ws::Request &req, ws::Message &res)
{
res.set_content(ws::MsgType::text, "hello, world");
});
server.run();
添加当接受的消息时的回调函数
[&server](const ws::Request &req, ws::Message &res){}
user_id
消息发送者的idcontent
消息内容。set_user(user_id)
指定回复的用户,默认为消息发送者
set_content(MsgType, data)
指定消息回复内容
MsgType | info |
---|---|
text | 文本 |
markdown | markdown子集 |
image | 图片(path) |
file | 文件(path) |
server.add_msg_handle(
[&server](const ws::Request &req, ws::Message &res)
{
std::thread(
[req, &server]()
{
//do something
res.set_content(ws::MsgType::text, ret);
}).detach();
});
server.send_message({ws::MsgType::text, "hello", "caozhanhao"});
server.send_message({ws::MsgType::file, "LICENSE", "caozhanhao"});
server.send_message({ws::MsgType::image, "example.jpg", "caozhanhao"});
server.send_message({ws::MsgType::markdown, "`hello world`", "caozhanhao"});
// ... 同set_content
Server(std::string host, int port_, int agent_id, const std::string& token, const std::string encoding_aes_key,
const std::string corp_id, const std::string corp_secret,
bool enable_console_logger, const std::string& logging_path = "")
ws::Server server;
server.load_config("config.czh");
// or
// auto config = ws::parse_config("config.czh");
// server.load_config(config);
server | info |
---|---|
host | 运行地址 |
port | 运行端口 |
enable_console_logger | 日志控制台输出, false不输出 |
logging_path | 日志文件, null不输出到文件 |
weixin | info |
---|---|
AgentId | 位于我的企业/xxx/AgentId |
CorpID | 位于我的企业/企业信息/企业ID |
CorpSecret | 位于应用管理/xxx/Secret |
Token和EncodingAESKey | 位于应用管理/xxx/功能/设置API接收/ |
注:以下为示例中需要的配置文件,不是wxserver必须的
bot | info |
---|---|
bot | "hugging_face"或 "chatgpt" |
proxy | Http代理地址,不需要则设为null |
proxy_port | Http代理端口,不需要则设为null |
hugging_face | info |
---|---|
model | 需Conversational,如ingen51/DialoGPT-medium-GPT4 |
token | HuggingFace token |
openai | info |
---|---|
model | 如"gpt-3.5-turbo" |
token | OpenAI token |
g++ examples/src/main.cpp -I examples/src -I include -I thirdparty -I thirdparty/json/include -I thirdparty/libczh/include -lssl -lcrypto -lpthread -O2 -std=c++2a -o wxserver-linux
g++ examples/src/main.cpp -I examples/src -I "C:Program FilesOpenSSL-Win64include" -I include -I thirdparty -I thirdparty/json/include -I thirdparty/libczh/include -L "C:Program FilesOpenSSL-Win64lib" -lssl -lcrypto -l ws2_32 -l crypt32 -lpthread -O2 -std=c++2a -o wxserver-windows.exe