feat: 添加云信群组api

This commit is contained in:
Yangtao
2025-11-28 13:59:36 +08:00
parent 465eeb5699
commit e0fbc8567b

View File

@ -759,6 +759,8 @@ func (client *ImClient) CreateProGroup(tname, owner, announcement, avatar, msg s
sb.Append("&")
sb.Append("joinmode=" + "0")
sb.Append("&")
sb.Append("beinvitemode=" + "1")
sb.Append("&")
sb.Append("invitemode=" + "1") // 邀请权限即谁可以邀请他人入群0群主和管理员默认。1所有人
sb.Append("&")
sb.Append("teamMemberLimit=" + "3000") // 最大群成员数(包含群主),[2200(默认)]
@ -991,7 +993,7 @@ func (client *ImClient) GroupMemberKick(ctx context.Context, tid, operator_id, e
}
// GroupMemberLeave
func (client *ImClient) GroupMemberLeave(ctx context.Context, tid, account_id, extension string, members []string) error {
func (client *ImClient) GroupMemberLeave(ctx context.Context, tid, account_id, extension string) error {
url := "https://open.yunxinapi.com/im/v2/team_members/actions/leave"
httpMethod := common.HTTP_METHOD_DELETE
header := client.generateJsonHeader()
@ -1022,6 +1024,40 @@ func (client *ImClient) GroupMemberLeave(ctx context.Context, tid, account_id, e
return nil
}
// GroupMemberJoin
func (client *ImClient) GroupMemberJoin(ctx context.Context, tid, operator_id, msg, extension string, invite_account_ids []string) error {
url := "https://open.yunxinapi.com/im/v2/team_members"
httpMethod := common.HTTP_METHOD_POST
header := client.generateJsonHeader()
reqBody := map[string]any{
"team_type": 1,
"operator_id": operator_id,
"team_id": tid,
"msg": msg,
"invite_account_ids": invite_account_ids,
"extension": extension,
}
bodyBytes, err := json.Marshal(reqBody)
if err != nil {
return errors.WithStack(err)
}
res, err := HyTools.HttpDo(httpMethod, url, header, string(bodyBytes))
if err != nil {
log.InfoF("GroupMemberJoin %s:"+err.Error(), tid)
return errors.WithStack(err)
}
log.InfoF("GroupMemberJoin group chat resp: %s", res)
var body BaseRes[CreateChatGroupRsp]
err = json.Unmarshal([]byte(res), &body)
if err != nil {
return errors.WithStack(err)
}
if body.Code != 200 {
return errors.Errorf("GroupMemberJoin code(%d) not 200,msg: %s", body.Code, body.Msg)
}
return nil
}
// ================ 私有方法 ========================
func generateBodyData(parameters map[string]string) string {
sb := htools.NewStringBuilder()