package callback import ( "encoding/json" "github.com/gin-gonic/gin" "io/ioutil" live2 "live/app/logic/live" "live/app/model/live" "log" "net/url" "strconv" ) type Live struct { } type argsPush struct { App string `json:"app"` Appid int64 `json:"appid"` Appname string `json:"appname"` ChannelID string `json:"channel_id"` Errcode int64 `json:"errcode"` Errmsg string `json:"errmsg"` EventTime int64 `json:"event_time"` EventType int64 `json:"event_type"` Height int64 `json:"height"` IdcID int64 `json:"idc_id"` Node string `json:"node"` Sequence string `json:"sequence"` SetID int64 `json:"set_id"` Sign string `json:"sign"` StreamID string `json:"stream_id"` StreamParam string `json:"stream_param"` T int64 `json:"t"` UserIP string `json:"user_ip"` Width int64 `json:"width"` } func (l *Live) Push(c *gin.Context) { data, _ := ioutil.ReadAll(c.Request.Body) log.Println("直播开始/继续:", string(data)) //args := argsPush{} //if err := json.Unmarshal(data, &args); err != nil { // log.Println("json序列化失败,err:", err) // return //} //query, err := url.ParseQuery(args.StreamParam) //if err != nil { // log.Println("参数序列化失败,err:", err) // return //} //liveItemId, _ := strconv.ParseUint(query.Get("liveItemId"), 10, 64) // //liveItemModel := &live.LiveItem{} //liveItemInfo := liveItemModel.FindById(uint(liveItemId)) //if liveItemInfo.Id <= 0 { // log.Println("直播场次获取失败,err:", err) // return //} //live2.ImLogic.SendLiveGroupMessage(liveItemInfo.RoomId, live2.LiveGroupMsgTypePlay, gin.H{ // "type": "play", // "time": time.Now().UnixNano(), //}) } type argsCutout struct { App string `json:"app"` Appid int64 `json:"appid"` Appname string `json:"appname"` ChannelID string `json:"channel_id"` Errcode int64 `json:"errcode"` Errmsg string `json:"errmsg"` EventTime int64 `json:"event_time"` EventType int64 `json:"event_type"` Height int64 `json:"height"` IdcID int64 `json:"idc_id"` Node string `json:"node"` PushDuration string `json:"push_duration"` Sequence string `json:"sequence"` SetID int64 `json:"set_id"` Sign string `json:"sign"` StreamID string `json:"stream_id"` StreamParam string `json:"stream_param"` T int64 `json:"t"` UserIP string `json:"user_ip"` Width int64 `json:"width"` } func (l *Live) Cutout(c *gin.Context) { data, _ := ioutil.ReadAll(c.Request.Body) log.Println("直播暂停:", string(data)) //args := argsCutout{} //if err := json.Unmarshal(data, &args); err != nil { // log.Println("json序列化失败,err:", err) // return //} //query, err := url.ParseQuery(args.StreamParam) //if err != nil { // log.Println("参数序列化失败,err:", err) // return //} //liveItemId, _ := strconv.ParseUint(query.Get("liveItemId"), 10, 64) // //liveItemModel := &live.LiveItem{} //liveItemInfo := liveItemModel.FindById(uint(liveItemId)) //if liveItemInfo.Id <= 0 { // log.Println("直播场次获取失败,err:", err) // return //} //live2.ImLogic.SendLiveGroupMessage(liveItemInfo.RoomId, live2.LiveGroupMsgTypePlay, gin.H{ // "type": "pause", // "time": time.Now().UnixNano(), //}) } type argsTranscribe struct { App string `json:"app"` Appid int64 `json:"appid"` Appname string `json:"appname"` ChannelID string `json:"channel_id"` Duration int64 `json:"duration"` EndTime int64 `json:"end_time"` EndTimeUsec int64 `json:"end_time_usec"` EventType int64 `json:"event_type"` FileFormat string `json:"file_format"` FileID string `json:"file_id"` FileSize int64 `json:"file_size"` MediaStartTime int64 `json:"media_start_time"` RecordBps int64 `json:"record_bps"` RecordFileID string `json:"record_file_id"` Sign string `json:"sign"` StartTime int64 `json:"start_time"` StartTimeUsec int64 `json:"start_time_usec"` StreamID string `json:"stream_id"` StreamParam string `json:"stream_param"` T int64 `json:"t"` TaskID string `json:"task_id"` VideoID string `json:"video_id"` VideoURL string `json:"video_url"` } func (l *Live) Transcribe(c *gin.Context) { data, _ := ioutil.ReadAll(c.Request.Body) log.Println("录播完成:", string(data)) args := argsTranscribe{} if err := json.Unmarshal(data, &args); err != nil { log.Println("json序列化失败,err:", err) return } query, err := url.ParseQuery(args.StreamParam) if err != nil { log.Println("参数序列化失败,err:", err) return } liveItemId, _ := strconv.ParseUint(query.Get("liveItemId"), 10, 64) liveItemModel := &live.LiveItem{} liveItemInfo := liveItemModel.FindById(uint(liveItemId)) if liveItemInfo.Id <= 0 { log.Println("直播场次获取失败,err:", err) return } if liveItemInfo.TranscribeType == live.LIVE_Transcribe_Type_ing { liveItemModel.UpdateById(liveItemInfo.Id, map[string]interface{}{ "file_id": args.FileID, "video_url": args.VideoURL, "transcribe_type": live.LIVE_Transcribe_Type_finish, }) } else { liveItemModel.UpdateById(liveItemInfo.Id, map[string]interface{}{ "file_id": args.FileID, "video_url": args.VideoURL, }) } if liveItemInfo.Status == live.LIVE_STATUS_ing { // 尚未结束直播 if err := live2.LiveLogic.Stop(liveItemInfo.UserId, liveItemInfo.Id); err != nil { log.Println("直播结束失败,err:", err) return } } } func (l *Live) ScreenShot(c *gin.Context) { } func (l *Live) Identify(c *gin.Context) { log.Println("identify:start") log.Println("data:", c.Request.RequestURI) log.Println("data:", c.Request.PostForm) all, err := ioutil.ReadAll(c.Request.Body) log.Println(string(all), err) log.Println("identify:end") }