浏览代码

feat: add some mp messages

Your Name 3 年前
父节点
当前提交
2566decc98
共有 4 个文件被更改,包括 104 次插入76 次删除
  1. 5
    28
      api/event/types.go
  2. 0
    6
      api/event/xml.go
  3. 41
    0
      api/mp/event.go
  4. 58
    42
      api/mp/message.go

+ 5
- 28
api/event/types.go 查看文件

17
 	INFO_TYPE_UNAUTHORIZED = "unauthorized"
17
 	INFO_TYPE_UNAUTHORIZED = "unauthorized"
18
 )
18
 )
19
 
19
 
20
+// CDATA 解析 xml cdata 字段
21
+type CDATA struct {
22
+	Value string `xml:",cdata"`
23
+}
24
+
20
 // ReceivedEncryptMessage 待解密数据
25
 // ReceivedEncryptMessage 待解密数据
21
 type ReceivedEncryptMessage struct {
26
 type ReceivedEncryptMessage struct {
22
 	XMLName    xml.Name `xml:"xml"`
27
 	XMLName    xml.Name `xml:"xml"`
70
 	MsgType      CDATA    `xml:"MsgType"`
75
 	MsgType      CDATA    `xml:"MsgType"`
71
 	Event        CDATA    `xml:"Event"`
76
 	Event        CDATA    `xml:"Event"`
72
 }
77
 }
73
-
74
-// SubscribeEvent 关注/取消关注事件
75
-// event subscribe(订阅)、unsubscribe(取消订阅)
76
-type SubscribeEvent struct {
77
-	AuthorizerEvent
78
-}
79
-
80
-// QRSceneEvent 扫描带参数二维码事件
81
-type QRSceneEvent struct {
82
-	AuthorizerEvent
83
-	EventKey CDATA `xml:"EventKey"`
84
-	Ticket   CDATA `xml:"Ticket"`
85
-}
86
-
87
-// LocationEvent 上报地理位置事件
88
-type LocationEvent struct {
89
-	AuthorizerEvent
90
-	Latitude  float64 `xml:"Latitude"`
91
-	Longitude float64 `xml:"Longitude"`
92
-	Precision float64 `xml:"Precision"`
93
-}
94
-
95
-// MenuEvent 自定义菜单事件
96
-// event 值为 CLICK
97
-type MenuEvent struct {
98
-	AuthorizerEvent
99
-	EventKey CDATA `xml:"EventKey"`
100
-}

+ 0
- 6
api/event/xml.go 查看文件

1
-package event
2
-
3
-// CDATA 解析 xml cdata 字段
4
-type CDATA struct {
5
-	Value string `xml:",cdata"`
6
-}

+ 41
- 0
api/mp/event.go 查看文件

1
+package mp
2
+
3
+import "encoding/xml"
4
+
5
+// Event 公众号事件
6
+type Event struct {
7
+	XMLName      xml.Name `xml:"xml"`
8
+	ToUserName   CDATA    `xml:"ToUserName"`
9
+	FromUserName CDATA    `xml:"FromUserName"`
10
+	CreateTime   int64    `xml:"CreateTime"`
11
+	MsgType      CDATA    `xml:"MsgType"`
12
+	Event        CDATA    `xml:"Event"`
13
+}
14
+
15
+// SubscribeEvent 关注/取消关注事件
16
+// event subscribe(订阅)、unsubscribe(取消订阅)
17
+type SubscribeEvent struct {
18
+	Event
19
+}
20
+
21
+// QRSceneEvent 扫描带参数二维码事件
22
+type QRSceneEvent struct {
23
+	Event
24
+	EventKey CDATA `xml:"EventKey"`
25
+	Ticket   CDATA `xml:"Ticket"`
26
+}
27
+
28
+// LocationEvent 上报地理位置事件
29
+type LocationEvent struct {
30
+	Event
31
+	Latitude  float64 `xml:"Latitude"`
32
+	Longitude float64 `xml:"Longitude"`
33
+	Precision float64 `xml:"Precision"`
34
+}
35
+
36
+// MenuEvent 自定义菜单事件
37
+// event 值为 CLICK
38
+type MenuEvent struct {
39
+	Event
40
+	EventKey CDATA `xml:"EventKey"`
41
+}

api/event/message.go → api/mp/message.go 查看文件

