OCR /vehicleLicense

# ocr.vehicleLicense

> 本接口应在服务器端调用,详细说明参见[服务端API](https://developers.weixin.qq.com/miniprogram/dev/framework/server-ability/backend-api.html)。

> 本接口支持[云调用](https://developers.weixin.qq.com/miniprogram/dev/wxcloud/guide/openapi/openapi.html)。需开发者工具版本 >= `1.02.1904090`(最新[稳定版下载](https://developers.weixin.qq.com/miniprogram/dev/devtools/stable.html)),`wx-server-sdk` >= `0.4.0`

本接口提供基于小程序的行驶证 OCR 识别

调用方式:

- [HTTPS 调用](https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/ocr/ocr.vehicleLicense.html#method-http)
- [云调用](https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/ocr/ocr.vehicleLicense.html#method-cloud)



## HTTPS 调用

### 请求地址

```text
POST https://api.weixin.qq.com/cv/ocr/driving?type=MODE&img_url=ENCODE_URL&access_token=ACCESS_TOCKEN
```

### 请求参数

| 属性                                  | 类型     | 默认值 | 必填 | 说明                                                         |
| :------------------------------------ | :------- | :----- | :--- | :----------------------------------------------------------- |
| access_token / cloudbase_access_token | string   |        | 是   | [接口调用凭证](https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/access-token/auth.getAccessToken.html) |
| type                                  | string   |        | 是   | 图片识别模式,photo(拍照模式)或 scan(扫描模式)           |
| img_url                               | string   |        | 是   | 要检测的图片 url,传这个则不用传 img 参数。                  |
| img                                   | FormData |        | 是   | form-data 中媒体文件标识,有filename、filelength、content-type等信息,传这个则不用传 img_url。 |

### 返回值

### Object

返回的 JSON 数据包

| 属性                         | 类型   | 说明       |
| :--------------------------- | :----- | :--------- |
| errcode                      | string | 错误码     |
| errmsg                       | string | 错误信息   |
| vehicle_type                 | string | 车辆类型   |
| owner                        | string | 所有人     |
| addr                         | string | 住址       |
| use_character                | string | 使用性质   |
| model                        | string | 品牌型号   |
| vin                          | string | 车辆识别代 |
| engine_num                   | string | 发动机号码 |
| register_date                | string | 注册日期   |
| issue_date                   | string | 发证日期   |
| plate_num_b                  | string | 车牌号码   |
| record                       | string | 号牌       |
| passengers_num               | string | 核定载人数 |
| total_quality                | string | 总质量     |
| totalprepare_quality_quality | string | 整备质量   |

### 使用说明

**接口限制** 内测期间已认证的订阅号、服务号、企业号、小程序可直接调用,次数限制为100次/天。

**使用 Tips** 此接口为后台接口,可基于自有业务承载情况,搭配小程序的拍照、相册选照等一起使用,即可完成身份证照片的采集、上传、识别、信息返回等流程,用于需要基于身份证、银行卡等实体卡或证,采集照片或文字信息等的业务场景。

**图片说明** 文件大小限制:小于2M

图片支持使用 img 参数实时上传,也支持使用img_url参数传送图片地址,由微信后台下载图片进行识别。type 有两种类型

**拍摄图片样例**

![img](https://res.wx.qq.com/op_res/T051P5uWvh9gSJ9j78tWib53WiNi2pHSSZhoO8wnY3Av-djpsA4kA9whbtt6_Tb6)

### 请求数据示例

示例1:

```text
curl https://api.weixin.qq.com/cv/ocr/driving?type=photo&img_url= ENCODE_URL&access_token=ACCESS_TOCKEN
```

示例2:

```text
curl -F ‘img=@test.jpg’“https://api.weixin.qq.com/cv/ocr/driving?type=photo&access_token=ACCESS_TOCKEN”
```

### 返回数据示例

```text
{
"vhicle_type": "小型普通客⻋",
"owner": "东莞市 xxxxx 机械厂",
"addr": "广东省东莞市 xxxxx 号",
"use_character": "非营运",
"model": "江淮牌HFCxxxxxxx",
"vin": "LJ166xxxxxxxx51",
"engine_num": "J3xxxxx3",
"register_date": "2018-07-06",
"issue_date": "2018-07-01",
"plate_num_b": "粤xxxxx",
"record": "441xxxxxx3",
"passengers_num": "7人",
"total_quality": "2700kg",
"prepare_quality": "1995kg"
}
```



## 云调用

> [云调用](https://developers.weixin.qq.com/miniprogram/dev/wxcloud/guide/openapi/openapi.html)是微信云开发提供的在云函数中调用微信开放接口的能力,需要在云函数中通过 `wx-server-sdk` 使用。

### 接口方法

```js
openapi.ocr.vehicleLicense
```

> 需在 `config.json` 中配置 `ocr.vehicleLicense` API 的权限,[详情](https://developers.weixin.qq.com/miniprogram/dev/wxcloud/guide/openapi/openapi.html#usage-3)

### 请求参数

| 属性   | 类型     | 默认值 | 必填 | 说明                                                         |
| :----- | :------- | :----- | :--- | :----------------------------------------------------------- |
| type   | string   |        | 是   | 图片识别模式,photo(拍照模式)或 scan(扫描模式)           |
| imgUrl | string   |        | 是   | 要检测的图片 url,传这个则不用传 img 参数。                  |
| img    | FormData |        | 是   | form-data 中媒体文件标识,有filename、filelength、content-type等信息,传这个则不用传 img_url。 |

**img 的结构**

| 属性        | 类型   | 默认值 | 必填 | 说明                     |
| :---------- | :----- | :----- | :--- | :----------------------- |
| contentType | string |        | 是   | 数据类型,传入 MIME Type |
| value       | Buffer |        | 是   | 文件 Buffer              |

### 返回值

### Object

返回的 JSON 数据包

| 属性                       | 类型   | 说明       |
| :------------------------- | :----- | :--------- |
| errCode                    | string | 错误码     |
| errMsg                     | string | 错误信息   |
| vehicleType                | string | 车辆类型   |
| owner                      | string | 所有人     |
| addr                       | string | 住址       |
| useCharacter               | string | 使用性质   |
| model                      | string | 品牌型号   |
| vin                        | string | 车辆识别代 |
| engineNum                  | string | 发动机号码 |
| registerDate               | string | 注册日期   |
| issueDate                  | string | 发证日期   |
| plateNumB                  | string | 车牌号码   |
| record                     | string | 号牌       |
| passengersNum              | string | 核定载人数 |
| totalQuality               | string | 总质量     |
| totalprepareQualityQuality | string | 整备质量   |

### 异常

### Object

抛出的异常

| 属性    | 类型   | 说明     |
| :------ | :----- | :------- |
| errCode | string | 错误码   |
| errMsg  | string | 错误信息 |

**errCode 的合法值**

| 值   | 说明 | 最低版本 |
| :--- | :--- | :------- |
|      |      |          |

### 使用说明

**接口限制** 内测期间已认证的订阅号、服务号、企业号、小程序可直接调用,次数限制为100次/天。

**使用 Tips** 此接口为后台接口,可基于自有业务承载情况,搭配小程序的拍照、相册选照等一起使用,即可完成身份证照片的采集、上传、识别、信息返回等流程,用于需要基于身份证、银行卡等实体卡或证,采集照片或文字信息等的业务场景。

**图片说明** 文件大小限制:小于2M

图片支持使用 img 参数实时上传,也支持使用img_url参数传送图片地址,由微信后台下载图片进行识别。type 有两种类型

**拍摄图片样例**

![img](https://res.wx.qq.com/op_res/T051P5uWvh9gSJ9j78tWib53WiNi2pHSSZhoO8wnY3Av-djpsA4kA9whbtt6_Tb6)

### 请求数据示例

```js
const cloud = require('wx-server-sdk')
cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV,
})
exports.main = async (event, context) => {
  try {
    const result = await cloud.openapi.ocr.vehicleLicense({
        "type": 'photo',
        "imgUrl": 'ENCODE_URL'
      })
    return result
  } catch (err) {
    return err
  }
}
```

或

```js
// cloud = require('wx-server-sdk')
// ...
// 方法返回 Promise
cloud.openapi.ocr.vehicleLicense({
  type: 'photo',
  img: {
    contentType: 'image/png',
    value: Buffer
  }
})
```

### 返回数据示例

```text
{
"vhicle_type": "小型普通客⻋",
"owner": "东莞市 xxxxx 机械厂",
"addr": "广东省东莞市 xxxxx 号",
"use_character": "非营运",
"model": "江淮牌HFCxxxxxxx",
"vin": "LJ166xxxxxxxx51",
"engine_num": "J3xxxxx3",
"register_date": "2018-07-06",
"issue_date": "2018-07-01",
"plate_num_b": "粤xxxxx",
"record": "441xxxxxx3",
"passengers_num": "7人",
"total_quality": "2700kg",
"prepare_quality": "1995kg"
}
```