wxserver
ver v0.3.4
C++ Header-only enterprise WeChat message push server
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();
Add a callback function when a message is received
[&server]( const ws::Request &req, ws::Message &res){}
user_id
The id of the message sendercontent
message content. set_user(user_id)
Specify the user to reply to, the default is the message sender
set_content(MsgType, data)
Specify message reply content
MsgType | info |
---|---|
text | text |
markdown | markdown subset |
image | Picture(path) |
file | 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 | Running address |
port | running port |
enable_console_logger | Log console output, false does not output |
logging_path | Log file, null does not output to file |
weixin | info |
---|---|
AgentId | Located at mybusiness/xxx/AgentId |
CorpID | Located in My Business/Business Information/Business ID |
CorpSecret | Located in Application Management/xxx/Secret |
Token and EncodingAESKey | Located in Application Management/xxx/Function/Settings API Receive/ |
Note: The following are the configuration files required in the example, not required for wxserver
bot | info |
---|---|
bot | "hugging_face" or "chatgpt" |
proxy | Http proxy address, set to null if not required |
proxy_port | Http proxy port, set to null if not required |
hugging_face | info |
---|---|
model | Conversational required, such as ingen51/DialoGPT-medium-GPT4 |
token | HuggingFace token |
openai | info |
---|---|
model | Such as "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