From ef99f24495bf0ff6ae468eb529ca58b45b09dd1b Mon Sep 17 00:00:00 2001 From: Yangtao Date: Fri, 28 Nov 2025 14:12:33 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E4=BA=91=E4=BF=A1?= =?UTF-8?q?=E7=BE=A4=E7=BB=84api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/common/netease/ImClient.go | 44 ++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/pkg/common/netease/ImClient.go b/pkg/common/netease/ImClient.go index 5cd7c7e..48ed179 100644 --- a/pkg/common/netease/ImClient.go +++ b/pkg/common/netease/ImClient.go @@ -735,6 +735,50 @@ func (client *ImClient) CreateChatGroup(ctx context.Context, ownerUserId string, return cast.ToString(body.Data.TeamInfo.TeamID), nil } +// GroupMsgSend 发送群消息 +func (client *ImClient) GroupMsgSend(from, tid, _type, content, msg string) error { + url := "https://api.netease.im/nimserver/msg/sendMsg.action" + httpMethod := common.HTTP_METHOD_POST + header := client.generateHeader() + sb := HyTools.NewStringBuilder() + sb.Append("from=" + from) + sb.Append("&") + sb.Append("ope=" + "1") + sb.Append("&") + sb.Append("to=" + tid) + sb.Append("&") + sb.Append("type=" + _type) // 0:文本消息1:图片消息2:语音消息3:视频消息4:地理位置消息6:文件消息10:提示消息100:自定义消息, + sb.Append("&") + sb.Append("body=" + content) + sb.Append("&") + sb.Append("antispam=true") + res, err := HyTools.HttpDo(httpMethod, url, header, sb.ToString()) + // code Integer 状态码 + // tid Long 网易云信服务器产生,群唯一标识 + // faccid String 入群失败的账号(accid)列表,格式为 JSONArray,如果创建时邀请的成员中存在加群数量超过限制的情况,会返回入群失败的 accid 以及附言(msg) + if err != nil { + // {"desc":"already register","code":414} + log.Info("GroupMsgSend %s:" + err.Error()) + return err + } else { + var resDTO CreateImRes + json.Unmarshal([]byte(res), &resDTO) + if resDTO.Code != 200 { + log.Info("GroupMsgSend %s:" + resDTO.Desc) + } else { + log.Info("GroupMsgSend %s:" + res) + } + } + var body map[string]any + if errJson := json.Unmarshal([]byte(res), &body); errJson != nil { + return errJson + } + if int(body["code"].(float64)) != 200 { + return errors.New(body["desc"].(string)) + } + return nil +} + // 创建云信账户 // 创建高级群,创建时即可通过设置群成员列表邀请用户入群。 // 建群成功会返回 tid,网易云信服务器产生,群唯一标识,该字段需要保存,以便于加人与踢人等后续操作。