You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright © 2023 OpenIM open source community. All rights reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package msg
  15. import (
  16. "errors"
  17. "fmt"
  18. "github.com/openimsdk/openkf/server/pkg/openim/client"
  19. "github.com/openimsdk/openkf/server/pkg/openim/param/request"
  20. "github.com/openimsdk/openkf/server/pkg/openim/param/response"
  21. )
  22. const (
  23. // PATH_SEND_MSG admin send message.
  24. PATH_SEND_MSG = "/msg/send_msg"
  25. )
  26. // AdminSendMsg admin send message.
  27. func AdminSendMsg(param *request.MsgInfo, operationID, host, adminToken string) (*response.BaseResponse, error) {
  28. // host: http://ip:port
  29. url := fmt.Sprintf("%s%s", host, PATH_SEND_MSG)
  30. r := &response.BaseResponse{}
  31. client := client.NewClient(url)
  32. resp, err := client.POST(operationID, adminToken, param)
  33. if err != nil {
  34. return r, err
  35. }
  36. r.ErrCode = uint(resp["errCode"].(float64))
  37. r.ErrMsg = resp["errMsg"].(string)
  38. r.ErrDlt = resp["errDlt"].(string)
  39. if resp["data"] == nil {
  40. return r, errors.New("data is nil: " + r.ErrMsg)
  41. }
  42. r.Data = resp["data"]
  43. return r, nil
  44. }