From cc115713e1c74164c530576d305c6448de6dc59c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AF=BB=E6=AC=A2?= Date: Tue, 11 Jan 2022 14:17:10 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E8=A1=A5=E5=85=85=E7=BE=A4?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E5=8F=91=E9=80=81=E5=89=8D=E5=90=8E=E5=9B=9E?= =?UTF-8?q?=E8=B0=83=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- callback/general.go | 53 ++++++++++++++++++++++++++++++++ callback/group.go | 15 +++++++++ callback/message.go | 74 ++++++++------------------------------------- 3 files changed, 80 insertions(+), 62 deletions(-) create mode 100644 callback/general.go create mode 100644 callback/group.go diff --git a/callback/general.go b/callback/general.go new file mode 100644 index 0000000..b9bc2df --- /dev/null +++ b/callback/general.go @@ -0,0 +1,53 @@ +package callback + +// 通用消息结构体 + +// TIMMessage 消息体 +type TIMMessage struct { + MsgType string `json:"MsgType"` // 消息元素类别;目前支持的消息对象包括:TIMTextElem(文本消息),TIMLocationElem(位置消息),TIMFaceElem(表情消息),TIMCustomElem(自定义消息),TIMSoundElem(语音消息),TIMImageElem(图像消息),TIMFileElem(文件消息),TIMVideoFileElem(视频消息) + MsgContent TIMMessageContent `json:"MsgContent"` // 消息元素的内容,不同的 MsgType 有不同的 MsgContent 格式 +} + +// TIMMessageContent 消息结构体 +// https://cloud.tencent.com/document/product/269/2720 +type TIMMessageContent struct { + Text string `json:"Text"` // [TIMTextElem]消息内容 + Desc string `json:"Desc"` // [TIMLocationElem]地理位置描述信息。 | [TIMCustomElem]自定义消息描述信息。 + Latitude float64 `json:"Latitude"` // [TIMLocationElem]纬度 + Longitude float64 `json:"Longitude"` // [TIMLocationElem]经度 + Index int `json:"Index"` // [TIMFaceElem]表情索引,用户自定义 + Data string `json:"Data"` // [TIMFaceElem]额外数据 | [TIMCustomElem]自定义消息数据。 + Ext string `json:"Ext"` // [TIMCustomElem]扩展字段 + Sound string `json:"Sound"` // [TIMCustomElem]自定义 APNs 推送铃音 + URL string `json:"Url"` // [TIMSoundElem]语音下载地址,可通过该 URL 地址直接下载相应语音 | [TIMFileElem]文件下载标记 + UUID string `json:"UUID"` // [TIMSoundElem]语音的唯一标识,客户端用于索引语音的键值 | [TIMImageElem]图片的唯一标识 | [TIMFileElem]文件的唯一标识 + Size int `json:"Size"` // [TIMSoundElem]语音数据大小,单位:字节。 + Second int `json:"Second"` // [TIMSoundElem]语音时长,单位:秒。 + DownloadFlag int `json:"Download_Flag"` // [TIMSoundElem]语音下载方式标记。目前 Download_Flag 取值只能为2,表示可通过Url字段值的 URL 地址直接下载语音。 | [TIMFileElem]文件下载方式标记 + ImageFormat int `json:"ImageFormat"` // [TIMImageElem]图片格式。JPG = 1,GIF = 2,PNG = 3,BMP = 4,其他 = 255 + ImageInfoArray []TIMMessageImageInfoArray `json:"ImageInfoArray"` // [TIMImageElem]原图、缩略图或者大图下载信息 + FileSize int `json:"FileSize"` // [TIMFileElem]文件数据大小,单位:字节 + FileName string `json:"FileName"` // [TIMFileElem]文件名称 + VideoURL string `json:"VideoUrl"` // [TIMVideoFileElem]视频下载地址。可通过该 URL 地址直接下载相应视频 + VideoUUID string `json:"VideoUUID"` // [TIMVideoFileElem]视频的唯一标识,客户端用于索引视频的键值 + VideoSize int `json:"VideoSize"` // [TIMVideoFileElem]视频数据大小,单位:字节 + VideoSecond int `json:"VideoSecond"` // [TIMVideoFileElem]视频时长,单位:秒 + VideoFormat string `json:"VideoFormat"` // [TIMVideoFileElem]视频格式,例如 mp4 + VideoDownloadFlag int `json:"VideoDownloadFlag"` // [TIMVideoFileElem]视频下载方式标记。目前 VideoDownloadFlag 取值只能为2,表示可通过VideoUrl字段值的 URL 地址直接下载视频 + ThumbURL string `json:"ThumbUrl"` // [TIMVideoFileElem]视频缩略图下载地址。可通过该 URL 地址直接下载相应视频缩略图 + ThumbUUID string `json:"ThumbUUID"` // [TIMVideoFileElem]视频缩略图的唯一标识,客户端用于索引视频缩略图的键值 + ThumbSize int `json:"ThumbSize"` // [TIMVideoFileElem]缩略图大小,单位:字节 + ThumbWidth int `json:"ThumbWidth"` // [TIMVideoFileElem]缩略图宽度,单位为像素 + ThumbHeight int `json:"ThumbHeight"` // [TIMVideoFileElem]缩略图高度,单位为像素 + ThumbFormat string `json:"ThumbFormat"` // [TIMVideoFileElem]缩略图格式,例如 JPG、BMP 等 + ThumbDownloadFlag int `json:"ThumbDownloadFlag"` // [TIMVideoFileElem]视频缩略图下载方式标记。目前 ThumbDownloadFlag 取值只能为2,表示可通过ThumbUrl字段值的 URL 地址直接下载视频缩略图 +} + +// TIMMessageImageInfoArray 图片消息数组 +type TIMMessageImageInfoArray struct { + Type int `json:"Type"` // 图片类型: 1-原图,2-大图,3-缩略图 + Size int `json:"Size"` // 图片数据大小,单位:字节 + Width int `json:"Width"` // 图片宽度,单位为像素 + Height int `json:"Height"` // 图片高度,单位为像素 + URL string `json:"URL"` // 图片下载地址 +} diff --git a/callback/group.go b/callback/group.go new file mode 100644 index 0000000..5b7df3d --- /dev/null +++ b/callback/group.go @@ -0,0 +1,15 @@ +package callback + +// GroupMessageCallbackData 群消息回调 +type GroupMessageCallbackData struct { + CallbackCommand string `json:"CallbackCommand"` // 回调命令 + GroupId string `json:"GroupId"` // 群组 ID + Type string `json:"Type"` // 群组类型 Work(好友工作群) | Public(陌生人社交群) | Meeting(临时会议群) | AVChatRoom(直播群) | Community(社群) + FromAccount string `json:"From_Account"` // 发送者 + OperatorAccount string `json:"Operator_Account"` // 请求的发起者 + Random int `json:"Random"` // 随机数 + OnlineOnlyFlag int `json:"OnlineOnlyFlag"` // 在线消息,为1,否则为0;直播群忽略此属性,为默认值0 + MsgSeq int `json:"MsgSeq"` // 消息序列号,一条消息的唯一标示,群聊消息使用 MsgSeq 进行排序,MsgSeq 值越大消息越靠后 + MsgTime int `json:"MsgTime"` // 消息发送的时间戳,对应后台 Server 时间 + MsgBody []TIMMessage `json:"MsgBody"` // 消息体 +} diff --git a/callback/message.go b/callback/message.go index d234b8e..50f1fdc 100644 --- a/callback/message.go +++ b/callback/message.go @@ -2,66 +2,16 @@ package callback // MessageCallbackData 单聊消息回调数据 type MessageCallbackData struct { - MsgBody []MessageCallbackMsgBody `json:"MsgBody"` // 消息体 - CallbackCommand string `json:"CallbackCommand"` // 回调命令 - FromAccount string `json:"From_Account"` // 发送者帐号 - ToAccount string `json:"To_Account"` // 接收者帐号 - MsgRandom int `json:"MsgRandom"` // 消息随机数 - MsgSeq int `json:"MsgSeq"` // 消息序列号 - MsgTime int `json:"MsgTime"` // 消息的发送时间戳,单位为秒 - MsgKey string `json:"MsgKey"` //消息的唯一标识,可用于 REST API 撤回单聊消息 - OnlineOnlyFlag int `json:"OnlineOnlyFlag"` //在线消息,为1,否则为0 - SendMsgResult int `json:"SendMsgResult"` // 消息发送之后独有 - ErrorInfo string `json:"ErrorInfo"` // 消息发送之后独有 - UnreadMsgNum int `json:"UnreadMsgNum"` // 消息发送之后独有 -} - -// MessageCallbackMsgBody 消息体 -type MessageCallbackMsgBody struct { - MsgType string `json:"MsgType"` // 消息元素类别;目前支持的消息对象包括:TIMTextElem(文本消息),TIMLocationElem(位置消息),TIMFaceElem(表情消息),TIMCustomElem(自定义消息),TIMSoundElem(语音消息),TIMImageElem(图像消息),TIMFileElem(文件消息),TIMVideoFileElem(视频消息) - MsgContent MessageCallbackMsgContent `json:"MsgContent"` // 消息元素的内容,不同的 MsgType 有不同的 MsgContent 格式 -} - -// MessageCallbackMsgContent 消息结构体 -// https://cloud.tencent.com/document/product/269/2720 -type MessageCallbackMsgContent struct { - Text string `json:"Text"` // [TIMTextElem]消息内容 - Desc string `json:"Desc"` // [TIMLocationElem]地理位置描述信息。 | [TIMCustomElem]自定义消息描述信息。 - Latitude float64 `json:"Latitude"` // [TIMLocationElem]纬度 - Longitude float64 `json:"Longitude"` // [TIMLocationElem]经度 - Index int `json:"Index"` // [TIMFaceElem]表情索引,用户自定义 - Data string `json:"Data"` // [TIMFaceElem]额外数据 | [TIMCustomElem]自定义消息数据。 - Ext string `json:"Ext"` // [TIMCustomElem]扩展字段 - Sound string `json:"Sound"` // [TIMCustomElem]自定义 APNs 推送铃音 - URL string `json:"Url"` // [TIMSoundElem]语音下载地址,可通过该 URL 地址直接下载相应语音 | [TIMFileElem]文件下载标记 - UUID string `json:"UUID"` // [TIMSoundElem]语音的唯一标识,客户端用于索引语音的键值 | [TIMImageElem]图片的唯一标识 | [TIMFileElem]文件的唯一标识 - Size int `json:"Size"` // [TIMSoundElem]语音数据大小,单位:字节。 - Second int `json:"Second"` // [TIMSoundElem]语音时长,单位:秒。 - DownloadFlag int `json:"Download_Flag"` // [TIMSoundElem]语音下载方式标记。目前 Download_Flag 取值只能为2,表示可通过Url字段值的 URL 地址直接下载语音。 | [TIMFileElem]文件下载方式标记 - ImageFormat int `json:"ImageFormat"` // [TIMImageElem]图片格式。JPG = 1,GIF = 2,PNG = 3,BMP = 4,其他 = 255 - ImageInfoArray []MessageCallbackMsgImageInfoArray `json:"ImageInfoArray"` // [TIMImageElem]原图、缩略图或者大图下载信息 - FileSize int `json:"FileSize"` // [TIMFileElem]文件数据大小,单位:字节 - FileName string `json:"FileName"` // [TIMFileElem]文件名称 - VideoURL string `json:"VideoUrl"` // [TIMVideoFileElem]视频下载地址。可通过该 URL 地址直接下载相应视频 - VideoUUID string `json:"VideoUUID"` // [TIMVideoFileElem]视频的唯一标识,客户端用于索引视频的键值 - VideoSize int `json:"VideoSize"` // [TIMVideoFileElem]视频数据大小,单位:字节 - VideoSecond int `json:"VideoSecond"` // [TIMVideoFileElem]视频时长,单位:秒 - VideoFormat string `json:"VideoFormat"` // [TIMVideoFileElem]视频格式,例如 mp4 - VideoDownloadFlag int `json:"VideoDownloadFlag"` // [TIMVideoFileElem]视频下载方式标记。目前 VideoDownloadFlag 取值只能为2,表示可通过VideoUrl字段值的 URL 地址直接下载视频 - ThumbURL string `json:"ThumbUrl"` // [TIMVideoFileElem]视频缩略图下载地址。可通过该 URL 地址直接下载相应视频缩略图 - ThumbUUID string `json:"ThumbUUID"` // [TIMVideoFileElem]视频缩略图的唯一标识,客户端用于索引视频缩略图的键值 - ThumbSize int `json:"ThumbSize"` // [TIMVideoFileElem]缩略图大小,单位:字节 - ThumbWidth int `json:"ThumbWidth"` // [TIMVideoFileElem]缩略图宽度,单位为像素 - ThumbHeight int `json:"ThumbHeight"` // [TIMVideoFileElem]缩略图高度,单位为像素 - ThumbFormat string `json:"ThumbFormat"` // [TIMVideoFileElem]缩略图格式,例如 JPG、BMP 等 - ThumbDownloadFlag int `json:"ThumbDownloadFlag"` // [TIMVideoFileElem]视频缩略图下载方式标记。目前 ThumbDownloadFlag 取值只能为2,表示可通过ThumbUrl字段值的 URL 地址直接下载视频缩略图 -} - -// MessageCallbackMsgImageInfoArray 图片消息数组 -type MessageCallbackMsgImageInfoArray struct { - Type int `json:"Type"` // 图片类型: 1-原图,2-大图,3-缩略图 - Size int `json:"Size"` // 图片数据大小,单位:字节 - Width int `json:"Width"` // 图片宽度,单位为像素 - Height int `json:"Height"` // 图片高度,单位为像素 - URL string `json:"URL"` // 图片下载地址 + MsgBody []TIMMessage `json:"MsgBody"` // 消息体 + CallbackCommand string `json:"CallbackCommand"` // 回调命令 + FromAccount string `json:"From_Account"` // 发送者帐号 + ToAccount string `json:"To_Account"` // 接收者帐号 + MsgRandom int `json:"MsgRandom"` // 消息随机数 + MsgSeq int `json:"MsgSeq"` // 消息序列号 + MsgTime int `json:"MsgTime"` // 消息的发送时间戳,单位为秒 + MsgKey string `json:"MsgKey"` //消息的唯一标识,可用于 REST API 撤回单聊消息 + OnlineOnlyFlag int `json:"OnlineOnlyFlag"` //在线消息,为1,否则为0 + SendMsgResult int `json:"SendMsgResult"` // 消息发送之后独有 + ErrorInfo string `json:"ErrorInfo"` // 消息发送之后独有 + UnreadMsgNum int `json:"UnreadMsgNum"` // 消息发送之后独有 }