互动
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.

59 lines
1.5 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
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/logger"
  8. "hudongzhuanjia/models"
  9. "hudongzhuanjia/utils"
  10. "strconv"
  11. )
  12. func SendNoticeByActivityId(activityId int64, _type im.NoticeStatus, data map[string]interface{}, members ...string) error {
  13. live := new(models.LiveConfig)
  14. exist, err := live.GetByActivityId(activityId)
  15. if err != nil {
  16. return err
  17. }
  18. if !exist {
  19. return errors.New("直播信息不存在")
  20. }
  21. groupId := fmt.Sprintf("%v%d%d", live.LiveRoomId, live.Id, live.ActivityId)
  22. return im.SendGroupSystemNotification(groupId, _type, data, members...)
  23. }
  24. func SendGroupCustomMessage(userId string, activityId int64, _type im.NoticeStatus, data map[string]interface{}) error {
  25. live := new(models.LiveConfig)
  26. exist, err := live.GetByActivityId(activityId)
  27. if err != nil || !exist {
  28. err = fmt.Errorf("直播信息异常: err-> %v, exist->%v, activity_id-> %v", err, exist, activityId)
  29. logger.Error(err.Error())
  30. return err
  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. FromAccount: userId,
  42. MsgBody: []im.MsgBody{
  43. {
  44. MsgType: "TIMCustomElem",
  45. MsgContent: im.MsgBodyContent{
  46. Data: string(bs),
  47. Desc: strconv.Itoa(int(_type)),
  48. Ext: "",
  49. Sound: "",
  50. },
  51. },
  52. },
  53. })
  54. }