🎨新增了一些群聊接口支持以及文件图片消息发送

This commit is contained in:
coward 2024-01-05 17:05:26 +08:00
parent f83cb27fac
commit ac18b24e35
3 changed files with 185 additions and 0 deletions

132
client.go
View File

@ -192,3 +192,135 @@ func (w *WxHelper) SendText(param *SendText) (err error) {
return
}
// SendFileMsg
// @description: 发送文件
// @receiver w
// @param param
// @return err
func (w *WxHelper) SendFileMsg(param SendFileMsg) (err error) {
req := w.client.R()
req.Header.Set("Content-Type", "application/json")
req.SetBody(param)
_, err = req.SetResult(&w.tmpResult).Post(w.GetAddr("/api/sendFileMsg"))
if err != nil {
return fmt.Errorf("发送文件失败: %v", err.Error())
}
if w.tmpResult.Code == 0 {
return fmt.Errorf("发送文件失败: %v", w.tmpResult.Msg)
}
return
}
// SendImageMsg
// @description: 发送图片
// @receiver w
// @param param
// @return err
func (w *WxHelper) SendImageMsg(param SendImageMsg) (err error) {
req := w.client.R()
req.Header.Set("Content-Type", "application/json")
req.SetBody(param)
_, err = req.SetResult(&w.tmpResult).Post(w.GetAddr("/api/sendImagesMsg"))
if err != nil {
return fmt.Errorf("发送图片失败: %v", err.Error())
}
if w.tmpResult.Code <= 0 {
return fmt.Errorf("发送图片失败: %v", w.tmpResult.Msg)
}
return
}
// ForwardMsg
// @description: 转发消息
// @receiver w
// @param param
// @return err
func (w *WxHelper) ForwardMsg(param ForwardMsg) (err error) {
req := w.client.R()
req.Header.Set("Content-Type", "application/json")
req.SetBody(param)
_, err = req.SetResult(&w.tmpResult).Post(w.GetAddr("/api/forwardMsg"))
if err != nil {
return fmt.Errorf("转发消息失败: %v", err.Error())
}
if w.tmpResult.Code != 1 {
return fmt.Errorf("转发消息失败: %v", w.tmpResult.Msg)
}
return
}
// DecodeImage
// @description: 解码图片
// @receiver w
// @param param
// @return err
func (w *WxHelper) DecodeImage(param DecodeImage) (err error) {
req := w.client.R()
req.Header.Set("Content-Type", "application/json")
req.SetBody(param)
_, err = req.SetResult(&w.tmpResult).Post(w.GetAddr("/api/decodeImage"))
if err != nil {
return fmt.Errorf("解码图片失败: %v", err.Error())
}
if w.tmpResult.Code <= 0 {
return fmt.Errorf("解码图片失败: %v", w.tmpResult.Msg)
}
return
}
// GetChatRoomDetail
// @description: 获取群聊详情
// @receiver w
// @param param
// @return chatRoot
// @return err
func (w *WxHelper) GetChatRoomDetail(param ChatRoomId) (chatRoot *ChatRoomDetail, err error) {
req := w.client.R()
req.Header.Set("Content-Type", "application/json")
req.SetBody(param)
_, err = req.SetResult(&w.tmpResult).Post(w.GetAddr("/api/getChatRoomDetailInfo"))
if err != nil {
return nil, fmt.Errorf("获取群聊信息失败: %v", err.Error())
}
if w.tmpResult.Code != 1 {
return nil, fmt.Errorf("获取群聊信息失败: %v", w.tmpResult.Msg)
}
data, _ := json.Marshal(w.tmpResult.Data)
_ = json.Unmarshal(data, &chatRoot)
return
}
// GetChatRoomMember
// @description: 获取群聊人员
// @receiver w
// @param param
// @return members
// @return err
func (w *WxHelper) GetChatRoomMember(param ChatRoomId) (members *ChatRoomMembers, err error) {
req := w.client.R()
req.Header.Set("Content-Type", "application/json")
req.SetBody(param)
_, err = req.SetResult(&w.tmpResult).Post(w.GetAddr("/api/getMemberFromChatRoom"))
if err != nil {
return nil, fmt.Errorf("获取群聊人员信息失败: %v", err.Error())
}
if w.tmpResult.Code != 1 {
return nil, fmt.Errorf("获取群聊人员信息失败: %v", w.tmpResult.Msg)
}
data, _ := json.Marshal(w.tmpResult.Data)
_ = json.Unmarshal(data, &members)
return
}

View File

@ -24,3 +24,37 @@ type SendText struct {
Wxid string `json:"wxid"`
Msg string `json:"msg"`
}
// SendFileMsg
// @description: 发送文件
type SendFileMsg struct {
Wxid string `json:"wxid"`
FilePath string `json:"filePath"`
}
// SendImageMsg
// @description: 发送图片
type SendImageMsg struct {
Wxid string `json:"wxid"`
ImagePath string `json:"imagePath"`
}
// DecodeImage
// @description: 解码图片
type DecodeImage struct {
FilePath string `json:"filePath"`
StoreDir string `json:"storeDir"`
}
// ChatRoomId
// @description: 群聊ID
type ChatRoomId struct {
ChatRoomId string `json:"chatRoomId"`
}
// ForwardMsg
// @description: 转发消息
type ForwardMsg struct {
Wxid string `json:"wxid"`
MsgId string `json:"msgId"`
}

View File

@ -39,3 +39,22 @@ type Friend struct {
VerifyFlag int `json:"verifyFlag"`
Wxid string `json:"wxid"`
}
// ChatRoomDetail
// @description: 群聊详情
type ChatRoomDetail struct {
ChatRoomId string `json:"chatRoomId"`
Notice string `json:"notice"`
Admin string `json:"admin"`
Xml string `json:"xml"`
}
// ChatRoomMembers
// @description: 群聊人员信息
type ChatRoomMembers struct {
Admin string `json:"admin"`
AdminNickname string `json:"adminNickname"`
ChatRoomId string `json:"chatRoomId"`
MemberNickname string `json:"memberNickname"`
Members string `json:"members"`
}