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

57 lines
1.3 KiB

5 years ago
5 years ago
5 years ago
5 years ago
  1. package im_service
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "hudongzhuanjia/libs/im"
  7. "hudongzhuanjia/models"
  8. "hudongzhuanjia/utils"
  9. "strconv"
  10. )
  11. func SendNoticeByActivityId(activityId int64, _type im.NoticeStatus, data map[string]interface{}, members ...string) error {
  12. live := new(models.LiveConfig)
  13. exist, err := live.GetByActivityId(activityId)
  14. if err != nil {
  15. return err
  16. }
  17. if !exist {
  18. return errors.New("直播信息不存在")
  19. }
  20. groupId := fmt.Sprintf("%v%d%d", live.LiveRoomId, live.Id, live.ActivityId)
  21. return im.SendGroupSystemNotification(groupId, _type, data, members...)
  22. }
  23. func SendGroupCustomMessage(activityId int64, _type im.NoticeStatus, data map[string]interface{}) error {
  24. live := new(models.LiveConfig)
  25. exist, err := live.GetByActivityId(activityId)
  26. if err != nil {
  27. return err
  28. }
  29. if !exist {
  30. return errors.New("直播信息不存在")
  31. }
  32. bs, err := json.Marshal(data)
  33. if err != nil {
  34. return err
  35. }
  36. groupId := fmt.Sprintf("%v%d%d", live.LiveRoomId, live.Id, live.ActivityId)
  37. return im.SendGroupMessage(&im.SendGroupMessageParam{
  38. GroupId: groupId,
  39. Random: utils.RandomInt(6),
  40. MsgPriority: "High",
  41. MsgBody: []im.MsgBody{
  42. {
  43. MsgType: "TIMCustomElem",
  44. MsgContent: im.MsgBodyContent{
  45. Data: string(bs),
  46. Desc: strconv.Itoa(int(_type)),
  47. Ext: "",
  48. Sound: "",
  49. },
  50. },
  51. },
  52. })
  53. }