-
Notifications
You must be signed in to change notification settings - Fork 0
/
image.go
65 lines (57 loc) · 1.38 KB
/
image.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package netease
import (
"encoding/json"
"errors"
"fmt"
"net/url"
"github.com/lcr2000/goutils"
"github.com/lcr2000/netease-detect/model"
)
/*
图片在线检测文档地址
https://support.dun.163.com/documents/2018041902?docId=424387300808773632
*/
// ImageDetect 图片检测
func (c *Client) ImageDetect(req *model.ImageDetectReq) (rsp *model.ImageDetectResp, err error) {
if req == nil || len(req.Images) == 0 {
err = errors.New("params is required")
return
}
// 单次请求最多支持32张图片
if len(req.Images) > 32 {
err = errors.New("support up to 32 images")
return
}
params := url.Values{
"images": []string{goutils.JsonMarshalNoError(req.Images)},
"version": []string{"v4.1"},
}
// 业务参数
if req.IP != "" {
params["ip"] = []string{req.IP}
}
if len(req.CheckLabels) > 0 {
params["checkLabels"] = req.CheckLabels
}
if req.SubProduct != "" {
params["subProduct"] = []string{req.SubProduct}
}
if req.Extension != "" {
params["extension"] = []string{req.Extension}
}
// 业务拓展参数
model.SplicingBusinessExpansion(req.BusinessExtension, params)
bytes, err := c.Request(ImageURL, "v4.1", params)
if err != nil {
return
}
rsp = &model.ImageDetectResp{}
if err = json.Unmarshal(bytes, &rsp); err != nil {
return
}
if rsp.Code != CallSuccessCode {
err = fmt.Errorf("ImageDetect fail, code=%v", rsp.Code)
return
}
return
}