|
@@ -24,7 +24,6 @@ type Client struct {
|
|
BaseURL string
|
|
BaseURL string
|
|
}
|
|
}
|
|
|
|
|
|
-// NewClient 获取新的连接
|
|
|
|
func NewClient(host, username, password string) (*Client, error) {
|
|
func NewClient(host, username, password string) (*Client, error) {
|
|
u, err := url.Parse("http://" + host)
|
|
u, err := url.Parse("http://" + host)
|
|
if err != nil {
|
|
if err != nil {
|
|
@@ -38,23 +37,32 @@ func NewClient(host, username, password string) (*Client, error) {
|
|
}, nil
|
|
}, nil
|
|
}
|
|
}
|
|
|
|
|
|
-// TouChuan 透传
|
|
|
|
-func TouChuan(host string, o Operation, data []byte, c *gin.Context) ([]byte, error) {
|
|
|
|
- info, err := Com(host, o, data)
|
|
|
|
|
|
+func TouChuan(host string, o Operation, data []byte, c *gin.Context) (resp any, err error) {
|
|
|
|
+ resp, err = Com(host, o, data)
|
|
if err != nil {
|
|
if err != nil {
|
|
- return nil, fmt.Errorf("TouChuan错误: %e", err)
|
|
|
|
|
|
+ logrus.Error(err)
|
|
|
|
+ response.FailWithDetailed(resp.(ResponseStatus), err.Error(), c)
|
|
|
|
+ return
|
|
}
|
|
}
|
|
- if err != nil {
|
|
|
|
- response.FailWithMessage(err.Error(), c)
|
|
|
|
- logrus.Errorf("%s error: %e", o, err)
|
|
|
|
- return nil, err
|
|
|
|
|
|
+ //断言成功,说明是配置响应,检查配置结果
|
|
|
|
+ r, ok := resp.(ResponseStatus)
|
|
|
|
+ if ok {
|
|
|
|
+ if r.StatusCode == 0 || r.StatusCode == 1 {
|
|
|
|
+ response.OkWithDetailed(resp, "操作成功", c)
|
|
|
|
+ return
|
|
|
|
+ } else {
|
|
|
|
+ response.FailWithDetailed(resp, "操作失败,请联系管理员", c)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- c.Data(200, `application/xml; charset="UTF-8"`, info)
|
|
|
|
- return info, nil
|
|
|
|
|
|
+ //断言失败,说明是查询响应,直接返回数据
|
|
|
|
+ response.OkWithData(resp, c)
|
|
|
|
+ return
|
|
}
|
|
}
|
|
|
|
|
|
// Com 透传
|
|
// Com 透传
|
|
-func Com(host string, o Operation, data []byte) ([]byte, error) {
|
|
|
|
|
|
+func Com(host string, o Operation, data []byte) (any, error) {
|
|
|
|
+ //TODO 应该使用公共的http client
|
|
c, err := NewClient(host, "admin", "kk176@lc")
|
|
c, err := NewClient(host, "admin", "kk176@lc")
|
|
if err != nil {
|
|
if err != nil {
|
|
return nil, err
|
|
return nil, err
|
|
@@ -66,6 +74,16 @@ func Com(host string, o Operation, data []byte) ([]byte, error) {
|
|
return c.GetSystemCap()
|
|
return c.GetSystemCap()
|
|
case GetChanCap:
|
|
case GetChanCap:
|
|
return c.GetOneChanEventCap()
|
|
return c.GetOneChanEventCap()
|
|
|
|
+ //遮盖侦测
|
|
|
|
+ //case GetTamperDetection:
|
|
|
|
+ // return c.GetTamperDetection("1")
|
|
|
|
+ //case PutTamperDetection:
|
|
|
|
+ // return c.PutTamperDetection("1", data)
|
|
|
|
+ //移动侦测
|
|
|
|
+ //case GetMotionDetection:
|
|
|
|
+ // return c.GetMotionDetection("1")
|
|
|
|
+ //case PutMotionDetection:
|
|
|
|
+ // return c.PutMotionDetection("1", data)
|
|
//越界侦测
|
|
//越界侦测
|
|
case GetLineDetectionCap:
|
|
case GetLineDetectionCap:
|
|
return c.GetLineDetectionCap()
|
|
return c.GetLineDetectionCap()
|
|
@@ -100,6 +118,10 @@ func Com(host string, o Operation, data []byte) ([]byte, error) {
|
|
case PutRegionEntrance:
|
|
case PutRegionEntrance:
|
|
return c.PutRegionEntrance(data)
|
|
return c.PutRegionEntrance(data)
|
|
//离开区域
|
|
//离开区域
|
|
|
|
+ //case GetRegionExiting:
|
|
|
|
+ // return c.GetRegionExiting()
|
|
|
|
+ //case PutRegionExiting:
|
|
|
|
+ // return c.PutRegionExiting(data)
|
|
case SetHosts:
|
|
case SetHosts:
|
|
return c.PutHost(data)
|
|
return c.PutHost(data)
|
|
case SetSIP:
|
|
case SetSIP:
|