|
11 | 11 | import me.chanjar.weixin.common.bean.ocr.WxOcrDrivingLicenseResult; |
12 | 12 | import me.chanjar.weixin.common.bean.ocr.WxOcrDrivingResult; |
13 | 13 | import me.chanjar.weixin.common.bean.ocr.WxOcrIdCardResult; |
| 14 | +import me.chanjar.weixin.common.bean.ocr.WxOcrMenuResult; |
14 | 15 | import org.testng.annotations.Guice; |
15 | 16 | import org.testng.annotations.Test; |
16 | 17 |
|
@@ -137,6 +138,22 @@ public void testComm2() throws Exception { |
137 | 138 | System.out.println(result); |
138 | 139 | } |
139 | 140 |
|
| 141 | + @Test |
| 142 | + public void testMenu() throws WxErrorException { |
| 143 | + final WxOcrMenuResult result = this.service.getOcrService().menu("https://res.wx.qq.com/op_res/apCy0YbnEdjYsa_cjW6x3FlpCc20uQ-2BYE7aXnFsrB-ALHZNgdKXhzIUcrRnDoL"); |
| 144 | + assertThat(result).isNotNull(); |
| 145 | + System.out.println(result); |
| 146 | + } |
| 147 | + |
| 148 | + @Test |
| 149 | + public void testMenu2() throws Exception { |
| 150 | + InputStream inputStream = ClassLoader.getSystemResourceAsStream("mm.jpeg"); |
| 151 | + File tempFile = FileUtils.createTmpFile(inputStream, UUID.randomUUID().toString(), TestConstants.FILE_JPG); |
| 152 | + final WxOcrMenuResult result = this.service.getOcrService().menu(tempFile); |
| 153 | + assertThat(result).isNotNull(); |
| 154 | + System.out.println(result); |
| 155 | + } |
| 156 | + |
140 | 157 | private InputStream getImageStream(String url) { |
141 | 158 | try { |
142 | 159 | HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); |
@@ -390,5 +407,46 @@ public void testComm() throws Exception { |
390 | 407 | assertThat(result).isNotNull(); |
391 | 408 | System.out.println(result); |
392 | 409 | } |
| 410 | + |
| 411 | + @Test |
| 412 | + public void testMenu() throws Exception { |
| 413 | + String returnJson = "{\n" + |
| 414 | + " \"errcode\": 0, \n" + |
| 415 | + " \"errmsg\": \"ok\", \n" + |
| 416 | + " \"items\": [\n" + |
| 417 | + " {\n" + |
| 418 | + " \"text\": \"红烧肉\", \n" + |
| 419 | + " \"pos\": {\n" + |
| 420 | + " \"left_top\": {\n" + |
| 421 | + " \"x\": 575, \n" + |
| 422 | + " \"y\": 519\n" + |
| 423 | + " }, \n" + |
| 424 | + " \"right_top\": {\n" + |
| 425 | + " \"x\": 744, \n" + |
| 426 | + " \"y\": 519\n" + |
| 427 | + " }, \n" + |
| 428 | + " \"right_bottom\": {\n" + |
| 429 | + " \"x\": 744, \n" + |
| 430 | + " \"y\": 532\n" + |
| 431 | + " }, \n" + |
| 432 | + " \"left_bottom\": {\n" + |
| 433 | + " \"x\": 573, \n" + |
| 434 | + " \"y\": 532\n" + |
| 435 | + " }\n" + |
| 436 | + " }\n" + |
| 437 | + " }\n" + |
| 438 | + " ], \n" + |
| 439 | + " \"img_size\": {\n" + |
| 440 | + " \"w\": 1280, \n" + |
| 441 | + " \"h\": 720\n" + |
| 442 | + " }\n" + |
| 443 | + "}"; |
| 444 | + when(wxService.post(anyString(), anyString())).thenReturn(returnJson); |
| 445 | + final WxMpOcrServiceImpl wxMpOcrService = new WxMpOcrServiceImpl(wxService); |
| 446 | + |
| 447 | + final WxOcrMenuResult result = wxMpOcrService.menu("abc"); |
| 448 | + assertThat(result).isNotNull(); |
| 449 | + System.out.println(result); |
| 450 | + } |
393 | 451 | } |
394 | 452 | } |
0 commit comments