-
Notifications
You must be signed in to change notification settings - Fork 152
/
client.go
136 lines (96 loc) · 3.31 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package ocr
import (
"errors"
"fmt"
"github.com/ArtisanCloud/PowerLibs/v2/object"
"github.com/ArtisanCloud/PowerWeChat/v2/src/kernel"
"github.com/ArtisanCloud/PowerWeChat/v2/src/officialAccount/ocr/response"
)
type Client struct {
*kernel.BaseClient
AllowTypes []string
}
func NewClient(app kernel.ApplicationInterface) (*Client, error) {
baseClient, err := kernel.NewBaseClient(&app, nil)
if err != nil {
return nil, err
}
return &Client{
BaseClient: baseClient,
AllowTypes: []string{"photo", "scan"},
}, nil
}
// 身份证 OCR 识别接口
// https://developers.weixin.qq.com/doc/offiaccount/Intelligent_Interface/OCR.html
func (comp *Client) IDCard(path string, IDType string) (*response.ResponseOCRIDCard, error) {
if !object.ContainsString(comp.AllowTypes, IDType) {
return nil, errors.New(fmt.Sprintf("Unsupported media type: '%s'", IDType))
}
result := &response.ResponseOCRIDCard{}
params := &object.HashMap{
"type": IDType,
"img_url": path,
}
_, err := comp.HttpPost("cv/ocr/idcard", params, nil, result)
return result, err
}
// 银行卡 OCR 识别接口
// https://developers.weixin.qq.com/doc/offiaccount/Intelligent_Interface/OCR.html
func (comp *Client) BankCard(path string) (*response.ResponseOCRBankCard, error) {
result := &response.ResponseOCRBankCard{}
params := &object.HashMap{
"img_url": path,
}
_, err := comp.HttpPost("cv/ocr/bankcard", params, nil, result)
return result, err
}
// 驾驶证 OCR 识别接口
// https://developers.weixin.qq.com/doc/offiaccount/Intelligent_Interface/OCR.html
func (comp *Client) VehicleLicense(path string) (*response.ResponseOCRVehicleLicense, error) {
result := &response.ResponseOCRVehicleLicense{}
params := &object.HashMap{
"img_url": path,
}
_, err := comp.HttpPost("cv/ocr/drivinglicense", params, nil, result)
return result, err
}
// 驾驶证 OCR 识别接口
// https://developers.weixin.qq.com/doc/offiaccount/Intelligent_Interface/OCR.html
func (comp *Client) Driving(path string) (*response.ResponseOCRDriving, error) {
result := &response.ResponseOCRDriving{}
params := &object.HashMap{
"img_url": path,
}
_, err := comp.HttpPost("cv/ocr/driving", params, nil, result)
return result, err
}
// 营业执照 OCR 识别接口
// https://developers.weixin.qq.com/doc/offiaccount/Intelligent_Interface/OCR.html
func (comp *Client) BizLicense(path string) (*response.ResponseOCRBizLicense, error) {
result := &response.ResponseOCRBizLicense{}
params := &object.HashMap{
"img_url": path,
}
_, err := comp.HttpPost("cv/ocr/bizlicense", params, nil, result)
return result, err
}
// 通用印刷体 OCR 识别接口
// https://developers.weixin.qq.com/doc/offiaccount/Intelligent_Interface/OCR.html
func (comp *Client) Common(path string) (*response.ResponseOCRCommon, error) {
result := &response.ResponseOCRCommon{}
params := &object.HashMap{
"img_url": path,
}
_, err := comp.HttpPost("cv/ocr/comm", params, nil, result)
return result, err
}
// 车牌识别接口
// https://developers.weixin.qq.com/doc/offiaccount/Intelligent_Interface/OCR.html
func (comp *Client) PlateNumber(path string) (*response.ResponseOCRPlateNumber, error) {
result := &response.ResponseOCRPlateNumber{}
params := &object.HashMap{
"img_url": path,
}
_, err := comp.HttpPost("cv/ocr/platenum", params, nil, result)
return result, err
}