forked from silenceper/wechat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
button.go
215 lines (182 loc) · 5.53 KB
/
button.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
package menu
// Button 菜单按钮
type Button struct {
Type string `json:"type,omitempty"`
Name string `json:"name,omitempty"`
Key string `json:"key,omitempty"`
URL string `json:"url,omitempty"`
MediaID string `json:"media_id,omitempty"`
AppID string `json:"appid,omitempty"`
PagePath string `json:"pagepath,omitempty"`
SubButtons []*Button `json:"sub_button,omitempty"`
}
// SetSubButton 设置二级菜单
func (btn *Button) SetSubButton(name string, subButtons []*Button) *Button {
btn.Name = name
btn.SubButtons = subButtons
btn.Type = ""
btn.Key = ""
btn.URL = ""
btn.MediaID = ""
return btn
}
// SetClickButton btn 为click类型
func (btn *Button) SetClickButton(name, key string) *Button {
btn.Type = "click"
btn.Name = name
btn.Key = key
btn.URL = ""
btn.MediaID = ""
btn.SubButtons = nil
return btn
}
// SetViewButton view类型
func (btn *Button) SetViewButton(name, url string) *Button {
btn.Type = "view"
btn.Name = name
btn.URL = url
btn.Key = ""
btn.MediaID = ""
btn.SubButtons = nil
return btn
}
// SetScanCodePushButton 扫码推事件
func (btn *Button) SetScanCodePushButton(name, key string) *Button {
btn.Type = "scancode_push"
btn.Name = name
btn.Key = key
btn.URL = ""
btn.MediaID = ""
btn.SubButtons = nil
return btn
}
// SetScanCodeWaitMsgButton 设置 扫码推事件且弹出"消息接收中"提示框
func (btn *Button) SetScanCodeWaitMsgButton(name, key string) *Button {
btn.Type = "scancode_waitmsg"
btn.Name = name
btn.Key = key
btn.URL = ""
btn.MediaID = ""
btn.SubButtons = nil
return btn
}
// SetPicSysPhotoButton 设置弹出系统拍照发图按钮
func (btn *Button) SetPicSysPhotoButton(name, key string) *Button {
btn.Type = "pic_sysphoto"
btn.Name = name
btn.Key = key
btn.URL = ""
btn.MediaID = ""
btn.SubButtons = nil
return btn
}
// SetPicPhotoOrAlbumButton 设置弹出拍照或者相册发图类型按钮
func (btn *Button) SetPicPhotoOrAlbumButton(name, key string) *Button {
btn.Type = "pic_photo_or_album"
btn.Name = name
btn.Key = key
btn.URL = ""
btn.MediaID = ""
btn.SubButtons = nil
return btn
}
// SetPicWeixinButton 设置弹出微信相册发图器类型按钮
func (btn *Button) SetPicWeixinButton(name, key string) *Button {
btn.Type = "pic_weixin"
btn.Name = name
btn.Key = key
btn.URL = ""
btn.MediaID = ""
btn.SubButtons = nil
return btn
}
// SetLocationSelectButton 设置 弹出地理位置选择器 类型按钮
func (btn *Button) SetLocationSelectButton(name, key string) *Button {
btn.Type = "location_select"
btn.Name = name
btn.Key = key
btn.URL = ""
btn.MediaID = ""
btn.SubButtons = nil
return btn
}
// SetMediaIDButton 设置 下发消息(除文本消息) 类型按钮
func (btn *Button) SetMediaIDButton(name, mediaID string) *Button {
btn.Type = "media_id"
btn.Name = name
btn.MediaID = mediaID
btn.Key = ""
btn.URL = ""
btn.SubButtons = nil
return btn
}
// SetViewLimitedButton 设置 跳转图文消息URL 类型按钮
func (btn *Button) SetViewLimitedButton(name, mediaID string) *Button {
btn.Type = "view_limited"
btn.Name = name
btn.MediaID = mediaID
btn.Key = ""
btn.URL = ""
btn.SubButtons = nil
return btn
}
// SetMiniprogramButton 设置 跳转小程序 类型按钮 (公众号后台必须已经关联小程序)
func (btn *Button) SetMiniprogramButton(name, url, appID, pagePath string) *Button {
btn.Type = "miniprogram"
btn.Name = name
btn.URL = url
btn.AppID = appID
btn.PagePath = pagePath
btn.Key = ""
btn.MediaID = ""
btn.SubButtons = nil
return btn
}
// NewSubButton 二级菜单
func NewSubButton(name string, subButtons []*Button) *Button {
return (&Button{}).SetSubButton(name, subButtons)
}
// NewClickButton btn 为click类型
func NewClickButton(name, key string) *Button {
return (&Button{}).SetClickButton(name, key)
}
// NewViewButton view类型
func NewViewButton(name, url string) *Button {
return (&Button{}).SetViewButton(name, url)
}
// NewScanCodePushButton 扫码推事件
func NewScanCodePushButton(name, key string) *Button {
return (&Button{}).SetScanCodePushButton(name, key)
}
// NewScanCodeWaitMsgButton 扫码推事件且弹出"消息接收中"提示框
func NewScanCodeWaitMsgButton(name, key string) *Button {
return (&Button{}).SetScanCodeWaitMsgButton(name, key)
}
// NewPicSysPhotoButton 弹出系统拍照发图按钮
func NewPicSysPhotoButton(name, key string) *Button {
return (&Button{}).SetPicSysPhotoButton(name, key)
}
// NewPicPhotoOrAlbumButton 弹出拍照或者相册发图类型按钮
func NewPicPhotoOrAlbumButton(name, key string) *Button {
return (&Button{}).SetPicPhotoOrAlbumButton(name, key)
}
// NewPicWeixinButton 弹出微信相册发图器类型按钮
func NewPicWeixinButton(name, key string) *Button {
return (&Button{}).SetPicWeixinButton(name, key)
}
// NewLocationSelectButton 弹出地理位置选择器 类型按钮
func NewLocationSelectButton(name, key string) *Button {
return (&Button{}).SetLocationSelectButton(name, key)
}
// NewMediaIDButton 下发消息(除文本消息) 类型按钮
func NewMediaIDButton(name, mediaID string) *Button {
return (&Button{}).SetMediaIDButton(name, mediaID)
}
// NewViewLimitedButton 跳转图文消息URL 类型按钮
func NewViewLimitedButton(name, mediaID string) *Button {
return (&Button{}).SetViewLimitedButton(name, mediaID)
}
// NewMiniprogramButton 跳转小程序 类型按钮 (公众号后台必须已经关联小程序)
func NewMiniprogramButton(name, url, appID, pagePath string) *Button {
return (&Button{}).SetMiniprogramButton(name, url, appID, pagePath)
}