1 Star 0 Fork 1

waiot/onvif

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
AddAudioEncoderConfiguration.go 2.28 KB
一键复制 编辑 原始数据 按行查看 历史
kokutas 提交于 2025-09-17 03:37 +08:00 . save
package media
import (
"context"
"regexp"
"errors"
"gitee.com/waiot/onvif/sdk"
soap "gitee.com/waiot/onvif/www.w3.org/2003/05/soapEnvelope"
"gitee.com/waiot/onvif/client"
"gitee.com/waiot/onvif/entity/ver10/media"
)
// AddAudioEncoderConfiguration forwards the call to cli.CallMethod() then parses the payload of the reply as a AddAudioEncoderConfigurationResponse.
func AddAudioEncoderConfiguration(ctx context.Context, cli *client.Client, request media.AddAudioEncoderConfiguration) (media.AddAudioEncoderConfigurationResponse, error) {
type Envelope struct {
// Header struct{}
Header *soap.Header `xml:"Header,omitempty"`
Body struct {
AddAudioEncoderConfigurationResponse media.AddAudioEncoderConfigurationResponse
Fault *soap.Fault `xml:"Fault,omitempty"`
}
}
var reply Envelope
response, err := cli.CallMethod(request)
if err != nil {
if response == nil {
return reply.Body.AddAudioEncoderConfigurationResponse, err
}
}
// 解析响应内容
if err := sdk.ReadAndParse(ctx, response, &reply, "AddAudioEncoderConfigurationResponse"); err != nil {
return reply.Body.AddAudioEncoderConfigurationResponse, err
}
// 检查SOAP Fault
if reply.Body.Fault != nil {
// 优先从Subcode中获取错误信息
if reply.Body.Fault.Code.Subcode != nil && len(reply.Body.Fault.Code.Subcode.Value) > 0 {
// 清理命名空间前缀,只保留错误码
err = errors.New(regexp.MustCompile(`.*:`).ReplaceAllString(string(reply.Body.Fault.Code.Subcode.Value), ""))
return reply.Body.AddAudioEncoderConfigurationResponse, err
}
if reply.Body.Fault.Code.Subcode != nil && reply.Body.Fault.Code.Subcode.Subcode != nil && len(reply.Body.Fault.Code.Subcode.Subcode.Value) > 0 {
// 清理命名空间前缀,只保留错误码
err = errors.New(regexp.MustCompile(`.*:`).ReplaceAllString(string(reply.Body.Fault.Code.Subcode.Subcode.Value), ""))
return reply.Body.AddAudioEncoderConfigurationResponse, err
}
// 从Reason中获取错误信息
if len(reply.Body.Fault.Reason.Text) > 0 {
// 优先使用第一个Reason Text(通常是默认语言)
for _, val := range reply.Body.Fault.Reason.Text {
err = errors.New(val.Value)
}
return reply.Body.AddAudioEncoderConfigurationResponse, err
}
}
return reply.Body.AddAudioEncoderConfigurationResponse, err
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/waiot/onvif.git
git@gitee.com:waiot/onvif.git
waiot
onvif
onvif
ef65237e8c45

搜索帮助