44import me .chanjar .weixin .common .error .WxErrorException ;
55import me .chanjar .weixin .mp .api .WxMpOcrService ;
66import 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 ;
712import me .chanjar .weixin .mp .bean .ocr .WxMpOcrIdCardResult ;
813import me .chanjar .weixin .mp .util .requestexecuter .ocr .OcrDiscernRequestExecutor ;
914
1217import java .net .URLEncoder ;
1318import java .nio .charset .StandardCharsets ;
1419
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 ;
1525import 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 ;
1631import static me .chanjar .weixin .mp .enums .WxMpApiUrl .Ocr .IDCARD ;
1732
1833/**
@@ -26,22 +41,116 @@ public class WxMpOcrServiceImpl implements WxMpOcrService {
2641 private final WxMpService wxMpService ;
2742
2843 @ Override
29- public WxMpOcrIdCardResult idCard (ImageType imgType , String imgUrl ) throws WxErrorException {
44+ public WxMpOcrIdCardResult idCard (String imgUrl ) throws WxErrorException {
3045 try {
3146 imgUrl = URLEncoder .encode (imgUrl , StandardCharsets .UTF_8 .name ());
3247 } catch (UnsupportedEncodingException e ) {
3348 // ignore cannot happen
3449 }
3550
3651 final String result = this .wxMpService .get (String .format (IDCARD .getUrl (this .wxMpService .getWxMpConfigStorage ()),
37- imgType . getType (), imgUrl ), null );
52+ imgUrl ), null );
3853 return WxMpOcrIdCardResult .fromJson (result );
3954 }
4055
4156 @ 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 );
4559 return WxMpOcrIdCardResult .fromJson (result );
4660 }
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+ }
47156}
0 commit comments