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

package im_service
import (
"encoding/json"
"errors"
"fmt"
"hudongzhuanjia/libs/im"
"hudongzhuanjia/logger"
"hudongzhuanjia/models"
"hudongzhuanjia/utils"
)
// 定义一些通知或者数据状态
type NoticeStatus int
const NoticeLiveRedPackStart NoticeStatus = 256 // 通知直播用户红包开始了
const NoticeLiveRedPackEnd NoticeStatus = 257 // 通知直播用户红包结束了
const NoticeLiveRedPackGet NoticeStatus = 258 // 某人摇中红包
const NoticeShakeRedPackStart NoticeStatus = 259 // 通知摇红包开始了
const NoticeShakeRedPackEnd NoticeStatus = 260 // 通知摇红包结束了
const NoticeReward NoticeStatus = 261 // 打赏
const NoticeLotteryDrawStart = 262 // 抽奖开始
const NoticeLotteryDrawStop = 263 // 抽奖结束
const NoticeLotteryDrawResult = 264 // 抽奖结果
const NoticeLotteryDrawRollStart = 265 // 开始滚动
const NoticeLotteryDrawRollStop = 266 // 停止滚动
const NoticeLiveGoodBuy = 267 // 商品购买通知
func SendNoticeByActivityId(activityId int64, _type NoticeStatus, data map[string]interface{}, members ...string) error {
live := new(models.LiveConfig)
exist, err := live.GetByActivityId(activityId)
if err != nil {
return err
}
if !exist {
return errors.New("直播信息不存在")
}
groupId := fmt.Sprintf("%v%d%d", live.LiveRoomId, live.Id, live.ActivityId)
return im.SendGroupSystemNotification(groupId, int(_type), data, members...)
}
func SendGroupCustomMessage(userId interface{}, activityId int64, _type NoticeStatus, data map[string]interface{}) error {
live := new(models.LiveConfig)
exist, err := live.GetByActivityId(activityId)
if err != nil || !exist {
err = fmt.Errorf("直播信息异常: err-> %v, exist->%v, activity_id-> %v", err, exist, activityId)
logger.Error(err.Error())
return err
}
bs, err := json.Marshal(data)
if err != nil {
return err
}
groupId := fmt.Sprintf("%v%d%d", live.LiveRoomId, live.Id, live.ActivityId)
return im.SendGroupMessage(&im.SendGroupMessageParam{
GroupId: groupId,
Random: utils.RandomInt(6),
MsgPriority: "High",
FromAccount: fmt.Sprint(userId),
MsgBody: []im.MsgBody{
{
MsgType: "TIMCustomElem",
MsgContent: im.MsgBodyContent{
Data: string(bs),
Desc: fmt.Sprint(_type),
Ext: "",
Sound: "",
},
},
},
})
}