4
4
import me .chanjar .weixin .common .error .WxErrorException ;
5
5
import me .chanjar .weixin .mp .api .WxMpOcrService ;
6
6
import me .chanjar .weixin .mp .api .WxMpService ;
7
+ import me .chanjar .weixin .mp .bean .ocr .WxMpOcrBankCardResult ;
8
+ import me .chanjar .weixin .mp .bean .ocr .WxMpOcrBizLicenseResult ;
9
+ import me .chanjar .weixin .mp .bean .ocr .WxMpOcrCommResult ;
10
+ import me .chanjar .weixin .mp .bean .ocr .WxMpOcrDrivingLicenseResult ;
11
+ import me .chanjar .weixin .mp .bean .ocr .WxMpOcrDrivingResult ;
7
12
import me .chanjar .weixin .mp .bean .ocr .WxMpOcrIdCardResult ;
8
13
import me .chanjar .weixin .mp .util .requestexecuter .ocr .OcrDiscernRequestExecutor ;
9
14
12
17
import java .net .URLEncoder ;
13
18
import java .nio .charset .StandardCharsets ;
14
19
20
+ import static me .chanjar .weixin .mp .enums .WxMpApiUrl .Ocr .BANK_CARD ;
21
+ import static me .chanjar .weixin .mp .enums .WxMpApiUrl .Ocr .BIZ_LICENSE ;
22
+ import static me .chanjar .weixin .mp .enums .WxMpApiUrl .Ocr .COMM ;
23
+ import static me .chanjar .weixin .mp .enums .WxMpApiUrl .Ocr .DRIVING ;
24
+ import static me .chanjar .weixin .mp .enums .WxMpApiUrl .Ocr .DRIVING_LICENSE ;
15
25
import static me .chanjar .weixin .mp .enums .WxMpApiUrl .Ocr .FILEIDCARD ;
26
+ import static me .chanjar .weixin .mp .enums .WxMpApiUrl .Ocr .FILE_BANK_CARD ;
27
+ import static me .chanjar .weixin .mp .enums .WxMpApiUrl .Ocr .FILE_BIZ_LICENSE ;
28
+ import static me .chanjar .weixin .mp .enums .WxMpApiUrl .Ocr .FILE_COMM ;
29
+ import static me .chanjar .weixin .mp .enums .WxMpApiUrl .Ocr .FILE_DRIVING ;
30
+ import static me .chanjar .weixin .mp .enums .WxMpApiUrl .Ocr .FILE_DRIVING_LICENSE ;
16
31
import static me .chanjar .weixin .mp .enums .WxMpApiUrl .Ocr .IDCARD ;
17
32
18
33
/**
@@ -26,22 +41,116 @@ public class WxMpOcrServiceImpl implements WxMpOcrService {
26
41
private final WxMpService wxMpService ;
27
42
28
43
@ Override
29
- public WxMpOcrIdCardResult idCard (ImageType imgType , String imgUrl ) throws WxErrorException {
44
+ public WxMpOcrIdCardResult idCard (String imgUrl ) throws WxErrorException {
30
45
try {
31
46
imgUrl = URLEncoder .encode (imgUrl , StandardCharsets .UTF_8 .name ());
32
47
} catch (UnsupportedEncodingException e ) {
33
48
// ignore cannot happen
34
49
}
35
50
36
51
final String result = this .wxMpService .get (String .format (IDCARD .getUrl (this .wxMpService .getWxMpConfigStorage ()),
37
- imgType . getType (), imgUrl ), null );
52
+ imgUrl ), null );
38
53
return WxMpOcrIdCardResult .fromJson (result );
39
54
}
40
55
41
56
@ Override
42
- public WxMpOcrIdCardResult idCard (ImageType imgType , File imgFile ) throws WxErrorException {
43
- String result = this .wxMpService .execute (OcrDiscernRequestExecutor .create (this .wxMpService .getRequestHttp ()), String .format (FILEIDCARD .getUrl (this .wxMpService .getWxMpConfigStorage ()),
44
- imgType .getType ()), imgFile );
57
+ public WxMpOcrIdCardResult idCard (File imgFile ) throws WxErrorException {
58
+ String result = this .wxMpService .execute (OcrDiscernRequestExecutor .create (this .wxMpService .getRequestHttp ()), FILEIDCARD .getUrl (this .wxMpService .getWxMpConfigStorage ()), imgFile );
45
59
return WxMpOcrIdCardResult .fromJson (result );
46
60
}
61
+
62
+ @ Override
63
+ public WxMpOcrBankCardResult bankCard (String imgUrl ) throws WxErrorException {
64
+ try {
65
+ imgUrl = URLEncoder .encode (imgUrl , StandardCharsets .UTF_8 .name ());
66
+ } catch (UnsupportedEncodingException e ) {
67
+ // ignore cannot happen
68
+ }
69
+
70
+ final String result = this .wxMpService .get (String .format (BANK_CARD .getUrl (this .wxMpService .getWxMpConfigStorage ()),
71
+ imgUrl ), null );
72
+ return WxMpOcrBankCardResult .fromJson (result );
73
+ }
74
+
75
+ @ Override
76
+ public WxMpOcrBankCardResult bankCard (File imgFile ) throws WxErrorException {
77
+ String result = this .wxMpService .execute (OcrDiscernRequestExecutor .create (this .wxMpService .getRequestHttp ()), FILE_BANK_CARD .getUrl (this .wxMpService .getWxMpConfigStorage ()), imgFile );
78
+ return WxMpOcrBankCardResult .fromJson (result );
79
+ }
80
+
81
+ @ Override
82
+ public WxMpOcrDrivingResult driving (String imgUrl ) throws WxErrorException {
83
+ try {
84
+ imgUrl = URLEncoder .encode (imgUrl , StandardCharsets .UTF_8 .name ());
85
+ } catch (UnsupportedEncodingException e ) {
86
+ // ignore cannot happen
87
+ }
88
+
89
+ final String result = this .wxMpService .get (String .format (DRIVING .getUrl (this .wxMpService .getWxMpConfigStorage ()),
90
+ imgUrl ), null );
91
+ return WxMpOcrDrivingResult .fromJson (result );
92
+ }
93
+
94
+ @ Override
95
+ public WxMpOcrDrivingResult driving (File imgFile ) throws WxErrorException {
96
+ String result = this .wxMpService .execute (OcrDiscernRequestExecutor .create (this .wxMpService .getRequestHttp ()), FILE_DRIVING .getUrl (this .wxMpService .getWxMpConfigStorage ()), imgFile );
97
+ return WxMpOcrDrivingResult .fromJson (result );
98
+ }
99
+
100
+ @ Override
101
+ public WxMpOcrDrivingLicenseResult drivingLicense (String imgUrl ) throws WxErrorException {
102
+ try {
103
+ imgUrl = URLEncoder .encode (imgUrl , StandardCharsets .UTF_8 .name ());
104
+ } catch (UnsupportedEncodingException e ) {
105
+ // ignore cannot happen
106
+ }
107
+
108
+ final String result = this .wxMpService .get (String .format (DRIVING_LICENSE .getUrl (this .wxMpService .getWxMpConfigStorage ()),
109
+ imgUrl ), null );
110
+ return WxMpOcrDrivingLicenseResult .fromJson (result );
111
+ }
112
+
113
+ @ Override
114
+ public WxMpOcrDrivingLicenseResult drivingLicense (File imgFile ) throws WxErrorException {
115
+ String result = this .wxMpService .execute (OcrDiscernRequestExecutor .create (this .wxMpService .getRequestHttp ()), FILE_DRIVING_LICENSE .getUrl (this .wxMpService .getWxMpConfigStorage ()), imgFile );
116
+ return WxMpOcrDrivingLicenseResult .fromJson (result );
117
+ }
118
+
119
+ @ Override
120
+ public WxMpOcrBizLicenseResult bizLicense (String imgUrl ) throws WxErrorException {
121
+ try {
122
+ imgUrl = URLEncoder .encode (imgUrl , StandardCharsets .UTF_8 .name ());
123
+ } catch (UnsupportedEncodingException e ) {
124
+ // ignore cannot happen
125
+ }
126
+
127
+ final String result = this .wxMpService .get (String .format (BIZ_LICENSE .getUrl (this .wxMpService .getWxMpConfigStorage ()),
128
+ imgUrl ), null );
129
+ return WxMpOcrBizLicenseResult .fromJson (result );
130
+ }
131
+
132
+ @ Override
133
+ public WxMpOcrBizLicenseResult bizLicense (File imgFile ) throws WxErrorException {
134
+ String result = this .wxMpService .execute (OcrDiscernRequestExecutor .create (this .wxMpService .getRequestHttp ()), FILE_BIZ_LICENSE .getUrl (this .wxMpService .getWxMpConfigStorage ()), imgFile );
135
+ return WxMpOcrBizLicenseResult .fromJson (result );
136
+ }
137
+
138
+ @ Override
139
+ public WxMpOcrCommResult comm (String imgUrl ) throws WxErrorException {
140
+ try {
141
+ imgUrl = URLEncoder .encode (imgUrl , StandardCharsets .UTF_8 .name ());
142
+ } catch (UnsupportedEncodingException e ) {
143
+ // ignore cannot happen
144
+ }
145
+
146
+ final String result = this .wxMpService .get (String .format (COMM .getUrl (this .wxMpService .getWxMpConfigStorage ()),
147
+ imgUrl ), null );
148
+ return WxMpOcrCommResult .fromJson (result );
149
+ }
150
+
151
+ @ Override
152
+ public WxMpOcrCommResult comm (File imgFile ) throws WxErrorException {
153
+ String result = this .wxMpService .execute (OcrDiscernRequestExecutor .create (this .wxMpService .getRequestHttp ()), FILE_COMM .getUrl (this .wxMpService .getWxMpConfigStorage ()), imgFile );
154
+ return WxMpOcrCommResult .fromJson (result );
155
+ }
47
156
}
0 commit comments