-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathmock.js
57 lines (55 loc) · 1.08 KB
/
mock.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
function Wechat(){
this.handlers = {}
}
Wechat.prototype = {
middlewarify: function(){
const that = this
return function(req, res, next){
const message = JSON.parse(req.rawBody.fields.raw)
that.handlers[message.MsgType](message, req, res, next)
}
},
text: function(fn){
this.handlers.text = fn
return this
},
image: function(fn){
this.handlers.image = fn
return this
},
voice: function(fn){
this.handlers.voice = fn
return this
},
video: function(fn){
this.handlers.video = fn
return this
},
shortvideo: function(fn){
this.handlers.shortvideo = fn
return this
},
location: function(fn){
this.handlers.location = fn
return this
},
link: function(fn){
this.handlers.link = fn
return this
},
event: function(fn){
this.handlers.event = fn
return this
},
device_text: function(fn){
this.handlers.device_text = fn
return this
},
device_event: function(fn){
this.handlers.device_event = fn
return this
},
}
module.exports = function(){
return new Wechat()
}