1
-package event
1
+package mp
2
+
3
+import "encoding/xml"
4
+
5
+// CDATA 解析 xml cdata 字段
6
+type CDATA struct {
7
+	Value string `xml:",cdata"`
8
+}
9
+
10
+// Message 公众号消息
11
+type Message struct {
12
+	XMLName      xml.Name `xml:"xml"`
13
+	ToUserName   CDATA    `xml:"ToUserName"`
14
+	FromUserName CDATA    `xml:"FromUserName"`
15
+	CreateTime   int64    `xml:"CreateTime"`
16
+	MsgType      CDATA    `xml:"MsgType"`
17
+}
2
 
18
 
3
 // TextMessage 文本消息
19
 // TextMessage 文本消息
4
 type TextMessage struct {
20
 type TextMessage struct {
5
-	AuthorizerEvent
21
+	Message
6
 	Content CDATA `xml:"Content"`
22
 	Content CDATA `xml:"Content"`
7
 	MsgID   int64 `xml:"MsgId"`
23
 	MsgID   int64 `xml:"MsgId"`
8
 
24
 
10
 	BizMsgMenuID int `xml:"bizmsgmenuid"`
26
 	BizMsgMenuID int `xml:"bizmsgmenuid"`
11
 }
27
 }
12
 
28
 
13
-// TextReplyMessage 回复文本消息
14
-type TextReplyMessage struct {
15
-	AuthorizerEvent
16
-	Content CDATA `xml:"Content"`
17
-}
18
-
19
 // ImageMessage 图片消息
29
 // ImageMessage 图片消息
20
 type ImageMessage struct {
30
 type ImageMessage struct {
21
-	AuthorizerEvent
31
+	Message
22
 	PicURL  CDATA `xml:"PicUrl"`
32
 	PicURL  CDATA `xml:"PicUrl"`
23
 	MediaID CDATA `xml:"MediaId"`
33
 	MediaID CDATA `xml:"MediaId"`
24
 	MsgID   int64 `xml:"MsgId"`
34
 	MsgID   int64 `xml:"MsgId"`
25
 }
35
 }
26
 
36
 
27
-// ImageReplyMessage 回复图片消息
28
-type ImageReplyMessage struct {
29
-	AuthorizerEvent
30
-	MediaID CDATA `xml:"Image>MediaId"`
31
-}
32
-
33
 // VoiceMessage 语音消息
37
 // VoiceMessage 语音消息
34
 type VoiceMessage struct {
38
 type VoiceMessage struct {
35
-	AuthorizerEvent
39
+	Message
36
 	MediaID     CDATA `xml:"MediaId"`
40
 	MediaID     CDATA `xml:"MediaId"`
37
 	Format      CDATA `xml:"Format"`
41
 	Format      CDATA `xml:"Format"`
38
 	Recognition CDATA `xml:"Recognition"`
42
 	Recognition CDATA `xml:"Recognition"`
39
 	MsgID       int64 `xml:"MsgId"`
43
 	MsgID       int64 `xml:"MsgId"`
40
 }
44
 }
41
 
45
 
42
-// VoiceReplyMessage 回复语音消息
43
-type VoiceReplyMessage struct {
44
-	AuthorizerEvent
45
-	MediaID CDATA `xml:"Voice>MediaId"`
46
-}
47
-
48
 // VideoMessage 视频消息
46
 // VideoMessage 视频消息
49
 type VideoMessage struct {
47
 type VideoMessage struct {
50
-	AuthorizerEvent
48
+	Message
51
 	MediaID      CDATA `xml:"MediaId"`
49
 	MediaID      CDATA `xml:"MediaId"`
52
 	ThumbMediaID CDATA `xml:"ThumbMediaId"`
50
 	ThumbMediaID CDATA `xml:"ThumbMediaId"`
53
 	MsgID        int64 `xml:"MsgId"`
51
 	MsgID        int64 `xml:"MsgId"`
54
 }
52
 }
55
 
53
 
56
-// VideoReplyMessage 回复视频消息
57
-type VideoReplyMessage struct {
58
-	AuthorizerEvent
59
-	MediaID     CDATA `xml:"Video>MediaId"`
60
-	Title       CDATA `xml:"Video>Title"`
61
-	Description CDATA `xml:"Video>Description"`
62
-}
63
-
64
 // MusicReplyMessage 回复音乐消息
54
 // MusicReplyMessage 回复音乐消息
