diff --git a/pkg/common/netease/ImClient.go b/pkg/common/netease/ImClient.go index f5031fd..d33cc40 100644 --- a/pkg/common/netease/ImClient.go +++ b/pkg/common/netease/ImClient.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "net/url" "strings" "gitea.ddegame.cn/open/servicebase/pkg/common" @@ -996,7 +997,7 @@ func (client *ImClient) GroupManagerAdd(ctx context.Context, id, operator_id, ex // GroupManagerRemove func (client *ImClient) GroupManagerRemove(ctx context.Context, id, operator_id, extension string, managers []string) error { - url := "https://open.yunxinapi.com/im/v2.1/teams/" + id + "/actions/remove_manager" + _url := "https://open.yunxinapi.com/im/v2.1/teams/" + id + "/actions/remove_manager" httpMethod := "DELETE" header := client.generateJsonHeader() reqBody := map[string]any{ @@ -1006,18 +1007,18 @@ func (client *ImClient) GroupManagerRemove(ctx context.Context, id, operator_id, // "extension": extension, } if len(extension) > 0 { - reqBody["extension"] = extension + reqBody["extension"] = url.PathEscape(extension) } - // var params []string - // for k, v := range reqBody { - // params = append(params, fmt.Sprintf("%s=%v", k, v)) + var params []string + for k, v := range reqBody { + params = append(params, fmt.Sprintf("%s=%v", k, v)) + } + _url = fmt.Sprintf("%s?%s", _url, strings.Join(params, "&")) + // bodyBytes, err := json.Marshal(reqBody) + // if err != nil { + // return errors.WithStack(err) // } - // url = fmt.Sprintf("%s?%s", url, strings.Join(params, "&")) - bodyBytes, err := json.Marshal(reqBody) - if err != nil { - return errors.WithStack(err) - } - res, err := HyTools.HttpDo(httpMethod, url, header, string(bodyBytes)) + res, err := HyTools.HttpDo(httpMethod, _url, header, "") if err != nil { log.InfoF("GroupManagerRemove %s:"+err.Error(), operator_id) return errors.WithStack(err) @@ -1029,14 +1030,14 @@ func (client *ImClient) GroupManagerRemove(ctx context.Context, id, operator_id, return errors.WithStack(err) } if body.Code != 200 { - return errors.Errorf("GroupManagerRemove code(%d) not 200 url=%s id=%s operator=%s managers=%v,msg: %s", body.Code, url, id, operator_id, managers, body.Msg) + return errors.Errorf("GroupManagerRemove code(%d) not 200 url=%s id=%s operator=%s managers=%v,msg: %s", body.Code, _url, id, operator_id, managers, body.Msg) } return nil } // GroupRemove func (client *ImClient) GroupRemove(ctx context.Context, id, operator_id, extension string) error { - url := "https://open.yunxinapi.com/im/v2.1/teams/" + id + _url := "https://open.yunxinapi.com/im/v2.1/teams/" + id httpMethod := "DELETE" header := client.generateJsonHeader() reqBody := map[string]any{ @@ -1045,18 +1046,18 @@ func (client *ImClient) GroupRemove(ctx context.Context, id, operator_id, extens // "extension": extension, } if len(extension) > 0 { - reqBody["extension"] = extension + reqBody["extension"] = url.PathEscape(extension) } - // var params []string - // for k, v := range reqBody { - // params = append(params, fmt.Sprintf("%s=%v", k, v)) + var params []string + for k, v := range reqBody { + params = append(params, fmt.Sprintf("%s=%v", k, v)) + } + _url = fmt.Sprintf("%s?%s", _url, strings.Join(params, "&")) + // bodyBytes, err := json.Marshal(reqBody) + // if err != nil { + // return errors.WithStack(err) // } - // url = fmt.Sprintf("%s?%s", url, strings.Join(params, "&")) - bodyBytes, err := json.Marshal(reqBody) - if err != nil { - return errors.WithStack(err) - } - res, err := HyTools.HttpDo(httpMethod, url, header, string(bodyBytes)) + res, err := HyTools.HttpDo(httpMethod, _url, header, "") if err != nil { log.InfoF("GroupRemove %s:"+err.Error(), operator_id) return errors.WithStack(err) @@ -1075,29 +1076,29 @@ func (client *ImClient) GroupRemove(ctx context.Context, id, operator_id, extens // GroupMemberKick func (client *ImClient) GroupMemberKick(ctx context.Context, tid, operator_id, extension string, members []string) error { - url := "https://open.yunxinapi.com/im/v2/team_members/actions/kick_member" + _url := "https://open.yunxinapi.com/im/v2/team_members/actions/kick_member" httpMethod := "DELETE" header := client.generateJsonHeader() reqBody := map[string]any{ "team_type": 1, "operator_id": operator_id, - "team_id": tools.StrToInt(tid), + "team_id": tools.StrToInt64(tid), "kick_account_ids": members, // "extension": extension, } if len(extension) > 0 { - reqBody["extension"] = extension + reqBody["extension"] = url.PathEscape(extension) } - // var params []string - // for k, v := range reqBody { - // params = append(params, fmt.Sprintf("%s=%v", k, v)) + var params []string + for k, v := range reqBody { + params = append(params, fmt.Sprintf("%s=%v", k, v)) + } + _url = fmt.Sprintf("%s?%s", _url, strings.Join(params, "&")) + // bodyBytes, err := json.Marshal(reqBody) + // if err != nil { + // return errors.WithStack(err) // } - // url = fmt.Sprintf("%s?%s", url, strings.Join(params, "&")) - bodyBytes, err := json.Marshal(reqBody) - if err != nil { - return errors.WithStack(err) - } - res, err := HyTools.HttpDo(httpMethod, url, header, string(bodyBytes)) + res, err := HyTools.HttpDo(httpMethod, _url, header, "") if err != nil { log.InfoF("GroupMemberKick %s:"+err.Error(), operator_id) return errors.WithStack(err) @@ -1116,28 +1117,28 @@ func (client *ImClient) GroupMemberKick(ctx context.Context, tid, operator_id, e // GroupMemberLeave func (client *ImClient) GroupMemberLeave(ctx context.Context, tid, account_id, extension string) error { - url := "https://open.yunxinapi.com/im/v2/team_members/actions/leave" + _url := "https://open.yunxinapi.com/im/v2/team_members/actions/leave" httpMethod := "DELETE" header := client.generateJsonHeader() reqBody := map[string]any{ "team_type": 1, "account_id": account_id, - "team_id": tools.StrToInt(tid), + "team_id": tid, // "extension": extension, } if len(extension) > 0 { - reqBody["extension"] = extension + reqBody["extension"] = url.PathEscape(extension) } - // var params []string - // for k, v := range reqBody { - // params = append(params, fmt.Sprintf("%s=%v", k, v)) + var params []string + for k, v := range reqBody { + params = append(params, fmt.Sprintf("%s=%v", k, v)) + } + _url = fmt.Sprintf("%s?%s", _url, strings.Join(params, "&")) + // bodyBytes, err := json.Marshal(reqBody) + // if err != nil { + // return errors.WithStack(err) // } - // url = fmt.Sprintf("%s?%s", url, strings.Join(params, "&")) - bodyBytes, err := json.Marshal(reqBody) - if err != nil { - return errors.WithStack(err) - } - res, err := HyTools.HttpDo(httpMethod, url, header, string(bodyBytes)) + res, err := HyTools.HttpDo(httpMethod, _url, header, "") if err != nil { log.InfoF("GroupMemberLeave %s:"+err.Error(), tid) return errors.WithStack(err) @@ -1162,7 +1163,7 @@ func (client *ImClient) GroupMemberJoin(ctx context.Context, tid, operator_id, m reqBody := map[string]any{ "team_type": 1, "operator_id": operator_id, - "team_id": tools.StrToInt(tid), + "team_id": tools.StrToInt64(tid), "msg": msg, "invite_account_ids": invite_account_ids, // "extension": extension,