github.com/chanxuehong/wechat@v0.0.0-20230222024006-36f0325263cd/mp/message/callback/request/msg.go (about) 1 package request 2 3 import ( 4 "github.com/chanxuehong/wechat/mp/core" 5 ) 6 7 const ( 8 // 普通消息类型 9 MsgTypeText core.MsgType = "text" // 文本消息 10 MsgTypeImage core.MsgType = "image" // 图片消息 11 MsgTypeVoice core.MsgType = "voice" // 语音消息 12 MsgTypeVideo core.MsgType = "video" // 视频消息 13 MsgTypeShortVideo core.MsgType = "shortvideo" // 小视频消息 14 MsgTypeLocation core.MsgType = "location" // 地理位置消息 15 MsgTypeLink core.MsgType = "link" // 链接消息 16 ) 17 18 // 文本消息 19 type Text struct { 20 XMLName struct{} `xml:"xml" json:"-"` 21 core.MsgHeader 22 MsgId int64 `xml:"MsgId" json:"MsgId"` // 消息id, 64位整型 23 Content string `xml:"Content" json:"Content"` // 文本消息内容 24 BizMsgMenuId int64 `xml:"bizmsgmenuid" json:"bizmsgmenuid"` //客服消息菜单重的menuid 25 } 26 27 func GetText(msg *core.MixedMsg) *Text { 28 return &Text{ 29 MsgHeader: msg.MsgHeader, 30 MsgId: msg.MsgId, 31 Content: msg.Content, 32 BizMsgMenuId: msg.BizMsgMenuId, 33 } 34 } 35 36 // 图片消息 37 type Image struct { 38 XMLName struct{} `xml:"xml" json:"-"` 39 core.MsgHeader 40 MsgId int64 `xml:"MsgId" json:"MsgId"` // 消息id, 64位整型 41 MediaId string `xml:"MediaId" json:"MediaId"` // 图片消息媒体id, 可以调用多媒体文件下载接口拉取数据. 42 PicURL string `xml:"PicUrl" json:"PicUrl"` // 图片链接 43 } 44 45 func GetImage(msg *core.MixedMsg) *Image { 46 return &Image{ 47 MsgHeader: msg.MsgHeader, 48 MsgId: msg.MsgId, 49 MediaId: msg.MediaId, 50 PicURL: msg.PicURL, 51 } 52 } 53 54 // 语音消息 55 type Voice struct { 56 XMLName struct{} `xml:"xml" json:"-"` 57 core.MsgHeader 58 MsgId int64 `xml:"MsgId" json:"MsgId"` // 消息id, 64位整型 59 MediaId string `xml:"MediaId" json:"MediaId"` // 语音消息媒体id, 可以调用多媒体文件下载接口拉取该媒体 60 Format string `xml:"Format" json:"Format"` // 语音格式, 如amr, speex等 61 62 // 语音识别结果, UTF8编码, 63 // NOTE: 需要开通语音识别功能, 否则该字段为空, 即使开通了语音识别该字段还是有可能为空 64 Recognition string `xml:"Recognition,omitempty" json:"Recognition,omitempty"` 65 } 66 67 func GetVoice(msg *core.MixedMsg) *Voice { 68 return &Voice{ 69 MsgHeader: msg.MsgHeader, 70 MsgId: msg.MsgId, 71 MediaId: msg.MediaId, 72 Format: msg.Format, 73 Recognition: msg.Recognition, 74 } 75 } 76 77 // 视频消息 78 type Video struct { 79 XMLName struct{} `xml:"xml" json:"-"` 80 core.MsgHeader 81 MsgId int64 `xml:"MsgId" json:"MsgId"` // 消息id, 64位整型 82 MediaId string `xml:"MediaId" json:"MediaId"` // 视频消息媒体id, 可以调用多媒体文件下载接口拉取数据. 83 ThumbMediaId string `xml:"ThumbMediaId" json:"ThumbMediaId"` // 视频消息缩略图的媒体id, 可以调用多媒体文件下载接口拉取数据. 84 } 85 86 func GetVideo(msg *core.MixedMsg) *Video { 87 return &Video{ 88 MsgHeader: msg.MsgHeader, 89 MsgId: msg.MsgId, 90 MediaId: msg.MediaId, 91 ThumbMediaId: msg.ThumbMediaId, 92 } 93 } 94 95 // 小视频消息 96 type ShortVideo struct { 97 XMLName struct{} `xml:"xml" json:"-"` 98 core.MsgHeader 99 MsgId int64 `xml:"MsgId" json:"MsgId"` // 消息id, 64位整型 100 MediaId string `xml:"MediaId" json:"MediaId"` // 视频消息媒体id, 可以调用多媒体文件下载接口拉取数据. 101 ThumbMediaId string `xml:"ThumbMediaId" json:"ThumbMediaId"` // 视频消息缩略图的媒体id, 可以调用多媒体文件下载接口拉取数据. 102 } 103 104 func GetShortVideo(msg *core.MixedMsg) *ShortVideo { 105 return &ShortVideo{ 106 MsgHeader: msg.MsgHeader, 107 MsgId: msg.MsgId, 108 MediaId: msg.MediaId, 109 ThumbMediaId: msg.ThumbMediaId, 110 } 111 } 112 113 // 地理位置消息 114 type Location struct { 115 XMLName struct{} `xml:"xml" json:"-"` 116 core.MsgHeader 117 MsgId int64 `xml:"MsgId" json:"MsgId"` // 消息id, 64位整型 118 LocationX float64 `xml:"Location_X" json:"Location_X"` // 地理位置纬度 119 LocationY float64 `xml:"Location_Y" json:"Location_Y"` // 地理位置经度 120 Scale int `xml:"Scale" json:"Scale"` // 地图缩放大小 121 Label string `xml:"Label" json:"Label"` // 地理位置信息 122 } 123 124 func GetLocation(msg *core.MixedMsg) *Location { 125 return &Location{ 126 MsgHeader: msg.MsgHeader, 127 MsgId: msg.MsgId, 128 LocationX: msg.LocationX, 129 LocationY: msg.LocationY, 130 Scale: msg.Scale, 131 Label: msg.Label, 132 } 133 } 134 135 // 链接消息 136 type Link struct { 137 XMLName struct{} `xml:"xml" json:"-"` 138 core.MsgHeader 139 MsgId int64 `xml:"MsgId" json:"MsgId"` // 消息id, 64位整型 140 Title string `xml:"Title" json:"Title"` // 消息标题 141 Description string `xml:"Description" json:"Description"` // 消息描述 142 URL string `xml:"Url" json:"Url"` // 消息链接 143 } 144 145 func GetLink(msg *core.MixedMsg) *Link { 146 return &Link{ 147 MsgHeader: msg.MsgHeader, 148 MsgId: msg.MsgId, 149 Title: msg.Title, 150 Description: msg.Description, 151 URL: msg.URL, 152 } 153 }