65
 type MusicReplyMessage struct {
55
 type MusicReplyMessage struct {
66
-	AuthorizerEvent
56
+	Message
67
 	Title        CDATA `xml:"Music>Title"`
57
 	Title        CDATA `xml:"Music>Title"`
68
 	Description  CDATA `xml:"Video>Description"`
58
 	Description  CDATA `xml:"Video>Description"`
69
 	MusicURL     CDATA `xml:"Video>MusicUrl"`
59
 	MusicURL     CDATA `xml:"Video>MusicUrl"`
73
 
63
 
74
 // ShortVideoMessage 小视频消息
64
 // ShortVideoMessage 小视频消息
75
 type ShortVideoMessage struct {
65
 type ShortVideoMessage struct {
76
-	AuthorizerEvent
66
+	Message
77
 	MediaID      CDATA `xml:"MediaId"`
67
 	MediaID      CDATA `xml:"MediaId"`
78
 	ThumbMediaID CDATA `xml:"ThumbMediaId"`
68
 	ThumbMediaID CDATA `xml:"ThumbMediaId"`
79
 	MsgID        int64 `xml:"MsgId"`
69
 	MsgID        int64 `xml:"MsgId"`
81
 
71
 
82
 // LocationMessage 地理位置消息
72
 // LocationMessage 地理位置消息
83
 type LocationMessage struct {
73
 type LocationMessage struct {
84
-	AuthorizerEvent
74
+	Message
85
 	LocationX float64 `xml:"Location_X"`
75
 	LocationX float64 `xml:"Location_X"`
86
 	LocationY float64 `xml:"Location_Y"`
76
 	LocationY float64 `xml:"Location_Y"`
87
 	Scale     int     `xml:"Scale"`
77
 	Scale     int     `xml:"Scale"`
91
 
81
 
92
 // LinkMessage 链接消息
82
 // LinkMessage 链接消息
93
 type LinkMessage struct {
83
 type LinkMessage struct {
94
-	AuthorizerEvent
84
+	Message
95
 	Title       CDATA `xml:"Title"`
85
 	Title       CDATA `xml:"Title"`
96
 	Description CDATA `xml:"Description"`
86
 	Description CDATA `xml:"Description"`
97
 	URL         CDATA `xml:"Url"`
87
 	URL         CDATA `xml:"Url"`
98
 	MsgID       int64 `xml:"MsgId"`
88
 	MsgID       int64 `xml:"MsgId"`
99
 }
89
 }
100
 
90
 
101
-// ItemMessage 回复图文消息的单独一个item
102
-type ItemMessage struct {
91
+// ReplyTextMessage 回复文本消息
92
+type ReplyTextMessage struct {
93
+	Message
94
+	Content CDATA `xml:"Content"`
95
+}
96
+
97
+// ReplyImageMessage 回复图片消息
98
+type ReplyImageMessage struct {
99
+	Message
100
+	MediaID CDATA `xml:"Image>MediaId"`
101
+}
102
+
103
+// ReplyVoiceMessage 回复语音消息
104
+type ReplyVoiceMessage struct {
105
+	Message
106
+	MediaID CDATA `xml:"Voice>MediaId"`
107
+}
108
+
109
+// ReplyVideoMessage 回复视频消息
110
+type ReplyVideoMessage struct {
111
+	Message
112
+	MediaID     CDATA `xml:"Video>MediaId"`
113
+	Title       CDATA `xml:"Video>Title"`
114
+	Description CDATA `xml:"Video>Description"`
115
+}
116
+
117
+// ReplyItem 回复图文消息的单独一个item
118
+type ReplyItem struct {
103
 	Title       CDATA `xml:"Title"`
119
 	Title       CDATA `xml:"Title"`
104
 	Description CDATA `xml:"Description"`
120
 	Description CDATA `xml:"Description"`
105
 	PicURL      CDATA `xml:"PicUrl"`
121
 	PicURL      CDATA `xml:"PicUrl"`
106
 	URL         CDATA `xml:"Url"`
122
 	URL         CDATA `xml:"Url"`
107
 }
123
 }
108
 
124
 
109
-// NewsReplyMessage 回复图文消息
110
-type NewsReplyMessage struct {
111
-	AuthorizerEvent
112
-	ArticleCount int           `xml:"ArticleCount"`
113
-	Articles     []ItemMessage `xml:"Articles>item"`
125
+// ReplyNewsMessage 回复图文消息
126
+type ReplyNewsMessage struct {
127
+	Message
128
+	ArticleCount int         `xml:"ArticleCount"`
129
+	Articles     []ReplyItem `xml:"Articles>item"`
114
 }
130
 }