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