-
Notifications
You must be signed in to change notification settings - Fork 165
/
client.go
76 lines (54 loc) · 2.14 KB
/
client.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
66
67
68
69
70
71
72
73
74
75
76
package image
import (
"errors"
"github.com/ArtisanCloud/PowerLibs/v3/object"
"github.com/ArtisanCloud/PowerWeChat/v3/src/kernel"
"github.com/ArtisanCloud/PowerWeChat/v3/src/kernel/power"
"github.com/ArtisanCloud/PowerWeChat/v3/src/miniProgram/image/response"
)
type Client struct {
*kernel.BaseClient
}
// 本接口提供基于小程序的图片智能裁剪能力
// https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/img/img.aiCrop.html
func (comp *Client) AICrop(imgURL string, img *power.HashMap) (*response.ResponseIMGAICrop, error) {
result := &response.ResponseIMGAICrop{}
_, err := comp.UploadImage("cv/img/aicrop", imgURL, img, result)
return result, err
}
// 本接口提供基于小程序的条码/二维码识别的API
// https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/img/img.scanQRCode.html
func (comp *Client) ScanQRCode(imgURL string, img *power.HashMap) (*response.ResponseIMGScanQRCode, error) {
result := &response.ResponseIMGScanQRCode{}
_, err := comp.UploadImage("cv/img/aicrop", imgURL, img, result)
return result, err
}
// 本接口提供基于小程序的图片高清化能力
// https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/img/img.superresolution.html
func (comp *Client) SuperResolution(imgURL string, img *power.HashMap) (*response.ResponseIMGSuperResolution, error) {
result := &response.ResponseIMGSuperResolution{}
_, err := comp.UploadImage("cv/img/superresolution", imgURL, img, result)
return result, err
}
func (comp *Client) UploadImage(entryPoint string, imgURL string, img *power.HashMap, result interface{}) (interface{}, error) {
params := &object.StringMap{}
var formData *kernel.UploadForm
if imgURL != "" {
params = &object.StringMap{
"img_url": imgURL,
}
} else if img != nil {
formData = &kernel.UploadForm{
Contents: []*kernel.UploadContent{
&kernel.UploadContent{
Name: (*img)["name"].(string),
Value: (*img)["value"],
},
},
}
} else {
return nil, errors.New("Please send image url or image form data ")
}
rs, err := comp.HttpUpload(entryPoint, nil, formData, params, nil, result)
return rs, err
}