May 20, 2021 WeChat Mini Program Development Document
This interface should be called on the server side, as detailed in the Service Side API.
This interface supports cloud calls. Developer tool version required . . . 1.02.1904090 (latest stable download)
wx-server-sdk >= 0.4.0
This interface provides small program-based driver's license OCR identification
How to call:
POST https://api.weixin.qq.com/cv/ocr/drivinglicense?img_url=ENCODE_URL&access_token=ACCESS_TOCKEN
Property | Type | The default | Required | Description |
---|---|---|---|---|
access_token | string | Is | The interface calls the credentials | |
img_url | string | Is | To detect the picture url, pass this without passing the img parameter. | |
Img | FormData | Is | Form-data media file identification, there is fileame, filelength, content-type and other information, pass this without passing img_url. |
The returned JSON packet
Property | Type | Description |
---|---|---|
errcode | string | Error code |
errmsg | string | The error message |
id_num | string | License number |
name | string | Name |
sex | string | Gender |
name | string | Name |
address | string | Address |
birth_date | string | Date of birth |
issue_date | string | The date of initial certification |
car_class | string | Quasi-driving type |
valid_from | string | The effective period start date |
valid_to | string | The expiration date of the validity period |
official_seal | string | Seal composition |
Interface Limits Subscription numbers, service numbers, enterprise numbers, and small programs that have been certified during the internal test can be called directly, with a limit of 500 times per day.
Using Tips this interface for the background interface, can be based on its own business hosting situation, with small programs of photography, photo selection, etc. together, you can complete the ID photo collection, upload, identification, information return and other processes, for the need to be based on identity cards, bank cards and other physical cards or certificates, collection of photos or text information and other business scenarios.
Image Description File size limit: less than 2m
The picture supports the use of the IMG parameter real-time upload, but also supports the use of the IMG_URL parameter to transfer the image address, and download the image by WeChat background.Type has two types
Photographing picture
Example 1:
curl http://api.weixin.qq.com/cv/ocr/drivinglicense?img_url=ENCODE_URL&access_token=ACCESS_TOCKEN
Example 2:
curl -F ‘[email protected]’“http://api.weixin.qq.com/cv/ocr/drivinglicense?access_token=ACCESS_TOCKEN”
{
"errcode": 0,
"errmsg": "ok",
"id_num": "660601xxxxxxxx1234",
"name": "张三",
"sex": "男",
"nationality": "中国",
"address": "广东省东莞市xxxxx号",
"birth_date": "1990-12-21",
"issue_date": "2012-12-21",
"car_class": "C1",
"valid_from": "2018-07-06",
"valid_to": "2020-07-01",
"official_seal": "xx市公安局公安交通管理局"
}
Cloud call is the ability provided by the small program Cloud Development to call WeChat open interfaces in cloud functions and need to be used in cloud functions via wx-server-sdk.
openapi.ocr.driverLicense
Permissions for the ocr.driverLicense API need to be configured in config.json, details
Property | Type | The default | Required | Description |
---|---|---|---|---|
imgUrl | string | Is | To detect the picture url, pass this without passing the img parameter. | |
Img | FormData | Is | Form-data media file identification, there is fileame, filelength, content-type and other information, pass this without passing img_url. |
The structure of img
Property | Type | The default | Required | Description |
---|---|---|---|---|
contentType | string | Is | Data type, incoming MIME Type | |
value | Buffer | Is | File Buffer |
The returned JSON packet
Property | Type | Description |
---|---|---|
errCode | string | Error code |
errMsg | string | The error message |
idNum | string | License number |
name | string | Name |
sex | string | Gender |
name | string | Name |
address | string | Address |
birthDate | string | Date of birth |
issueDate | string | The date of initial certification |
carClass | string | Quasi-driving type |
validFrom | string | The effective period start date |
validTo | string | The expiration date of the validity period |
officialSeal | string | Seal composition |
The exception thrown
Property | Type | Description |
---|---|---|
errCode | string | Error code |
errMsg | string | The error message |
The legal value of errCode
Value | Description | The lowest version |
---|
Interface Limits Subscription numbers, service numbers, enterprise numbers, and small programs that have been certified during the internal test can be called directly, with a limit of 500 times per day.
Using Tips this interface for the background interface, can be based on its own business hosting situation, with small programs of photography, photo selection, etc. together, you can complete the ID photo collection, upload, identification, information return and other processes, for the need to be based on identity cards, bank cards and other physical cards or certificates, collection of photos or text information and other business scenarios.
Image caption File size limit: less than 2M
Images support the use of img parameters for real-time upload, but also img_url parameters to transmit picture addresses, by WeChat background download pictures to identify. There are two types of type
Take a picture sample
const cloud = require('wx-server-sdk')
cloud.init()
exports.main = async (event, context) => {
try {
const result = await cloud.openapi.ocr.driverLicense({
type: 'photo',
imgUrl: 'ENCODE_URL'
})
return result
} catch (err) {
return err
}
}
Or
// cloud = require('wx-server-sdk')
// ...
// 方法返回 Promise
cloud.openapi.ocr.driverLicense({
type: 'photo',
img: {
contentType: 'image/png',
value: Buffer
}
})
{
"errcode": 0,
"errmsg": "ok",
"id_num": "660601xxxxxxxx1234",
"name": "张三",
"sex": "男",
"nationality": "中国",
"address": "广东省东莞市xxxxx号",
"birth_date": "1990-12-21",
"issue_date": "2012-12-21",
"car_class": "C1",
"valid_from": "2018-07-06",
"valid_to": "2020-07-01",
"official_seal": "xx市公安局公安交通管理局"
}