Skip to content

feat(weixin-java-mp): 实现 OCR 菜单识别接口(cv/ocr/menu)#4028

Open
Copilot wants to merge 2 commits into
developfrom
copilot/add-ocr-identification-interfaces
Open

feat(weixin-java-mp): 实现 OCR 菜单识别接口(cv/ocr/menu)#4028
Copilot wants to merge 2 commits into
developfrom
copilot/add-ocr-identification-interfaces

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 31, 2026

WxOcrService 缺少第 7 种 OCR 类型——菜单识别(cv/ocr/menu),导致开发者无法通过 SDK 调用该能力。

变更内容

weixin-java-common

  • 新增 WxOcrMenuResult Bean(含 items 文本列表和 imgSize 字段,结构与 WxOcrCommResult 一致)
  • WxOcrService 接口新增 menu(String imgUrl) / menu(File imgFile) 两个方法声明

weixin-java-mp

  • WxMpApiUrl.Ocr 枚举新增 MENUFILE_MENU URL 常量(/cv/ocr/menu
  • WxMpOcrServiceImpl 实现上述两个方法

weixin-java-miniapp

  • WxMaApiUrlConstants.Ocr 新增 MENU / FILE_MENU 常量
  • WxMaOcrServiceImpl 同步实现 menu 方法

测试

  • WxMpOcrServiceImplTest 新增集成测试 testMenu/testMenu2 及 Mock 单元测试

使用示例

// 通过 URL 识别菜单
WxOcrMenuResult result = wxMpService.getOcrService().menu("https://example.com/menu.jpg");

// 通过本地文件识别菜单
WxOcrMenuResult result = wxMpService.getOcrService().menu(new File("/path/to/menu.jpg"));

result.getItems().forEach(item -> System.out.println(item.getText()));

- 新增 WxOcrMenuResult Bean(weixin-java-common)
- 在 WxOcrService 接口中添加 menu(String) 和 menu(File) 方法
- 在 WxMpApiUrl.Ocr 枚举中添加 MENU 和 FILE_MENU URL
- 在 WxMpOcrServiceImpl 中实现 menu 方法
- 在 WxMaApiUrlConstants.Ocr 中添加菜单识别URL常量
- 在 WxMaOcrServiceImpl 中实现 menu 方法
- 在 WxMpOcrServiceImplTest 中添加 testMenu 和 testMenu2 测试用例
Copilot AI changed the title [WIP] Add OCR recognition interfaces for seven document types feat(weixin-java-mp): 实现 OCR 菜单识别接口(cv/ocr/menu) May 31, 2026
Copilot AI requested a review from binarywang May 31, 2026 14:24
@binarywang binarywang marked this pull request as ready for review May 31, 2026 14:30
Copilot AI review requested due to automatic review settings May 31, 2026 14:30
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

本 PR 为 WxJava 的 OCR 服务补充微信菜单识别接口 /cv/ocr/menu,使公众号与小程序模块都能通过统一的 WxOcrService 调用菜单 OCR 能力。

Changes:

  • 新增 WxOcrMenuResult 结果 Bean,并在公共 OCR 接口中声明 menu(String) / menu(File)
  • 在公众号与小程序模块中新增菜单 OCR URL 常量及实现。
  • 为公众号 OCR 服务补充菜单识别相关测试。

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/ocr/WxOcrMenuResult.java 新增菜单 OCR 响应模型。
weixin-java-common/src/main/java/me/chanjar/weixin/common/service/WxOcrService.java 扩展公共 OCR 服务接口,加入菜单识别方法。
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/enums/WxMpApiUrl.java 为公众号模块新增菜单 OCR API 地址。
weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpOcrServiceImpl.java 实现公众号菜单 OCR URL 与文件调用。
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpOcrServiceImplTest.java 增加公众号菜单 OCR 测试。
weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/constant/WxMaApiUrlConstants.java 为小程序模块新增菜单 OCR API 地址。
weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaOcrServiceImpl.java 实现小程序菜单 OCR URL 与文件调用。

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c3e5f0f5fc

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

/**
* 菜单OCR识别
*/
MENU(API_DEFAULT_HOST_URL, "/cv/ocr/menu?img_url=%s"),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Use a supported OCR endpoint

The server-side WeChat OCR API set exposes the license-plate recognizer as /cv/ocr/platenum; menu is a mini-program OCR plugin certificateType, not a cv/ocr/menu REST endpoint. With this URL, both new menu(String) and menu(File) calls in MP (and the mirrored MiniApp constants) will post to an unsupported path, so users trying this added SDK method will get API errors rather than menu OCR results.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[weixin-java-mp] OCR识别接口完全缺失(7种证件类型均无实现)

3 participants