github.com/chanxuehong/wechat@v0.0.0-20230222024006-36f0325263cd/mp/message/mass/mass2group/msg.go (about) 1 package mass2group 2 3 import ( 4 "github.com/chanxuehong/wechat/mp/core" 5 ) 6 7 const ( 8 MsgTypeText core.MsgType = "text" 9 MsgTypeImage core.MsgType = "image" 10 MsgTypeVoice core.MsgType = "voice" 11 MsgTypeVideo core.MsgType = "mpvideo" 12 MsgTypeNews core.MsgType = "mpnews" 13 MsgTypeWxCard core.MsgType = "wxcard" 14 ) 15 16 type MsgHeader struct { 17 Filter struct { 18 GroupId int64 `json:"group_id"` 19 } `json:"filter"` 20 MsgType core.MsgType `json:"msgtype"` 21 } 22 23 type Text struct { 24 MsgHeader 25 Text struct { 26 Content string `json:"content"` 27 } `json:"text"` 28 } 29 30 func NewText(groupId int64, content string) *Text { 31 var msg Text 32 msg.MsgType = MsgTypeText 33 msg.Filter.GroupId = groupId 34 msg.Text.Content = content 35 return &msg 36 } 37 38 type Image struct { 39 MsgHeader 40 Image struct { 41 MediaId string `json:"media_id"` 42 } `json:"image"` 43 } 44 45 func NewImage(groupId int64, mediaId string) *Image { 46 var msg Image 47 msg.MsgType = MsgTypeImage 48 msg.Filter.GroupId = groupId 49 msg.Image.MediaId = mediaId 50 return &msg 51 } 52 53 type Voice struct { 54 MsgHeader 55 Voice struct { 56 MediaId string `json:"media_id"` 57 } `json:"voice"` 58 } 59 60 func NewVoice(groupId int64, mediaId string) *Voice { 61 var msg Voice 62 msg.MsgType = MsgTypeVoice 63 msg.Filter.GroupId = groupId 64 msg.Voice.MediaId = mediaId 65 return &msg 66 } 67 68 type Video struct { 69 MsgHeader 70 Video struct { 71 MediaId string `json:"media_id"` 72 } `json:"mpvideo"` 73 } 74 75 // 新建视频消息 76 // 77 // NOTE: 对于临时素材, mediaId 应该通过 media.UploadVideo2 得到 78 func NewVideo(groupId int64, mediaId string) *Video { 79 var msg Video 80 msg.MsgType = MsgTypeVideo 81 msg.Filter.GroupId = groupId 82 msg.Video.MediaId = mediaId 83 return &msg 84 } 85 86 // 图文消息 87 type News struct { 88 MsgHeader 89 News struct { 90 MediaId string `json:"media_id"` 91 } `json:"mpnews"` 92 } 93 94 // 新建图文消息 95 // 96 // NOTE: 对于临时素材, mediaId 应该通过 media.UploadNews 得到 97 func NewNews(groupId int64, mediaId string) *News { 98 var msg News 99 msg.MsgType = MsgTypeNews 100 msg.Filter.GroupId = groupId 101 msg.News.MediaId = mediaId 102 return &msg 103 } 104 105 // 卡券消息 106 type WxCard struct { 107 MsgHeader 108 WxCard struct { 109 CardId string `json:"card_id"` 110 CardExt string `json:"card_ext,omitempty"` 111 } `json:"wxcard"` 112 } 113 114 // 新建卡券, 特别注意: 目前该接口仅支持填入非自定义code的卡券和预存模式的自定义code卡券. 115 // 116 // cardExt 可以为空 117 func NewWxCard(groupId int64, cardId, cardExt string) *WxCard { 118 var msg WxCard 119 msg.MsgType = MsgTypeWxCard 120 msg.Filter.GroupId = groupId 121 msg.WxCard.CardId = cardId 122 msg.WxCard.CardExt = cardExt 123 return &msg 124 }