Skip to content

Commit

Permalink
update handler
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidAlphaFox committed Jan 15, 2019
1 parent b48bf7c commit 69358de
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ ai_wx_message_handler可以用来处理`接收普通消息`和`接收事件消

`Module`为项目中真正处理用户消息的模块,该模块需要支持以下行为

-callback handle_message(maps:maps()) -> binary().
-callback handle_event(maps:maps())-> binary().
-callback handle_message(string(),maps:maps()) -> binary().
-callback handle_event(string(),maps:maps())-> binary().

* `handle_message`用来处理用户消息
* `handle_event`用来处理关注,扫码,菜单等事件
* `handle_message`用来处理用户消息,第一个参数为MsgType
* `handle_event`用来处理关注,扫码,菜单等事件,第一个参数为Event

它们都会接受一个map作为参数,该map为微信公众平台[消息管理](https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421140453)中描述的消息的键值对,如下面例子

Expand Down
10 changes: 6 additions & 4 deletions src/ai_wx_message_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

-export([init/2]).

-callback handle_message(maps:maps()) -> binary().
-callback handle_event(maps:maps())-> binary().
-callback handle_message(string(),maps:maps()) -> binary().
-callback handle_event(string(),maps:maps())-> binary().


init(Req,State)->
Expand Down Expand Up @@ -69,8 +69,10 @@ process(Handler,Map)->
MsgType = maps:get('MsgType',Map),
try
if
MsgType == "event" -> Handler:handle_event(Map);
true -> Handler:handle_message(Map)
MsgType == "event" ->
Key = maps:get('Event',Map),
Handler:handle_event(Key,Map);
true -> Handler:handle_message(MsgType,Map)
end
catch
_Reason:_Error -> error
Expand Down

0 comments on commit 69358de

Please sign in to comment.