-
Notifications
You must be signed in to change notification settings - Fork 157
/
callback.go
69 lines (57 loc) · 1.74 KB
/
callback.go
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
58
59
60
61
62
63
64
65
66
67
68
69
package models
import (
"encoding/xml"
"github.com/ArtisanCloud/PowerWeChat/v3/src/kernel/contract"
)
type Callback struct {
XMLName xml.Name `xml:"xml"`
Text string `xml:",chardata"`
ToUserName string `xml:"ToUserName" json:"ToUserName"`
AgentID string `xml:"AgentID" json:"AgentID"`
Encrypt string `xml:"Encrypt" json:"Encrypt"`
}
const (
CALLBACK_MSG_TYPE_EVENT = "event"
CALLBACK_MSG_TYPE_TEXT = "text"
CALLBACK_MSG_TYPE_IMAGE = "image"
CALLBACK_MSG_TYPE_VOICE = "voice"
CALLBACK_MSG_TYPE_VIDEO = "video"
CALLBACK_MSG_TYPE_LOCATION = "location"
CALLBACK_MSG_TYPE_LINK = "link"
)
type CallbackMessageHeader struct {
contract.EventInterface
XMLName xml.Name `xml:"xml"`
Text string `xml:",chardata"`
ToUserName string `xml:"ToUserName"`
FromUserName string `xml:"FromUserName"`
CreateTime string `xml:"CreateTime"`
MsgType string `xml:"MsgType"`
Event string `xml:"Event"`
ChangeType string `xml:"ChangeType"`
Content []byte
}
func (header CallbackMessageHeader) GetToUserName() string {
return header.ToUserName
}
func (header CallbackMessageHeader) GetFromUserName() string {
return header.FromUserName
}
func (header CallbackMessageHeader) GetCreateTime() string {
return header.CreateTime
}
func (header CallbackMessageHeader) GetMsgType() string {
return header.MsgType
}
func (header CallbackMessageHeader) GetEvent() string {
return header.Event
}
func (header CallbackMessageHeader) GetChangeType() string {
return header.ChangeType
}
func (header CallbackMessageHeader) ReadMessage(msg interface{}) error {
return xml.Unmarshal(header.Content, msg)
}
func (header CallbackMessageHeader) GetContent() []byte {
return header.Content
}