# 菜单识别

[调试诊断](https://developers.weixin.qq.com/console/devtools/debug?utm_source=api_tools)

> 接口应在服务器端调用，不可在前端（小程序、网页、APP等）直接调用，具体可参考[接口调用指南](/doc/oplatform/developers/dev/guide.md)。

接口英文名：menuOcr

本接口用于识别纸质菜单

## 1. 调用方式

### HTTPS 调用

```bash
POST https://api.weixin.qq.com/cv/ocr/menu?access_token=ACCESS_TOCKEN&img_url=ENCODE_URL
```

### 云调用

- 本接口不支持云调用。

### 第三方调用

- 本接口支持第三方平台代商家调用。

- 该接口所属的权限集 id 为：117

- 服务商获得其中之一权限集授权后，可通过使用 [authorizer_access_token](/doc/oplatform/developers/dev/AuthorizerAccessToken.md) 代商家进行调用，具体可查看 [第三方调用](/doc/oplatform/Third-party_Platforms/2.0/Before_Develop/call_interface.md) 说明文档。

## 2. 请求参数

### 查询参数 `Query String Parameters`

```json
[
  {
    "参数名": "access_token",
    "类型": "string",
    "必填": "是",
    "示例": "ACCESS_TOCKEN",
    "说明": "接口调用凭证，可使用 [access_token](/doc/subscription/api/base/api_getaccesstoken)、[authorizer_access_token](/doc/oplatform/openApi/ticket-token/api_getauthorizeraccesstoken.md)"
  },
  {
    "参数名": "img_url",
    "类型": "string",
    "必填": "否",
    "示例": "ENCODE_URL",
    "说明": "要检测的图片 url，传这个则不用传 img 参数。"
  }
]
```

### 请求体 `Request Payload`

```json
[
  {
    "参数名": "img",
    "类型": "formdata",
    "必填": "否",
    "说明": "图片文件，文件大小限制：小于2M"
  }
]
```

## 3. 返回参数

### 返回体 `Response Payload`

```json
[
  {
    "参数名": "errcode",
    "类型": "number",
    "说明": "错误码"
  },
  {
    "参数名": "errmsg",
    "类型": "string",
    "说明": "错误信息"
  },
  {
    "参数名": "content",
    "类型": "object",
    "说明": "识别的信息"
  }
]
```

### Res.content `Object Payload`

识别的信息

```json
[
  {
    "参数名": "menu_items",
    "类型": "objarray",
    "说明": "菜单内容列表"
  }
]
```

">

### Res.content.menu_items(Array) `Object Payload`

菜单内容列表

```json
[
  {
    "参数名": "name",
    "类型": "string",
    "说明": "菜单名"
  },
  {
    "参数名": "price",
    "类型": "number",
    "说明": "价格"
  }
]
```

## 4. 注意事项

该接口尚未接入服务平台，暂时不支持付费购买。

## 5. 代码示例

### 5.1 上传文件请求

请求示例

``` bash
curl -F 'img=@test.jpg' "https://api.weixin.qq.com/cv/ocr/menu?access_token=ACCESS_TOCKEN" 
```

返回示例

``` json
{
    "errcode": 0, 
    "errmsg": "ok", 
    "content": "{\"menu_items\": [{\"name\": \"酱鸭\", \"price\": 48.0}, {\"name\": \"龙虾\", \"price\": 80.0}, {\"name\": \"芝麻鸭块\", \"price\": 48.0}, {\"name\": \"皮皮虾\", \"price\": 70.0}, {\"name\": \"特色辣鸭脚\", \"price\": 46.0}, {\"name\": \"花甲\", \"price\": 30.0}, {\"name\": \"小鸭翅\", \"price\": 46.0}, {\"name\": \"鸭肠\", \"price\": 40.0}, {\"name\": \"微辣大鸭脚\", \"price\": 43.0}, {\"name\": \"八宝\", \"price\": 10.0}, {\"name\": \"大鸭翅\", \"price\": 43.0}, {\"name\": \"千叶豆腐\", \"price\": 10.0}, {\"name\": \"鸭脖\", \"price\": 35.0}, {\"name\": \"毛豆\", \"price\": 15.0}, {\"name\": \"鸭锁骨\", \"price\": 35.0}, {\"name\": \"螺丝\", \"price\": 15.0}, {\"name\": \"特色蟹脚\", \"price\": 55.0}, {\"name\": \"藕片\", \"price\": 15.0}, {\"name\": \"鱿鱼须\", \"price\": 70.0}, {\"name\": \"腐竹\", \"price\": 15.0}, {\"name\": \"鸭下巴\", \"price\": 70.0}, {\"name\": \"鸭头\", \"price\": 5.0}, {\"name\": \"无骨鸭脚\", \"price\": 70.0}, {\"name\": \"辣椒酱\", \"price\": 10.0}, {\"name\": \"鸭舌\", \"price\": 138.0}, {\"name\": \"花生米\", \"price\": 5.0}, {\"name\": \"鸭胗\", \"price\": 55.0}, {\"name\": \"萝卜干\", \"price\": 12.0}, {\"name\": \"牛肉串\", \"price\": 65.0}, {\"name\": \"盐菜\", \"price\": 12.0}]}"
}
```

### 5.2 上传链接请求

请求示例

``` bash
curl "https://api.weixin.qq.com/cv/ocr/menu?img_url=ENCODE_URL&access_token=ACCESS_TOCKEN"
```

返回示例

``` json
{
    "errcode": 0, 
    "errmsg": "ok", 
    "content": "{\"menu_items\": [{\"name\": \"酱鸭\", \"price\": 48.0}, {\"name\": \"龙虾\", \"price\": 80.0}, {\"name\": \"芝麻鸭块\", \"price\": 48.0}, {\"name\": \"皮皮虾\", \"price\": 70.0}, {\"name\": \"特色辣鸭脚\", \"price\": 46.0}, {\"name\": \"花甲\", \"price\": 30.0}, {\"name\": \"小鸭翅\", \"price\": 46.0}, {\"name\": \"鸭肠\", \"price\": 40.0}, {\"name\": \"微辣大鸭脚\", \"price\": 43.0}, {\"name\": \"八宝\", \"price\": 10.0}, {\"name\": \"大鸭翅\", \"price\": 43.0}, {\"name\": \"千叶豆腐\", \"price\": 10.0}, {\"name\": \"鸭脖\", \"price\": 35.0}, {\"name\": \"毛豆\", \"price\": 15.0}, {\"name\": \"鸭锁骨\", \"price\": 35.0}, {\"name\": \"螺丝\", \"price\": 15.0}, {\"name\": \"特色蟹脚\", \"price\": 55.0}, {\"name\": \"藕片\", \"price\": 15.0}, {\"name\": \"鱿鱼须\", \"price\": 70.0}, {\"name\": \"腐竹\", \"price\": 15.0}, {\"name\": \"鸭下巴\", \"price\": 70.0}, {\"name\": \"鸭头\", \"price\": 5.0}, {\"name\": \"无骨鸭脚\", \"price\": 70.0}, {\"name\": \"辣椒酱\", \"price\": 10.0}, {\"name\": \"鸭舌\", \"price\": 138.0}, {\"name\": \"花生米\", \"price\": 5.0}, {\"name\": \"鸭胗\", \"price\": 55.0}, {\"name\": \"萝卜干\", \"price\": 12.0}, {\"name\": \"牛肉串\", \"price\": 65.0}, {\"name\": \"盐菜\", \"price\": 12.0}]}"
}
````

## 6. 错误码

以下是本接口的错误码列表，其他错误码可参考 [通用错误码](/doc/oplatform/developers/errCode/README.md)；调用接口遇到报错，可使用官方提供的 [API 诊断工具](https://developers.weixin.qq.com/console/devtools/debug?utm_source=api_errcode) 辅助定位和分析问题。

```json
[
  {
    "错误码": "-1",
    "错误描述": "system error",
    "解决方案": "系统繁忙，此时请开发者稍候再试"
  },
  {
    "错误码": "101000",
    "错误描述": "invalid image url",
    "解决方案": ""
  },
  {
    "错误码": "101001",
    "错误描述": "certificate not found",
    "解决方案": ""
  },
  {
    "错误码": "101002",
    "错误描述": "decode image failed",
    "解决方案": "图片大小超过限制，resp_type = 0: 2MB，resp_type = 1: 10MB"
  }
]
```

## 7. 适用范围

本接口在不同账号类型下的可调用情况：

```json
[
  {
    "小程序": "✔",
    "公众号": "仅认证",
    "服务号": "仅认证"
  }
]
```

- ✔：该账号可调用此接口。
- 仅认证：表示仅允许企业主体已认证账号调用，未认证或不支持认证的账号无法调用。
- 其他未明确声明的账号类型，如无特殊说明，均不可调用此接口。
