From ac18b24e355e7d3e921458a2fac7468894879846 Mon Sep 17 00:00:00 2001 From: coward Date: Fri, 5 Jan 2024 17:05:26 +0800 Subject: [PATCH] =?UTF-8?q?:art:=E6=96=B0=E5=A2=9E=E4=BA=86=E4=B8=80?= =?UTF-8?q?=E4=BA=9B=E7=BE=A4=E8=81=8A=E6=8E=A5=E5=8F=A3=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E4=BB=A5=E5=8F=8A=E6=96=87=E4=BB=B6=E5=9B=BE=E7=89=87=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E5=8F=91=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client.go | 132 ++++++++++++++++++++++++++++++++++++++++++++++++++++ request.go | 34 ++++++++++++++ response.go | 19 ++++++++ 3 files changed, 185 insertions(+) diff --git a/client.go b/client.go index f805dec..2e9c7f9 100644 --- a/client.go +++ b/client.go @@ -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 +} diff --git a/request.go b/request.go index 5be38f9..40c99bc 100644 --- a/request.go +++ b/request.go @@ -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"` +} diff --git a/response.go b/response.go index 112a6a4..a5ab7ad 100644 --- a/response.go +++ b/response.go @@ -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"` +}