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

73 lines
2.3 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
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. )
  11. // 定义一些通知或者数据状态
  12. type NoticeStatus int
  13. const NoticeLiveRedPackStart NoticeStatus = 256 // 通知直播用户红包开始了
  14. const NoticeLiveRedPackEnd NoticeStatus = 257 // 通知直播用户红包结束了
  15. const NoticeLiveRedPackGet NoticeStatus = 258 // 某人摇中红包
  16. const NoticeShakeRedPackStart NoticeStatus = 259 // 通知摇红包开始了
  17. const NoticeShakeRedPackEnd NoticeStatus = 260 // 通知摇红包结束了
  18. const NoticeReward NoticeStatus = 261 // 打赏
  19. const NoticeLotteryDrawStart = 262 // 抽奖开始
  20. const NoticeLotteryDrawStop = 263 // 抽奖结束
  21. const NoticeLotteryDrawResult = 264 // 抽奖结果
  22. const NoticeLotteryDrawRollStart = 265 // 开始滚动
  23. const NoticeLotteryDrawRollStop = 266 // 停止滚动
  24. func SendNoticeByActivityId(activityId int64, _type NoticeStatus, data map[string]interface{}, members ...string) error {
  25. live := new(models.LiveConfig)
  26. exist, err := live.GetByActivityId(activityId)
  27. if err != nil {
  28. return err
  29. }
  30. if !exist {
  31. return errors.New("直播信息不存在")
  32. }
  33. groupId := fmt.Sprintf("%v%d%d", live.LiveRoomId, live.Id, live.ActivityId)
  34. return im.SendGroupSystemNotification(groupId, int(_type), data, members...)
  35. }
  36. func SendGroupCustomMessage(userId interface{}, activityId int64, _type NoticeStatus, data map[string]interface{}) error {
  37. live := new(models.LiveConfig)
  38. exist, err := live.GetByActivityId(activityId)
  39. if err != nil || !exist {
  40. err = fmt.Errorf("直播信息异常: err-> %v, exist->%v, activity_id-> %v", err, exist, activityId)
  41. logger.Error(err.Error())
  42. return err
  43. }
  44. bs, err := json.Marshal(data)
  45. if err != nil {
  46. return err
  47. }
  48. groupId := fmt.Sprintf("%v%d%d", live.LiveRoomId, live.Id, live.ActivityId)
  49. return im.SendGroupMessage(&im.SendGroupMessageParam{
  50. GroupId: groupId,
  51. Random: utils.RandomInt(6),
  52. MsgPriority: "High",
  53. FromAccount: fmt.Sprint(userId),
  54. MsgBody: []im.MsgBody{
  55. {
  56. MsgType: "TIMCustomElem",
  57. MsgContent: im.MsgBodyContent{
  58. Data: string(bs),
  59. Desc: fmt.Sprint(_type),
  60. Ext: "",
  61. Sound: "",
  62. },
  63. },
  64. },
  65. })
  66. }