client

package
v0.0.0-...-ef65237 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2025 License: AGPL-3.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var XMLNamespaces = map[string]string{
	"onvif":   "http://www.onvif.org/ver10/schema",
	"tds":     "http://www.onvif.org/ver10/device/wsdl",
	"trt":     "http://www.onvif.org/ver10/media/wsdl",
	"tev":     "http://www.onvif.org/ver10/events/wsdl",
	"tptz":    "http://www.onvif.org/ver20/ptz/wsdl",
	"timg":    "http://www.onvif.org/ver20/imaging/wsdl",
	"tan":     "http://www.onvif.org/ver20/analytics/wsdl",
	"xmime":   "http://www.w3.org/2005/05/xmlmime",
	"wsnt":    "http://docs.oasis-open.org/wsn/b-2",
	"xop":     "http://www.w3.org/2004/08/xop/include",
	"wsa":     "http://www.w3.org/2005/08/addressing",
	"wstop":   "http://docs.oasis-open.org/wsn/t-1",
	"wsntw":   "http://docs.oasis-open.org/wsn/bw-2",
	"wsrf-rw": "http://docs.oasis-open.org/wsrf/rw-2",
	"wsaw":    "http://www.w3.org/2006/05/addressing/wsdl",
}

XMLNamespaces XML Scheam

Functions

func SetClient

func SetClient(addr string, username string, password string, client *Client)

SetClient 设置 ONVIF 客户端

Types

type BasicInfo

type BasicInfo struct {
	XAddrs          []string  `xorm:"blob 'xaddrs'"`    // xaddr 地址列表
	Addrs           []string  `json:"addrs"`            // 地址列表
	IPs             []string  `json:"ips"`              // ip列表
	Types           []string  `json:"types"`            // 类型列表
	Scopes          []string  `json:"scopes"`           // 域列表
	Locations       []string  `json:"locations"`        // 位置信息列表
	Profiles        []string  `json:"profiles"`         // 规范列表
	Names           []string  `json:"names"`            // 名称/型号列表
	Macs            []string  `json:"macs"`             // Mac 地址列表
	Hardwares       []string  `json:"hardwares"`        // 硬件信息列表
	MetadataVersion *int      `json:"metadata_version"` // 元数据版本
	Location        *Location `json:"location"`         // 地理位置信息
	Name            string    `json:"name"`             // 名称
	Brand           string    `json:"brand"`            // 品牌
	Model           string    `json:"model"`            // 型号
	Type            string    `json:"type"`             // 设备类型
	Mac             string    `json:"mac"`              // Mac 地址
	SerialNumber    string    `json:"serial_number"`    // 序列号
	Manufacturer    string    `json:"manufacturer"`     // 制造商/厂商
	FirmwareVersion string    `json:"firmware_version"` // 固件版本
	HardwareVersion string    `json:"hardware_version"` // 硬件版本
	SoftwareVersion string    `json:"software_version"` // 软件版本
}

设备基本信息

type Client

type Client struct {
	Config       *Config                       `json:"config"`       // 配置信息(设备连接参数)
	HttpClient   *http.Client                  `json:"-"`            // HTTP 客户端
	BasicInfo    *BasicInfo                    `json:"basic_info"`   // 设备基础信息(WS-Discovery结果)
	Endpoints    map[string]string             `json:"endpoints"`    // 服务能力节点/地址列表
	Nonces       map[string]DigestNonceContext `json:"-"`            // nonce 摘要认证的上下文信息
	RWMutex      sync.RWMutex                  `json:"-"`            // 保护 Nonces
	Capabilities *tt.Capabilities              `json:"capabilities"` // 能力列表
}

Client ONVIF 设备客户端

func GetClient

func GetClient(addr string, username string, password string) *Client

GetClient 获取 ONVIF 客户端

func New

func New(conf *Config) (*Client, error)

New 创建一个新的ONVIF设备客户端

func (*Client) AddEndpoint

func (cli *Client) AddEndpoint(Key, Value string)

AddEndpoint 添加服务能力节点/地址列表信息

func (*Client) BasicAuth

func (cli *Client) BasicAuth(endpoint string, method interface{}) (*http.Response, error)

BasicAuth 处理基本认证

func (*Client) BuildMethodSOAP

func (cli *Client) BuildMethodSOAP(msg string) (soap.SoapMessage, error)

BuildMethodSOAP 构建 SOAP 消息

func (*Client) CalculateMD5

func (cli *Client) CalculateMD5(data string) string

CalculateMD5 计算MD5哈希

func (*Client) CallMethod

