feat(app): update

This commit is contained in:
Yangtao
2025-12-02 13:44:25 +08:00
parent 7a7706d0fb
commit 8bde0f660d

View File

@ -736,6 +736,50 @@ func (client *ImClient) CreateChatGroup(ctx context.Context, ownerUserId string,
return cast.ToString(body.Data.TeamInfo.TeamID), nil return cast.ToString(body.Data.TeamInfo.TeamID), nil
} }
// P2PMsgSend 发送单聊消息
func (client *ImClient) P2PMsgSend(from, to, _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=" + "0")
sb.Append("&")
sb.Append("to=" + to)
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.InfoF("GroupMsgSend error %s:", err.Error())
return err
} else {
var resDTO CreateImRes
json.Unmarshal([]byte(res), &resDTO)
if resDTO.Code != 200 {
log.InfoF("GroupMsgSend code error %s", resDTO.Desc)
} else {
log.InfoF("GroupMsgSend success from=%s to=%s type=%s content=%s res=%s", from, to, _type, content, 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
}
// GroupMsgSend 发送群消息 // GroupMsgSend 发送群消息
func (client *ImClient) GroupMsgSend(from, tid, _type, content, msg string) error { func (client *ImClient) GroupMsgSend(from, tid, _type, content, msg string) error {
url := "https://api.netease.im/nimserver/msg/sendMsg.action" url := "https://api.netease.im/nimserver/msg/sendMsg.action"
@ -759,15 +803,15 @@ func (client *ImClient) GroupMsgSend(from, tid, _type, content, msg string) erro
// faccid String 入群失败的账号accid列表格式为 JSONArray如果创建时邀请的成员中存在加群数量超过限制的情况会返回入群失败的 accid 以及附言msg // faccid String 入群失败的账号accid列表格式为 JSONArray如果创建时邀请的成员中存在加群数量超过限制的情况会返回入群失败的 accid 以及附言msg
if err != nil { if err != nil {
// {"desc":"already register","code":414} // {"desc":"already register","code":414}
log.Info("GroupMsgSend %s:" + err.Error()) log.InfoF("GroupMsgSend error %s:", err.Error())
return err return err
} else { } else {
var resDTO CreateImRes var resDTO CreateImRes
json.Unmarshal([]byte(res), &resDTO) json.Unmarshal([]byte(res), &resDTO)
if resDTO.Code != 200 { if resDTO.Code != 200 {
log.Info("GroupMsgSend %s:" + resDTO.Desc) log.InfoF("GroupMsgSend code error %s", resDTO.Desc)
} else { } else {
log.Info("GroupMsgSend %s:" + res) log.InfoF("GroupMsgSend success from=%s to=%s type=%s content=%s res=%s", from, tid, _type, content, res)
} }
} }
var body map[string]any var body map[string]any
@ -843,7 +887,7 @@ func (client *ImClient) CreateProGroup(tname, owner, announcement, avatar, msg s
// GroupUpdate 更新群组 // GroupUpdate 更新群组
func (client *ImClient) GroupUpdate(ctx context.Context, id, operator_id, name, announcement, icon string) error { func (client *ImClient) GroupUpdate(ctx context.Context, id, operator_id, name, announcement, icon string) error {
url := "https://open.yunxinapi.com/im/v2.1/teams/" + id url := "https://open.yunxinapi.com/im/v2.1/teams/" + id
httpMethod := common.HTTP_METHOD_PATCH httpMethod := "PATCH"
header := client.generateJsonHeader() header := client.generateJsonHeader()
reqBody := map[string]any{ reqBody := map[string]any{
"operator_id": operator_id, "operator_id": operator_id,
@ -880,7 +924,7 @@ func (client *ImClient) GroupUpdate(ctx context.Context, id, operator_id, name,
// GroupTransfer 转让群组 // GroupTransfer 转让群组
func (client *ImClient) GroupTransfer(ctx context.Context, id, new_owner, extension string) error { func (client *ImClient) GroupTransfer(ctx context.Context, id, new_owner, extension string) error {
url := "https://open.yunxinapi.com/im/v2.1/teams/" + id + "/actions/transfer_owner" url := "https://open.yunxinapi.com/im/v2.1/teams/" + id + "/actions/transfer_owner"
httpMethod := common.HTTP_METHOD_PATCH httpMethod := "PATCH"
header := client.generateJsonHeader() header := client.generateJsonHeader()
reqBody := map[string]any{ reqBody := map[string]any{
"team_type": 1, "team_type": 1,
@ -918,7 +962,7 @@ func (client *ImClient) GroupManagerAdd(ctx context.Context, id, operator_id, ex
"team_type": 1, "team_type": 1,
"managers": managers, "managers": managers,
"operator_id": operator_id, "operator_id": operator_id,
"extension": extension, // "extension": extension,
} }
bodyBytes, err := json.Marshal(reqBody) bodyBytes, err := json.Marshal(reqBody)
if err != nil { if err != nil {
@ -944,14 +988,19 @@ func (client *ImClient) GroupManagerAdd(ctx context.Context, id, operator_id, ex
// GroupManagerRemove // GroupManagerRemove
func (client *ImClient) GroupManagerRemove(ctx context.Context, id, operator_id, extension string, managers []string) error { 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 := common.HTTP_METHOD_DELETE httpMethod := "DELETE"
header := client.generateJsonHeader() header := client.generateJsonHeader()
reqBody := map[string]any{ reqBody := map[string]any{
"team_type": 1, "team_type": 1,
"managers": managers, "managers": managers,
"operator_id": operator_id, "operator_id": operator_id,
"extension": extension, // "extension": extension,
} }
// 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) bodyBytes, err := json.Marshal(reqBody)
if err != nil { if err != nil {
return errors.WithStack(err) return errors.WithStack(err)
@ -968,7 +1017,7 @@ func (client *ImClient) GroupManagerRemove(ctx context.Context, id, operator_id,
return errors.WithStack(err) return errors.WithStack(err)
} }
if body.Code != 200 { if body.Code != 200 {
return errors.Errorf("GroupManagerRemove code(%d) not 200,msg: %s", body.Code, 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 return nil
} }
@ -976,18 +1025,23 @@ func (client *ImClient) GroupManagerRemove(ctx context.Context, id, operator_id,
// GroupRemove // GroupRemove
func (client *ImClient) GroupRemove(ctx context.Context, id, operator_id, extension string) error { 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 := common.HTTP_METHOD_DELETE httpMethod := "DELETE"
header := client.generateJsonHeader() header := client.generateJsonHeader()
reqBody := map[string]any{ reqBody := map[string]any{
"team_type": 1, "team_type": 1,
"operator_id": operator_id, "operator_id": operator_id,
"extension": extension, // "extension": extension,
} }
bodyBytes, err := json.Marshal(reqBody) var params []string
if err != nil { for k, v := range reqBody {
return errors.WithStack(err) params = append(params, fmt.Sprintf("%s=%v", k, v))
} }
res, err := HyTools.HttpDo(httpMethod, url, header, string(bodyBytes)) 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, "")
if err != nil { if err != nil {
log.InfoF("GroupRemove %s:"+err.Error(), operator_id) log.InfoF("GroupRemove %s:"+err.Error(), operator_id)
return errors.WithStack(err) return errors.WithStack(err)
@ -1007,20 +1061,25 @@ func (client *ImClient) GroupRemove(ctx context.Context, id, operator_id, extens
// GroupMemberKick // GroupMemberKick
func (client *ImClient) GroupMemberKick(ctx context.Context, tid, operator_id, extension string, members []string) error { 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 := common.HTTP_METHOD_DELETE httpMethod := "DELETE"
header := client.generateJsonHeader() header := client.generateJsonHeader()
reqBody := map[string]any{ reqBody := map[string]any{
"team_type": 1, "team_type": 1,
"operator_id": operator_id, "operator_id": operator_id,
"team_id": tools.StrToInt(tid), "team_id": tools.StrToInt(tid),
"kick_account_ids": members, "kick_account_ids": members,
"extension": extension, // "extension": extension,
} }
bodyBytes, err := json.Marshal(reqBody) var params []string
if err != nil { for k, v := range reqBody {
return errors.WithStack(err) params = append(params, fmt.Sprintf("%s=%v", k, v))
} }
res, err := HyTools.HttpDo(httpMethod, url, header, string(bodyBytes)) 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, "")
if err != nil { if err != nil {
log.InfoF("GroupMemberKick %s:"+err.Error(), operator_id) log.InfoF("GroupMemberKick %s:"+err.Error(), operator_id)
return errors.WithStack(err) return errors.WithStack(err)
@ -1040,19 +1099,24 @@ func (client *ImClient) GroupMemberKick(ctx context.Context, tid, operator_id, e
// GroupMemberLeave // GroupMemberLeave
func (client *ImClient) GroupMemberLeave(ctx context.Context, tid, account_id, extension 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" url := "https://open.yunxinapi.com/im/v2/team_members/actions/leave"
httpMethod := common.HTTP_METHOD_DELETE httpMethod := "DELETE"
header := client.generateJsonHeader() header := client.generateJsonHeader()
reqBody := map[string]any{ reqBody := map[string]any{
"team_type": 1, "team_type": 1,
"account_id": account_id, "account_id": account_id,
"team_id": tools.StrToInt(tid), "team_id": tools.StrToInt(tid),
"extension": extension, // "extension": extension,
} }
bodyBytes, err := json.Marshal(reqBody) var params []string
if err != nil { for k, v := range reqBody {
return errors.WithStack(err) params = append(params, fmt.Sprintf("%s=%v", k, v))
} }
res, err := HyTools.HttpDo(httpMethod, url, header, string(bodyBytes)) 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, "")
if err != nil { if err != nil {
log.InfoF("GroupMemberLeave %s:"+err.Error(), tid) log.InfoF("GroupMemberLeave %s:"+err.Error(), tid)
return errors.WithStack(err) return errors.WithStack(err)