View Source WeChat.Plug.WorkEventHandler (wechat v0.16.0)
企业微信推送消息处理器
Usage
请将入口路径设置为如下格式 /*xxx/:app/:agent
并将代码加到 router
里面:
scope "/wx/event/:app/:agent" do
forward "/", WeChat.Plug.WorkEventHandler, event_handler: &YourModule.handle_event/4
end
Options
event_handler
: 必填, 定义event_parser
: 可选, 定义, 默认值: &ServerMessage.EventHelper.parse_work_xml_event/4
Summary
Types
@type event_handler() :: (Plug.Conn.t(), WeChat.client(), WeChat.Work.Agent.t(), message :: map() -> WeChat.Plug.EventHandler.event_handler_return())
事件处理回调函数
@type event_parser() :: (params :: map(), body :: String.t() | map(), WeChat.client(), WeChat.Work.Agent.t() -> {:ok, WeChat.ServerMessage.EventHelper.data_type(), WeChat.ServerMessage.EventHelper.xml() | WeChat.ServerMessage.EventHelper.json()} | {:error, String.t()})
事件解析函数
Functions
Callback implementation for Plug.call/2
.
Link to this function
handle_event_request(conn, client, agent, event_parser, event_handler)
View Source@spec handle_event_request( Plug.Conn.t(), WeChat.client(), WeChat.Work.Agent.t(), event_parser(), event_handler() ) :: Plug.Conn.t()
接受事件推送
@spec validate_encrypted_request( Plug.Conn.t(), id :: String.t(), WeChat.token(), WeChat.ServerMessage.Encryptor.aes_key() ) :: Plug.Conn.t()
验证消息的确来自微信服务器