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

74 lines
2.4 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
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. const NoticeLiveGoodBuy = 267 // 商品购买通知
  25. func SendNoticeByActivityId(activityId int64, _type NoticeStatus, data map[string]interface{}, members ...string) error {
  26. live := new(models.LiveConfig)
  27. exist, err := live.GetByActivityId(activityId)
  28. if err != nil {
  29. return err
  30. }
  31. if !exist {
  32. return errors.New("直播信息不存在")
  33. }
  34. groupId := fmt.Sprintf("%v%d%d", live.LiveRoomId, live.Id, live.ActivityId)
  35. return im.SendGroupSystemNotification(groupId, int(_type), data, members...)
  36. }
  37. func SendGroupCustomMessage(userId interface{}, activityId int64, _type NoticeStatus, data map[string]interface{}) error {
  38. live := new(models.LiveConfig)
  39. exist, err := live.GetByActivityId(activityId)
  40. if err != nil || !exist {
  41. err = fmt.Errorf("直播信息异常: err-> %v, exist->%v, activity_id-> %v", err, exist, activityId)
  42. logger.Error(err.Error())
  43. return err
  44. }
  45. bs, err := json.Marshal(data)
  46. if err != nil {
  47. return err
  48. }
  49. groupId := fmt.Sprintf("%v%d%d", live.LiveRoomId, live.Id, live.ActivityId)
  50. return im.SendGroupMessage(&im.SendGroupMessageParam{
  51. GroupId: groupId,
  52. Random: utils.RandomInt(6),
  53. MsgPriority: "High",
  54. FromAccount: fmt.Sprint(userId),
  55. MsgBody: []im.MsgBody{
  56. {
  57. MsgType: "TIMCustomElem",
  58. MsgContent: im.MsgBodyContent{
  59. Data: string(bs),
  60. Desc: fmt.Sprint(_type),
  61. Ext: "",
  62. Sound: "",
  63. },
  64. },
  65. },
  66. })
  67. }