func (cli *Client) CallMethod(method any) (*http.Response, error)

CallMethod 调用 ONVIF 方法,自动处理认证

func (*Client) DigestAuth

func (cli *Client) DigestAuth(endpoint string, method interface{}, Config map[string]string) (*http.Response, error)

DigestAuth 处理摘要认证

func (*Client) GenDigestAuthHeader

func (cli *Client) GenDigestAuthHeader(username, password, realm, nonce, qop, uri, method string) (string, error)

GenDigestAuthHeader 生成摘要认证头部

func (*Client) GenRandomCNonce

func (cli *Client) GenRandomCNonce() (string, error)

GenRandomCNonce 生成随机cnonce

func (*Client) GetAction

func (cli *Client) GetAction(method any) soap.Action

func (*Client) GetBasicInfo

func (cli *Client) GetBasicInfo() *BasicInfo

GetBasicInfo 获取设备基础信息(WS-Discovery结果)

func (*Client) GetConfig

func (cli *Client) GetConfig() *Config

GetConfig 获取配置信息(设备连接参数)

func (*Client) GetEndpoint

func (cli *Client) GetEndpoint(service string) (string, error)

GetEndpoint 获取服务能力节点/地址URL

func (*Client) GetHttpClient

func (cli *Client) GetHttpClient() *http.Client

GetHttpClient 获取 HTTP 客户端

func (*Client) GetIncrementNonceCount

func (cli *Client) GetIncrementNonceCount(nonce string) uint64

GetIncrementNonceCount 获取并增加 nonce 计数器

func (*Client) GetServiceName

func (cli *Client) GetServiceName(method any) string

GetServiceName 从方法类型获取服务名称

func (*Client) GetServices

func (cli *Client) GetServices() map[string]string

GetServices 获取服务能力节点/地址列表

func (*Client) GetSupportedServices

func (cli *Client) GetSupportedServices(resp *http.Response) error

GetSupportedServices 从 GetCapabilities(设备能力信息)请求方法响应中获取支持的服务列表[节点信息]

func (*Client) ParseAuthHeader

func (cli *Client) ParseAuthHeader(header string) (scheme string, Config map[string]string, err error)

ParseAuthHeader 解析 WWW-Authenticate 头部

func (*Client) SetHttpClient

func (cli *Client) SetHttpClient(client *http.Client)

SetHttpClient 设置 HTTP 客户端

func (*Client) UnAuthorized

func (cli *Client) UnAuthorized(endpoint string, method any, response *http.Response) (*http.Response, error)

UnAuthorized 处理 401 未授权响应

type Config

type Config struct {
	XAddr    string        `json:"xaddr"`    // 基础地址
	Username string        `json:"username"` // 用户名
	Password string        `json:"password"` // 密码
	Debug    bool          `json:"debug"`    // 调试模式
	Timeout  time.Duration `json:"timeout"`  // 超时时间
}

Config 设备连接配置

func (*Config) GetDebug

func (c *Config) GetDebug() bool

GetDebug 获取调试模式

func (*Config) GetPassword

func (c *Config) GetPassword() string

GetPassword 获取密码

func (*Config) GetTimeout

func (c *Config) GetTimeout() time.Duration

GetTimeout 设置超时时间

func (*Config) GetUsername

func (c *Config) GetUsername() string

GetUsername 获取用户名

func (*Config) GetXAddr

func (c *Config) GetXAddr() string

GetXAddr 获取基础地址

func (*Config) SetDebug

func (c *Config) SetDebug(debug bool)

SetDebug 设置调试模式

func (*Config) SetPassword

func (c *Config) SetPassword(password string)

SetPassword 设置密码

func (*Config) SetTimeout

func (c *Config) SetTimeout(timeout time.Duration)

SetTimeout 设置超时时间

func (*Config) SetUsername

func (c *Config) SetUsername(username string)

SetUsername 设置用户名

func (*Config) SetXAddr

func (c *Config) SetXAddr(xaddr string)

SetXAddr 设置基础地址

type DigestNonceContext

type DigestNonceContext struct {
	Nonce     string
	NC        uint64
	CNonce    string
	Timestamp time.Time
}

DigestNonceContext 存储摘要认证的上下文信息

type Location

type Location struct {
	Country  string `json:"country"`  // 国家/地区
	City     string `json:"city"`     // 城市
	Building string `json:"building"` // 建筑名称或编号
	Floor    string `json:"floor"`    // 楼层
	Area     string `json:"area"`     // 区域或房间号
	Rack     string `json:"rack"`     // 机架位置(IT设备适用)
}

地址位置信息

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL