From 76e213cbef39f2525eefd27351959daea4a1b589 Mon Sep 17 00:00:00 2001 From: pg Date: Thu, 27 Feb 2025 23:50:52 +0800 Subject: [PATCH] fix: deviceinfo,catalog xml --- plugin/gb28181pro/device.go | 18 +++++++++--------- plugin/gb28181pro/index.go | 3 ++- plugin/gb28181pro/pkg/message.go | 20 ++++++++++++-------- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/plugin/gb28181pro/device.go b/plugin/gb28181pro/device.go index 69e1cee..b497647 100644 --- a/plugin/gb28181pro/device.go +++ b/plugin/gb28181pro/device.go @@ -202,18 +202,18 @@ func (d *Device) send(req *sip.Request) (*sip.Response, error) { func (d *Device) Go() (err error) { var response *sip.Response - response, err = d.catalog() - if err != nil { - d.Error("catalog", "err", err) - } else { - d.Debug("catalog", "response", response.String()) - } response, err = d.queryDeviceInfo() if err != nil { d.Error("deviceInfo", "err", err) } else { d.Debug("deviceInfo", "response", response.String()) } + response, err = d.catalog() + if err != nil { + d.Error("catalog", "err", err) + } else { + d.Debug("catalog", "response", response.String()) + } subTick := time.NewTicker(time.Second * 3600) defer subTick.Stop() catalogTick := time.NewTicker(time.Second * 60) @@ -295,20 +295,20 @@ func (d *Device) catalog() (*sip.Response, error) { request := d.CreateRequest(sip.MESSAGE, nil) //d.subscriber.Timeout = time.Now().Add(time.Second * time.Duration(expires)) request.AppendHeader(sip.NewHeader("Expires", "3600")) - request.SetBody(gb28181.BuildCatalogXML(d.SN, d.DeviceID)) + request.SetBody(gb28181.BuildCatalogXML(d.Charset, d.SN, d.DeviceID)) return d.send(request) } func (d *Device) subscribeCatalog() (*sip.Response, error) { request := d.CreateRequest(sip.SUBSCRIBE, nil) request.AppendHeader(sip.NewHeader("Expires", "3600")) - request.SetBody(gb28181.BuildCatalogXML(d.SN, d.DeviceID)) + request.SetBody(gb28181.BuildCatalogXML(d.Charset, d.SN, d.DeviceID)) return d.send(request) } func (d *Device) queryDeviceInfo() (*sip.Response, error) { request := d.CreateRequest(sip.MESSAGE, nil) - request.SetBody(gb28181.BuildDeviceInfoXML(d.SN, d.DeviceID)) + request.SetBody(gb28181.BuildDeviceInfoXML(d.SN, d.DeviceID, d.Charset)) return d.send(request) } diff --git a/plugin/gb28181pro/index.go b/plugin/gb28181pro/index.go index 694890e..2d138e1 100644 --- a/plugin/gb28181pro/index.go +++ b/plugin/gb28181pro/index.go @@ -553,7 +553,8 @@ func (gb *GB28181ProPlugin) StoreDevice(deviceid string, req *sip.Request) (d *D d.Logger = gb.With("deviceid", deviceid) d.fromHDR.Params.Add("tag", sip.GenerateTagN(16)) - d.client, _ = sipgo.NewClient(gb.ua, sipgo.WithClientLogger(zerolog.New(os.Stdout)), sipgo.WithClientHostname(host)) + d.client, _ = sipgo.NewClient(gb.ua, sipgo.WithClientLogger(zerolog.New(os.Stdout)), sipgo.WithClientHostname(host), sipgo.WithClientPort(serverPort)) + gb.Info("get serverport is ", serverPort) d.dialogClient = sipgo.NewDialogClient(d.client, d.contactHDR) d.channels.L = new(sync.RWMutex) d.Info("StoreDevice", "source", source, "desc", desc, "servIp", servIp, "publicIP", host, "recipient", req.Recipient) diff --git a/plugin/gb28181pro/pkg/message.go b/plugin/gb28181pro/pkg/message.go index 8218f85..d0d838e 100644 --- a/plugin/gb28181pro/pkg/message.go +++ b/plugin/gb28181pro/pkg/message.go @@ -16,14 +16,16 @@ import ( const ( // CatalogXML 获取设备列表xml样式 - CatalogXML = ` + CatalogXML = ` + Catalog %d %s ` // RecordInfoXML 获取录像文件列表xml样式 - RecordInfoXML = ` + RecordInfoXML = ` + RecordInfo %d %s @@ -34,14 +36,16 @@ const ( ` // DeviceInfoXML 查询设备详情xml样式 - DeviceInfoXML = ` + DeviceInfoXML = ` + DeviceInfo %d %s ` // DevicePositionXML 订阅设备位置 - DevicePositionXML = ` + DevicePositionXML = ` + MobilePosition %d %s @@ -82,13 +86,13 @@ func toGB2312(s string) []byte { } // BuildDeviceInfoXML 获取设备详情指令 -func BuildDeviceInfoXML(sn int, id string) []byte { - return toGB2312(fmt.Sprintf(DeviceInfoXML, sn, id)) +func BuildDeviceInfoXML(sn int, id string, charset string) []byte { + return toGB2312(fmt.Sprintf(DeviceInfoXML, charset, sn, id)) } // BuildCatalogXML 获取NVR下设备列表指令 -func BuildCatalogXML(sn int, id string) []byte { - return toGB2312(fmt.Sprintf(CatalogXML, sn, id)) +func BuildCatalogXML(charset string, sn int, id string) []byte { + return toGB2312(fmt.Sprintf(CatalogXML, charset, sn, id)) } // BuildRecordInfoXML 获取录像文件列表指令