Files
PandaX/pkg/ys/device.go
2023-09-05 17:09:24 +08:00

58 lines
2.0 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package ys
import (
"pandax/pkg/tool"
)
const (
//设备列表
DEVICELIST = "https://open.ys7.com/api/lapp/device/list"
//获取指定设备的通道信息
DEVICECHANNELLIST = "https://open.ys7.com/api/lapp/device/camera/list"
// 获取播放地址
DEVICELIVEADDRESS = "https://open.ys7.com/api/lapp/v2/live/address/get"
)
// GetDeviceList 获取设备列表
func (ys *Ys) GetDeviceList(pageNum, pageSize int) (devices []Device, total int64, err error) {
params := make(map[string]interface{})
params["pageStart"] = pageNum
params["pageSize"] = pageSize
status, err := ys.authorizeRequset("POST", DEVICELIST, params, &devices) //获取用户下的设备列表
if err != nil {
return nil, 0, err
}
var page = Page{}
err = tool.InterfaceToStruct(status.Page, &page)
if err != nil {
return nil, 0, err
}
return devices, int64(page.Total), nil
}
// GetDeviceChannelList 获取指定设备的通道信息
func (ys *Ys) GetDeviceChannelList(deviceSerial string) (cameras []Channel, err error) {
params := make(map[string]interface{})
params["deviceSerial"] = deviceSerial
_, err = ys.authorizeRequset("POST", DEVICECHANNELLIST, params, &cameras)
if err != nil {
return nil, err
}
return cameras, nil
}
// GetDeviceLiveAddress 获取指定设备通道的播放地址
func (ys *Ys) GetDeviceLiveAddress(deviceSerial string, channelNo int) (live []LiveAddress, err error) {
params := make(map[string]interface{})
params["deviceSerial"] = deviceSerial
params["channelNo"] = channelNo
params["protocol"] = 4 //流播放协议1-ezopen、2-hls、3-rtmp、4-flv默认为1
params["type"] = "1" //地址的类型1-预览2-本地录像回放3-云存储录像回放非必选默认为1回放仅支持rtmp、ezopen、flv协议
params["quality"] = 1 //视频清晰度1-高清主码流、2-流畅(子码流)
_, err = ys.authorizeRequset("POST", DEVICELIVEADDRESS, params, &live)
if err != nil {
return nil, err
}
return live, nil
}