New file |
| | |
| | | package service |
| | | |
| | | import ( |
| | | "encoding/xml" |
| | | "gat1400Exchange/pkg/logger" |
| | | dac "github.com/xinsnake/go-http-digest-auth-client" |
| | | "io/ioutil" |
| | | ) |
| | | |
| | | // 设置其他字符的第一个, 位置固定位7 |
| | | // 摄像机信息暂时固定, 避免泄露 |
| | | const ( |
| | | HikISAPIOverlaySetUrl = "/ISAPI/System/Video/inputs/channels/1/overlays/text/7" |
| | | CameraWebAddr = "http://192.168.10.11:40080" |
| | | CameraWebUser = "admin" |
| | | CameraWebPassword = "a1234567" |
| | | ) |
| | | |
| | | type TextOverlay struct { |
| | | Id int64 `xml:"id"` |
| | | Enabled bool `xml:"enabled"` |
| | | PositionX int64 `xml:"positionX"` |
| | | PositionY int64 `xml:"positionY"` |
| | | DisplayText string `xml:"displayText"` |
| | | DirectAngle string `xml:"directAngle"` |
| | | IsPersistentText bool `xml:"isPersistentText"` |
| | | } |
| | | |
| | | func AddFloorToOSD(osdText string) { |
| | | overlay7Url := CameraWebAddr + HikISAPIOverlaySetUrl |
| | | rsp, err := ISAPIRequest(CameraWebUser, CameraWebPassword, "GET", overlay7Url, "") |
| | | if err != nil { |
| | | logger.Warn("Get osd info failure") |
| | | return |
| | | } |
| | | |
| | | var overlayText TextOverlay |
| | | err = xml.Unmarshal(rsp, &overlayText) |
| | | if err != nil { |
| | | logger.Warn("%s", err.Error()) |
| | | return |
| | | } |
| | | |
| | | overlayText.DisplayText = osdText |
| | | body, _ := xml.Marshal(overlayText) |
| | | _, err = ISAPIRequest(CameraWebUser, CameraWebPassword, "PUT", overlay7Url, string(body)) |
| | | if err != nil { |
| | | logger.Warn("Camera osd set failure!!") |
| | | return |
| | | } |
| | | } |
| | | |
| | | func ISAPIRequest(username, password, method, url, body string) ([]byte, error) { |
| | | dr := dac.NewRequest(username, password, method, url, body) |
| | | resp, err := dr.Execute() |
| | | if err != nil { |
| | | return nil, err |
| | | } |
| | | |
| | | defer resp.Body.Close() |
| | | |
| | | return ioutil.ReadAll(resp.Body) |
| | | } |