github.com/chanxuehong/wechat@v0.0.0-20230222024006-36f0325263cd/mp/menu/event.go (about) 1 package menu 2 3 import ( 4 "github.com/chanxuehong/wechat/mp/core" 5 ) 6 7 const ( 8 EventTypeClick core.EventType = "CLICK" // 点击菜单拉取消息时的事件推送 9 EventTypeView core.EventType = "VIEW" // 点击菜单跳转链接时的事件推送 10 11 // 请注意, 下面的事件仅支持微信iPhone5.4.1以上版本, 和Android5.4以上版本的微信用户, 12 // 旧版本微信用户点击后将没有回应, 开发者也不能正常接收到事件推送. 13 EventTypeScanCodePush core.EventType = "scancode_push" // 扫码推事件的事件推送 14 EventTypeScanCodeWaitMsg core.EventType = "scancode_waitmsg" // 扫码推事件且弹出"消息接收中"提示框的事件推送 15 EventTypePicSysPhoto core.EventType = "pic_sysphoto" // 弹出系统拍照发图的事件推送 16 EventTypePicPhotoOrAlbum core.EventType = "pic_photo_or_album" // 弹出拍照或者相册发图的事件推送 17 EventTypePicWeixin core.EventType = "pic_weixin" // 弹出微信相册发图器的事件推送 18 EventTypeLocationSelect core.EventType = "location_select" // 弹出地理位置选择器的事件推送 19 ) 20 21 // CLICK: 点击菜单拉取消息时的事件推送 22 type ClickEvent struct { 23 XMLName struct{} `xml:"xml" json:"-"` 24 core.MsgHeader 25 EventType core.EventType `xml:"Event" json:"Event"` // 事件类型, CLICK 26 EventKey string `xml:"EventKey" json:"EventKey"` // 事件KEY值, 与自定义菜单接口中KEY值对应 27 } 28 29 func GetClickEvent(msg *core.MixedMsg) *ClickEvent { 30 return &ClickEvent{ 31 MsgHeader: msg.MsgHeader, 32 EventType: msg.EventType, 33 EventKey: msg.EventKey, 34 } 35 } 36 37 // VIEW: 点击菜单跳转链接时的事件推送 38 type ViewEvent struct { 39 XMLName struct{} `xml:"xml" json:"-"` 40 core.MsgHeader 41 EventType core.EventType `xml:"Event" json:"Event"` // 事件类型, VIEW 42 EventKey string `xml:"EventKey" json:"EventKey"` // 事件KEY值, 设置的跳转URL 43 MenuId int64 `xml:"MenuId,omitempty" json:"MenuId,omitempty"` // 菜单ID,如果是个性化菜单,则可以通过这个字段,知道是哪个规则的菜单被点击了。 44 } 45 46 func GetViewEvent(msg *core.MixedMsg) *ViewEvent { 47 return &ViewEvent{ 48 MsgHeader: msg.MsgHeader, 49 EventType: msg.EventType, 50 EventKey: msg.EventKey, 51 MenuId: msg.MenuId, 52 } 53 } 54 55 // scancode_push: 扫码推事件的事件推送 56 type ScanCodePushEvent struct { 57 XMLName struct{} `xml:"xml" json:"-"` 58 core.MsgHeader 59 EventType core.EventType `xml:"Event" json:"Event"` // 事件类型, scancode_push 60 EventKey string `xml:"EventKey" json:"EventKey"` // 事件KEY值, 由开发者在创建菜单时设定 61 62 ScanCodeInfo *struct { 63 ScanType string `xml:"ScanType" json:"ScanType"` // 扫描类型, 一般是qrcode 64 ScanResult string `xml:"ScanResult" json:"ScanResult"` // 扫描结果, 即二维码对应的字符串信息 65 } `xml:"ScanCodeInfo,omitempty" json:"ScanCodeInfo,omitempty"` 66 } 67 68 func GetScanCodePushEvent(msg *core.MixedMsg) *ScanCodePushEvent { 69 return &ScanCodePushEvent{ 70 MsgHeader: msg.MsgHeader, 71 EventType: msg.EventType, 72 EventKey: msg.EventKey, 73 ScanCodeInfo: msg.ScanCodeInfo, 74 } 75 } 76 77 // scancode_waitmsg: 扫码推事件且弹出"消息接收中"提示框的事件推送 78 type ScanCodeWaitMsgEvent struct { 79 XMLName struct{} `xml:"xml" json:"-"` 80 core.MsgHeader 81 EventType core.EventType `xml:"Event" json:"Event"` // 事件类型, scancode_waitmsg 82 EventKey string `xml:"EventKey" json:"EventKey"` // 事件KEY值, 由开发者在创建菜单时设定 83 84 ScanCodeInfo *struct { 85 ScanType string `xml:"ScanType" json:"ScanType"` // 扫描类型, 一般是qrcode 86 ScanResult string `xml:"ScanResult" json:"ScanResult"` // 扫描结果, 即二维码对应的字符串信息 87 } `xml:"ScanCodeInfo,omitempty" json:"ScanCodeInfo,omitempty"` 88 } 89 90 func GetScanCodeWaitMsgEvent(msg *core.MixedMsg) *ScanCodeWaitMsgEvent { 91 return &ScanCodeWaitMsgEvent{ 92 MsgHeader: msg.MsgHeader, 93 EventType: msg.EventType, 94 EventKey: msg.EventKey, 95 ScanCodeInfo: msg.ScanCodeInfo, 96 } 97 } 98 99 // pic_sysphoto: 弹出系统拍照发图的事件推送 100 type PicSysPhotoEvent struct { 101 XMLName struct{} `xml:"xml" json:"-"` 102 core.MsgHeader 103 EventType core.EventType `xml:"Event" json:"Event"` // 事件类型, pic_sysphoto 104 EventKey string `xml:"EventKey" json:"EventKey"` // 事件KEY值, 由开发者在创建菜单时设定 105 106 SendPicsInfo *struct { 107 Count int `xml:"Count" json:"Count"` 108 PicList []struct { 109 PicMd5Sum string `xml:"PicMd5Sum" json:"PicMd5Sum"` 110 } `xml:"PicList>item,omitempty" json:"PicList,omitempty"` 111 } `xml:"SendPicsInfo,omitempty" json:"SendPicsInfo,omitempty"` 112 } 113 114 func GetPicSysPhotoEvent(msg *core.MixedMsg) *PicSysPhotoEvent { 115 return &PicSysPhotoEvent{ 116 MsgHeader: msg.MsgHeader, 117 EventType: msg.EventType, 118 EventKey: msg.EventKey, 119 SendPicsInfo: msg.SendPicsInfo, 120 } 121 } 122 123 // pic_photo_or_album: 弹出拍照或者相册发图的事件推送 124 type PicPhotoOrAlbumEvent struct { 125 XMLName struct{} `xml:"xml" json:"-"` 126 core.MsgHeader 127 EventType core.EventType `xml:"Event" json:"Event"` // 事件类型, pic_photo_or_album 128 EventKey string `xml:"EventKey" json:"EventKey"` // 事件KEY值, 由开发者在创建菜单时设定 129 130 SendPicsInfo *struct { 131 Count int `xml:"Count" json:"Count"` 132 PicList []struct { 133 PicMd5Sum string `xml:"PicMd5Sum" json:"PicMd5Sum"` 134 } `xml:"PicList>item,omitempty" json:"PicList,omitempty"` 135 } `xml:"SendPicsInfo,omitempty" json:"SendPicsInfo,omitempty"` 136 } 137 138 func GetPicPhotoOrAlbumEvent(msg *core.MixedMsg) *PicPhotoOrAlbumEvent { 139 return &PicPhotoOrAlbumEvent{ 140 MsgHeader: msg.MsgHeader, 141 EventType: msg.EventType, 142 EventKey: msg.EventKey, 143 SendPicsInfo: msg.SendPicsInfo, 144 } 145 } 146 147 // pic_weixin: 弹出微信相册发图器的事件推送 148 type PicWeixinEvent struct { 149 XMLName struct{} `xml:"xml" json:"-"` 150 core.MsgHeader 151 EventType core.EventType `xml:"Event" json:"Event"` // 事件类型, pic_weixin 152 EventKey string `xml:"EventKey" json:"EventKey"` // 事件KEY值, 由开发者在创建菜单时设定 153 154 SendPicsInfo *struct { 155 Count int `xml:"Count" json:"Count"` 156 PicList []struct { 157 PicMd5Sum string `xml:"PicMd5Sum" json:"PicMd5Sum"` 158 } `xml:"PicList>item,omitempty" json:"PicList,omitempty"` 159 } `xml:"SendPicsInfo,omitempty" json:"SendPicsInfo,omitempty"` 160 } 161 162 func GetPicWeixinEvent(msg *core.MixedMsg) *PicWeixinEvent { 163 return &PicWeixinEvent{ 164 MsgHeader: msg.MsgHeader, 165 EventType: msg.EventType, 166 EventKey: msg.EventKey, 167 SendPicsInfo: msg.SendPicsInfo, 168 } 169 } 170 171 // location_select: 弹出地理位置选择器的事件推送 172 type LocationSelectEvent struct { 173 XMLName struct{} `xml:"xml" json:"-"` 174 core.MsgHeader 175 EventType core.EventType `xml:"Event" json:"Event"` // 事件类型, location_select 176 EventKey string `xml:"EventKey" json:"EventKey"` // 事件KEY值, 由开发者在创建菜单时设定 177 178 SendLocationInfo *struct { 179 LocationX float64 `xml:"Location_X" json:"Location_X"` // 地理位置纬度 180 LocationY float64 `xml:"Location_Y" json:"Location_Y"` // 地理位置经度 181 Scale int `xml:"Scale" json:"Scale"` // 精度, 可理解为精度或者比例尺, 越精细的话 scale越高 182 Label string `xml:"Label" json:"Label"` // 地理位置的字符串信息 183 PoiName string `xml:"Poiname" json:"Poiname"` // 朋友圈POI的名字, 可能为空 184 } `xml:"SendLocationInfo,omitempty" json:"SendLocationInfo,omitempty"` 185 } 186 187 func GetLocationSelectEvent(msg *core.MixedMsg) *LocationSelectEvent { 188 return &LocationSelectEvent{ 189 MsgHeader: msg.MsgHeader, 190 EventType: msg.EventType, 191 EventKey: msg.EventKey, 192 SendLocationInfo: msg.SendLocationInfo, 193 } 194 }