github.com/use-go/onvif

1. Installation use-go/onvif

go get github.com/use-go/onvif

2. 新建连接并获取摄像头基础信息

package main

import (
    "context"
    "fmt"
    goonvif "github.com/use-go/onvif"
    "github.com/use-go/onvif/device"
    sdkdevice "github.com/use-go/onvif/sdk/device"
    "net/http"
)

var (
    xaddr    = "192.168.1.100:80"
    username = "onvif"
    password = "onvifpassword"
)

func main() {
    ctx := context.Background()
    dev, err := goonvif.NewDevice(goonvif.DeviceParams{
        Xaddr:      xaddr,
        Username:   username,
        Password:   password,
        HttpClient: new(http.Client),
    })
    if err != nil {
        panic(err)
    }
    // 读取设备基础信息
    GetDeviceInformation(ctx, dev)
}

// GetDeviceInformation 读取设备基础信息
// @author: Sen
// @date  : 2023-03-09 16:36:16
func GetDeviceInformation(ctx context.Context, dev *goonvif.Device) {
    // 读取设备基础信息
    getDeviceInformation := device.GetDeviceInformation{}
    getDeviceInformationResponse, err := sdkdevice.Call_GetDeviceInformation(ctx, dev, getDeviceInformation)
    if err != nil {
        panic(err)
    }
    //HardwareId      string //固件ID/设备编号
    //SerialNumber    string //设备序列号
    //FirmwareVersion string //固件版本
    //Model           string //设备类型
    //Manufacturer    string //厂家信息
    fmt.Println("getDeviceInformationResponse:")
    fmt.Println(getDeviceInformationResponse)
}

3. 备注

use-go/onvif

海康摄像头的配置路径:管理后台 -> 配置 -> 网络 -> 高级配置 -> 集成协议