Skip to content

Commit 6a27b83

Browse files
committed
🐛 修复公众号和小程序的OCR相关接口请求方式为post
1 parent fbe2dd9 commit 6a27b83

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaOcrServiceImpl.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public WxOcrIdCardResult idCard(String imgUrl) throws WxErrorException {
4343
// ignore cannot happen
4444
}
4545

46-
final String result = this.mainService.get(String.format(IDCARD, imgUrl), null);
46+
final String result = this.mainService.post(String.format(IDCARD, imgUrl), null);
4747
return WxOcrIdCardResult.fromJson(result);
4848
}
4949

@@ -62,7 +62,7 @@ public WxOcrBankCardResult bankCard(String imgUrl) throws WxErrorException {
6262
// ignore cannot happen
6363
}
6464

65-
final String result = this.mainService.get(String.format(BANK_CARD, imgUrl), null);
65+
final String result = this.mainService.post(String.format(BANK_CARD, imgUrl), null);
6666
return WxOcrBankCardResult.fromJson(result);
6767
}
6868

@@ -81,7 +81,7 @@ public WxOcrDrivingResult driving(String imgUrl) throws WxErrorException {
8181
// ignore cannot happen
8282
}
8383

84-
final String result = this.mainService.get(String.format(DRIVING, imgUrl), null);
84+
final String result = this.mainService.post(String.format(DRIVING, imgUrl), null);
8585
return WxOcrDrivingResult.fromJson(result);
8686
}
8787

@@ -100,7 +100,7 @@ public WxOcrDrivingLicenseResult drivingLicense(String imgUrl) throws WxErrorExc
100100
// ignore cannot happen
101101
}
102102

103-
final String result = this.mainService.get(String.format(DRIVING_LICENSE, imgUrl), null);
103+
final String result = this.mainService.post(String.format(DRIVING_LICENSE, imgUrl), null);
104104
return WxOcrDrivingLicenseResult.fromJson(result);
105105
}
106106

@@ -119,7 +119,7 @@ public WxOcrBizLicenseResult bizLicense(String imgUrl) throws WxErrorException {
119119
// ignore cannot happen
120120
}
121121

122-
final String result = this.mainService.get(String.format(BIZ_LICENSE, imgUrl), null);
122+
final String result = this.mainService.post(String.format(BIZ_LICENSE, imgUrl), null);
123123
return WxOcrBizLicenseResult.fromJson(result);
124124
}
125125

@@ -138,7 +138,7 @@ public WxOcrCommResult comm(String imgUrl) throws WxErrorException {
138138
// ignore cannot happen
139139
}
140140

141-
final String result = this.mainService.get(String.format(COMM, imgUrl), null);
141+
final String result = this.mainService.post(String.format(COMM, imgUrl), null);
142142
return WxOcrCommResult.fromJson(result);
143143
}
144144

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpOcrServiceImpl.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public WxOcrIdCardResult idCard(String imgUrl) throws WxErrorException {
4848
// ignore cannot happen
4949
}
5050

