isapi_system_time.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package isapi
  2. import (
  3. "encoding/xml"
  4. "net/url"
  5. )
  6. // Time
  7. type Time struct {
  8. XMLName xml.Name `xml:"Time,omitempty"`
  9. XMLVersion string `xml:"version,attr"`
  10. XMLNamespace string `xml:"xmlns,attr"`
  11. TimeMode string `xml:"timeMode,omitempty" json:"timeMode,omitempty"` //校时方式,[NTP#NTP校时,manual#手动校时,satellite#卫星校时,platform#平台校时,NONE#不允校时或无校时源,GB28181#GB28181校时,PTP#PTP校时]
  12. LocalTime string `xml:"localTime,omitempty" json:"localTime,omitempty"`
  13. TimeZone string `xml:"timeZone,omitempty" json:"timeZone,omitempty"` //CST为时区名称,-8:00:00为(UTC时间-本地时间)
  14. }
  15. // GetTime 获取时间信息
  16. func (c *Client) GetTime() (resp *Time, err error) {
  17. path := "/ISAPI/System/time"
  18. u, err := url.Parse(c.BaseURL + path)
  19. if err != nil {
  20. return nil, err
  21. }
  22. body, err := c.Get(u)
  23. if err != nil {
  24. return nil, err
  25. }
  26. err = xml.Unmarshal(body, &resp)
  27. if err != nil {
  28. return nil, err
  29. }
  30. return resp, nil
  31. }
  32. // PutTime 更新时间
  33. func (c *Client) PutTime(data []byte) (resp []byte, err error) {
  34. u, err := url.Parse(c.BaseURL + "/ISAPI/System/time")
  35. if err != nil {
  36. return nil, err
  37. }
  38. resp, err = c.PutXML(u, data)
  39. if err != nil {
  40. return nil, err
  41. }
  42. return resp, nil
  43. }