Explorar el Código

feat: add some mp messages

Your Name hace 3 años
padre
commit
2566decc98
Se han modificado 4 ficheros con 104 adiciones y 76 borrados
  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 Ver fichero

@@ -17,6 +17,11 @@ const (
17 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 25
 // ReceivedEncryptMessage 待解密数据
21 26
 type ReceivedEncryptMessage struct {
22 27
 	XMLName    xml.Name `xml:"xml"`
@@ -70,31 +75,3 @@ type AuthorizerEvent struct {
70 75
 	MsgType      CDATA    `xml:"MsgType"`
71 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 Ver fichero

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

+ 41
- 0
api/mp/event.go Ver fichero

@@ -0,0 +1,41 @@
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 Ver fichero

@@ -1,8 +1,24 @@
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 19
 // TextMessage 文本消息
4 20
 type TextMessage struct {
5
-	AuthorizerEvent
21
+	Message
6 22
 	Content CDATA `xml:"Content"`
7 23
 	MsgID   int64 `xml:"MsgId"`
8 24
 
@@ -10,60 +26,34 @@ type TextMessage struct {
10 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 29
 // ImageMessage 图片消息
20 30
 type ImageMessage struct {
21
-	AuthorizerEvent
31
+	Message
22 32
 	PicURL  CDATA `xml:"PicUrl"`
23 33
 	MediaID CDATA `xml:"MediaId"`
24 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 37
 // VoiceMessage 语音消息
34 38
 type VoiceMessage struct {
35
-	AuthorizerEvent
39
+	Message
36 40
 	MediaID     CDATA `xml:"MediaId"`
37 41
 	Format      CDATA `xml:"Format"`
38 42
 	Recognition CDATA `xml:"Recognition"`
39 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 46
 // VideoMessage 视频消息
49 47
 type VideoMessage struct {
50
-	AuthorizerEvent
48
+	Message
51 49
 	MediaID      CDATA `xml:"MediaId"`
52 50
 	ThumbMediaID CDATA `xml:"ThumbMediaId"`
53 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 54
 // MusicReplyMessage 回复音乐消息
65 55
 type MusicReplyMessage struct {
66
-	AuthorizerEvent
56
+	Message
67 57
 	Title        CDATA `xml:"Music>Title"`
68 58
 	Description  CDATA `xml:"Video>Description"`
69 59
 	MusicURL     CDATA `xml:"Video>MusicUrl"`
@@ -73,7 +63,7 @@ type MusicReplyMessage struct {
73 63
 
74 64
 // ShortVideoMessage 小视频消息
75 65
 type ShortVideoMessage struct {
76
-	AuthorizerEvent
66
+	Message
77 67
 	MediaID      CDATA `xml:"MediaId"`
78 68
 	ThumbMediaID CDATA `xml:"ThumbMediaId"`
79 69
 	MsgID        int64 `xml:"MsgId"`
@@ -81,7 +71,7 @@ type ShortVideoMessage struct {
81 71
 
82 72
 // LocationMessage 地理位置消息
83 73
 type LocationMessage struct {
84
-	AuthorizerEvent
74
+	Message
85 75
 	LocationX float64 `xml:"Location_X"`
86 76
 	LocationY float64 `xml:"Location_Y"`
87 77
 	Scale     int     `xml:"Scale"`
@@ -91,24 +81,50 @@ type LocationMessage struct {
91 81
 
92 82
 // LinkMessage 链接消息
93 83
 type LinkMessage struct {
94
-	AuthorizerEvent
84
+	Message
95 85
 	Title       CDATA `xml:"Title"`
96 86
 	Description CDATA `xml:"Description"`
97 87
 	URL         CDATA `xml:"Url"`
98 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 119
 	Title       CDATA `xml:"Title"`
104 120
 	Description CDATA `xml:"Description"`
105 121
 	PicURL      CDATA `xml:"PicUrl"`
106 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
 }