51-
final String result = this.mainService.get(String.format(IDCARD.getUrl(this.mainService.getWxMpConfigStorage()),
51+
final String result = this.mainService.post(String.format(IDCARD.getUrl(this.mainService.getWxMpConfigStorage()),
5252
imgUrl), null);
5353
return WxOcrIdCardResult.fromJson(result);
5454
}
@@ -68,7 +68,7 @@ public WxOcrBankCardResult bankCard(String imgUrl) throws WxErrorException {
6868
// ignore cannot happen
6969
}
7070

71-
final String result = this.mainService.get(String.format(BANK_CARD.getUrl(this.mainService.getWxMpConfigStorage()),
71+
final String result = this.mainService.post(String.format(BANK_CARD.getUrl(this.mainService.getWxMpConfigStorage()),
7272
imgUrl), null);
7373
return WxOcrBankCardResult.fromJson(result);
7474
}
@@ -88,7 +88,7 @@ public WxOcrDrivingResult driving(String imgUrl) throws WxErrorException {
8888
// ignore cannot happen
8989
}
9090

91-
final String result = this.mainService.get(String.format(DRIVING.getUrl(this.mainService.getWxMpConfigStorage()),
91+
final String result = this.mainService.post(String.format(DRIVING.getUrl(this.mainService.getWxMpConfigStorage()),
9292
imgUrl), null);
9393
return WxOcrDrivingResult.fromJson(result);
9494
}
@@ -108,7 +108,7 @@ public WxOcrDrivingLicenseResult drivingLicense(String imgUrl) throws WxErrorExc
108108
// ignore cannot happen
109109
}
110110

111-
final String result = this.mainService.get(String.format(DRIVING_LICENSE.getUrl(this.mainService.getWxMpConfigStorage()),
111+
final String result = this.mainService.post(String.format(DRIVING_LICENSE.getUrl(this.mainService.getWxMpConfigStorage()),
112112
imgUrl), null);
113113
return WxOcrDrivingLicenseResult.fromJson(result);
114114
}
@@ -128,7 +128,7 @@ public WxOcrBizLicenseResult bizLicense(String imgUrl) throws WxErrorException {
128128
// ignore cannot happen
129129
}
130130

131-
final String result = this.mainService.get(String.format(BIZ_LICENSE.getUrl(this.mainService.getWxMpConfigStorage()),
131+
final String result = this.mainService.post(String.format(BIZ_LICENSE.getUrl(this.mainService.getWxMpConfigStorage()),
132132
imgUrl), null);
133133
return WxOcrBizLicenseResult.fromJson(result);
134134
}
@@ -148,7 +148,7 @@ public WxOcrCommResult comm(String imgUrl) throws WxErrorException {
148148
// ignore cannot happen
149149
}
150150

151-
final String result = this.mainService.get(String.format(COMM.getUrl(this.mainService.getWxMpConfigStorage()),
151+
final String result = this.mainService.post(String.format(COMM.getUrl(this.mainService.getWxMpConfigStorage()),
152152
imgUrl), null);
153153
return WxOcrCommResult.fromJson(result);
154154
}

weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpOcrServiceImplTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,13 @@ private InputStream getImageStream(String url) {
153153
}
154154

155155
public static class MockTest {
156-
private WxMpService wxService = mock(WxMpService.class);
156+
private final WxMpService wxService = mock(WxMpService.class);
157157

158158
@Test
159159
public void testIdCard() throws Exception {
160160
String returnJson = "{\"type\":\"Back\",\"name\":\"张三\",\"id\":\"110101199909090099\",\"valid_date\":\"20110101-20210201\"}";
161161

162-
when(wxService.get(anyString(), anyString())).thenReturn(returnJson);
162+
when(wxService.post(anyString(), anyString())).thenReturn(returnJson);
163163
final WxMpOcrServiceImpl wxMpOcrService = new WxMpOcrServiceImpl(wxService);
164164

165165
final WxOcrIdCardResult result = wxMpOcrService.idCard("abc");
@@ -171,7 +171,7 @@ public void testIdCard() throws Exception {
171171
public void testBankCard() throws Exception {
172172
String returnJson = "{\"number\":\"24234234345234\"}";
173173

174-
when(wxService.get(anyString(), anyString())).thenReturn(returnJson);
174+
when(wxService.post(anyString(), anyString())).thenReturn(returnJson);
175175
final WxMpOcrServiceImpl wxMpOcrService = new WxMpOcrServiceImpl(wxService);
176176

177177
final WxOcrBankCardResult result = wxMpOcrService.bankCard("abc");
@@ -246,7 +246,7 @@ public void testDriving() throws Exception {
246246
" }\n" +
247247
"}";
248248

249-
when(wxService.get(anyString(), anyString())).thenReturn(returnJson);
249+
when(wxService.post(anyString(), anyString())).thenReturn(returnJson);
250250
final WxMpOcrServiceImpl wxMpOcrService = new WxMpOcrServiceImpl(wxService);
251251

252252
final WxOcrDrivingResult result = wxMpOcrService.driving("abc");
@@ -271,7 +271,7 @@ public void testDrivingLicense() throws Exception {
271271
" \"valid_to\": \"2020-07-01\", //有效期限终止日\n" +
272272
" \"official_seal\": \"xx市公安局公安交通管理局\" //印章文字\n" +
273273
"}";
274-
when(wxService.get(anyString(), anyString())).thenReturn(returnJson);
274+
when(wxService.post(anyString(), anyString())).thenReturn(returnJson);
275275
final WxMpOcrServiceImpl wxMpOcrService = new WxMpOcrServiceImpl(wxService);
276276

277277
final WxOcrDrivingLicenseResult result = wxMpOcrService.drivingLicense("abc");
@@ -321,7 +321,7 @@ public void testBizLicense() throws Exception {
321321
" \"h\": 728\n" +
322322
" }\n" +
323323
"}";
324-
when(wxService.get(anyString(), anyString())).thenReturn(returnJson);
324+
when(wxService.post(anyString(), anyString())).thenReturn(returnJson);
325325
final WxMpOcrServiceImpl wxMpOcrService = new WxMpOcrServiceImpl(wxService);
326326

327327
final WxOcrBizLicenseResult result = wxMpOcrService.bizLicense("abc");
@@ -383,7 +383,7 @@ public void testComm() throws Exception {
383383
" \"h\": 720\n" +
384384
" }\n" +
385385
"}";
386-
when(wxService.get(anyString(), anyString())).thenReturn(returnJson);
386+
when(wxService.post(anyString(), anyString())).thenReturn(returnJson);
387387
final WxMpOcrServiceImpl wxMpOcrService = new WxMpOcrServiceImpl(wxService);
388388

389389
final WxOcrCommResult result = wxMpOcrService.comm("abc");

0 commit comments

Comments
 (0)