// Copyright 2019 autocareai.com. All rights reserved. // Use of this source code is governed by autocareai.com. package gb28181 import ( "encoding/json" "gitlab.sydip.com/repo/gopkgs/cache" "time" . "m7s.live/engine/v4" "go.uber.org/zap" "fmt" ) type PushMessageBody struct { Id int64 `form:"id" json:"id"` Sn string `form:"sn" json:"sn" description:"sn"` RecongnitionKey string `form:"recongnition_key" json:"recongnition_key"` Color string `form:"color" json:"color"` Img string `form:"img" json:"img"` Location string `form:"location" json:"location"` CameraLocation string `form:"camera_location" json:"camera_location"` Time int64 `form:"time" json:"time"` RecongnitionType int `form:"recongnition_type" json:"recongnition_type"` AccessType int `form:"access_type" json:"access_type"` } type PushStateBody struct { Sn string `form:"sn" json:"sn"` State int `form:"state" json:"state"` Time int64 `json:"time"` } type Message struct{ Code string `json:"code"` // 1 车辆消息,2 人脸消息 Sn string `json:"sn"` ChannelId string `json:"channel_id"` Body []byte `json:"body"` } const( PushStateCode = "200" PushMessageCode = "201" PushMessageKey = "push-message-list" RebootDevicePre ="reboot:" ) func getRebootKey(channelId string) string { return fmt.Sprintf("%s:%s",RebootDevicePre,channelId) } func SendMessageToRedis(channelId string,state int) error { newMessage := Message{} newMessage.Code = PushStateCode newMessage.ChannelId = channelId //newMessage.ChannelId = message.channelId body := PushStateBody{} body.State = state body.Time = time.Now().Unix() sdata ,_:= json.Marshal(body) newMessage.Body = sdata ndata ,_ := json.Marshal(newMessage) _,err := cache.Redis().RPush(PushMessageKey,string(ndata)) if err != nil{ GB28181Plugin.Error("发送设备状态更新失败:",zap.String("deviceId", channelId),zap.String("error", err.Error())) }else{ GB28181Plugin.Info("发送设备状态更新成功",zap.String("deviceId", channelId)) } //fmt.Println("发送设备状态更新:",channelId,state) return err } func SendRebootMessage(channelId string){ if channelId == ""{ return } key := getRebootKey(channelId) //fmt.Println(EngineConfig.Engine.RebootCacheTime) if EngineConfig.Engine.RebootCacheTime == 0 { EngineConfig.Engine.RebootCacheTime = 360 // 6分钟 }else{ EngineConfig.Engine.RebootCacheTime = EngineConfig.Engine.RebootCacheTime + 60 } // 10分钟 _,err := cache.Redis().SetNxEx(key,"reboot",EngineConfig.Engine.RebootCacheTime) if err != nil{ GB28181Plugin.Info("重启设备发送失败",zap.String("channelId", channelId),zap.String("error",err.Error())) } } func DeleteRebootMessage(channelId string){ if channelId == ""{ return } key := getRebootKey(channelId) _,err := cache.Redis().Del(key) if err != nil{ GB28181Plugin.Info("删除重启设备失败",zap.String("channelId", channelId),zap.String("error",err.Error())) } }