3 Star 11 Fork 7

FlyCate / onvif

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
ws-discovery.go 2.24 KB
一键复制 编辑 原始数据 按行查看 历史
package wsdiscovery
import (
"strings"
"gitee.com/dzhw0314/onvif/gosoap"
"github.com/beevik/etree"
)
func buildProbeMessage(uuidV4 string, scopes, types []string, nmsp map[string]string) gosoap.SoapMessage {
//Список namespace
namespaces := make(map[string]string)
namespaces["a"] = "http://schemas.xmlsoap.org/ws/2004/08/addressing"
//namespaces["d"] = "http://schemas.xmlsoap.org/ws/2005/04/discovery"
probeMessage := gosoap.NewEmptySOAP()
probeMessage.AddRootNamespaces(namespaces)
//if len(nmsp) != 0 {
// probeMessage.AddRootNamespaces(nmsp)
//}
//fmt.Println(probeMessage.String())
//Содержимое Head
var headerContent []*etree.Element
action := etree.NewElement("a:Action")
action.SetText("http://schemas.xmlsoap.org/ws/2005/04/discovery/Probe")
action.CreateAttr("mustUnderstand", "1")
msgID := etree.NewElement("a:MessageID")
msgID.SetText("uuid:" + uuidV4)
replyTo := etree.NewElement("a:ReplyTo")
replyTo.CreateElement("a:Address").SetText("http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous")
to := etree.NewElement("a:To")
to.SetText("urn:schemas-xmlsoap-org:ws:2005:04:discovery")
to.CreateAttr("mustUnderstand", "1")
headerContent = append(headerContent, action, msgID, replyTo, to)
probeMessage.AddHeaderContents(headerContent)
//Содержимое Body
probe := etree.NewElement("Probe")
probe.CreateAttr("xmlns", "http://schemas.xmlsoap.org/ws/2005/04/discovery")
if len(types) != 0 {
typesTag := etree.NewElement("d:Types")
if len(nmsp) != 0 {
for key, value := range nmsp {
typesTag.CreateAttr("xmlns:"+key, value)
}
}
typesTag.CreateAttr("xmlns:d", "http://schemas.xmlsoap.org/ws/2005/04/discovery")
//typesTag.CreateAttr("xmlns:dp0", "http://www.onvif.org/ver10/network/wsdl")
var typesString string
for _, j := range types {
typesString += j
typesString += " "
}
typesTag.SetText(strings.TrimSpace(typesString))
probe.AddChild(typesTag)
}
if len(scopes) != 0 {
scopesTag := etree.NewElement("d:Scopes")
var scopesString string
for _, j := range scopes {
scopesString += j
scopesString += " "
}
scopesTag.SetText(strings.TrimSpace(scopesString))
probe.AddChild(scopesTag)
}
probeMessage.AddBodyContent(probe)
return probeMessage
}
Go
1
https://gitee.com/dzhw0314/onvif.git
git@gitee.com:dzhw0314/onvif.git
dzhw0314
onvif
onvif
v0.2.3

搜索帮助

53164aa7 5694891 3bd8fe86 5694891