mirror of
https://github.com/zxbit2011/hikvisionOpenAPIGo.git
synced 2025-12-24 13:37:59 +08:00
add result
This commit is contained in:
@@ -2,11 +2,9 @@
|
||||
> 海康威视OpenAPI安全认证库 - Golang版本实现
|
||||
# 官网
|
||||
|
||||
接口调用认证:
|
||||
https://open.hikvision.com/docs/7d0beeded66543999bff7bc2f91414d4
|
||||
接口调用认证:[文档说明](https://open.hikvision.com/docs/7d0beeded66543999bff7bc2f91414d4)
|
||||
|
||||
其他语言版本:
|
||||
https://open.hikvision.com/download/5c67f1e2f05948198c909700?type=10
|
||||
其他语言版本:[下载链接](https://open.hikvision.com/download/5c67f1e2f05948198c909700?type=10)
|
||||
# 快速使用
|
||||
````
|
||||
> go get github.com/zxbit2011/hikvisionOpenAPIGo
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
package examples
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/zxbit2011/hikvisionOpenAPIGo"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSDK(t *testing.T) {
|
||||
hk := hikvisionOpenAPIGo.HKConfig{
|
||||
Ip: "172.17.207.240",
|
||||
Ip: "127.0.0.1",
|
||||
Port: 443,
|
||||
AppKey: "28057383",
|
||||
Secret: "dZztQSSUAF4kLpURGQMa",
|
||||
AppKey: "28057000",
|
||||
Secret: "dZztQSS0000kLpURG000",
|
||||
IsHttps: true,
|
||||
}
|
||||
|
||||
@@ -23,16 +24,18 @@ func TestSDK(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
return
|
||||
}
|
||||
t.Log("OK", string(result))
|
||||
resJson, err := json.Marshal(result)
|
||||
t.Log("OK", string(resJson))
|
||||
|
||||
/*body := map[string]string{
|
||||
"cameraIndexCode": "71c1e8bd1b0d406a94e7cdf88a251f9b",
|
||||
"protocol": "rtmp",
|
||||
}
|
||||
result, err := hk.Post("/artemis/api/video/v2/cameras/previewURLs", body, 15)
|
||||
result, err := hk.HttpPost("/artemis/api/video/v2/cameras/previewURLs", body, 15)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
return
|
||||
}
|
||||
t.Log("OK", string(result))*/
|
||||
resJson, err := json.Marshal(result)
|
||||
t.Log("OK", string(resJson))*/
|
||||
}
|
||||
|
||||
26
sdk.go
26
sdk.go
@@ -27,11 +27,26 @@ type HKConfig struct {
|
||||
IsHttps bool //是否使用HTTPS协议
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
type Result struct {
|
||||
Code string `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
Data interface{} `json:"data"`
|
||||
}
|
||||
|
||||
// 返回值data
|
||||
type Data struct {
|
||||
Total int `json:"total"`
|
||||
PageSize int `json:"pageSize"`
|
||||
PageNo int `json:"pageNo"`
|
||||
List []map[string]interface{} `json:"list"`
|
||||
}
|
||||
|
||||
// @title HTTP Post请求
|
||||
// @url HTTP接口Url string HTTP接口Url,不带协议和端口,如/artemis/api/resource/v1/org/advance/orgList
|
||||
// @body 请求参数 map[string]string
|
||||
// @return 请求结果 参数类型
|
||||
func (hk HKConfig) HttpPost(url string, body map[string]string, timeout int) (result []byte, err error) {
|
||||
func (hk HKConfig) HttpPost(url string, body map[string]string, timeout int) (result Result, err error) {
|
||||
var header = make(map[string]string)
|
||||
bodyJson := MustJsonString(body)
|
||||
hk.initRequest(header, url, bodyJson, true)
|
||||
@@ -75,7 +90,12 @@ func (hk HKConfig) HttpPost(url string, body map[string]string, timeout int) (re
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode == http.StatusOK {
|
||||
result, err = ioutil.ReadAll(resp.Body)
|
||||
var resBody []byte
|
||||
resBody, err = ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = json.Unmarshal(resBody, &result)
|
||||
} else if resp.StatusCode == http.StatusFound || resp.StatusCode == http.StatusMovedPermanently {
|
||||
reqUrl := resp.Header.Get("Location")
|
||||
panic(fmt.Errorf("HttpPost Response StatusCode:%d,Location:%s", resp.StatusCode, reqUrl))
|
||||
@@ -113,7 +133,7 @@ func (hk HKConfig) initRequest(header map[string]string, url, body string, isPos
|
||||
|
||||
// computeContentMd5 计算content-md5
|
||||
func computeContentMd5(body string) string {
|
||||
return base64.StdEncoding.EncodeToString([]byte( Md5(body)))
|
||||
return base64.StdEncoding.EncodeToString([]byte(Md5(body)))
|
||||
}
|
||||
|
||||
// computeForHMACSHA256 计算HMACSHA265
|
||||
|
||||
Reference in New Issue
Block a user