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 universal print OCR identification based on small programs
How to call:
POST https://api.weixin.qq.com/cv/ocr/comm?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 |
items | string | Identify the results |
img_size | string | The size of the picture |
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.Universal print body OCR is suitable for screen screenshots, print photos and other scenes
Example 1
curl http://api.weixin.qq.com/cv/ocr/comm?img_url=ENCODE_URL&access_token=ACCESS_TOCKEN
Example 2:
curl -F ‘[email protected]’“http://api.weixin.qq.com/cv/ocr/comm?access_token=ACCESS_TOCKEN”
{
"errcode": 0,
"errmsg": "ok",
"items": [ //识别结果
{
"text": "腾讯",
"pos": {
"left_top": {
"x": 575,
"y": 519
},
"right_top": {
"x": 744,
"y": 519
},
"right_bottom": {
"x": 744,
"y": 532
},
"left_bottom": {
"x": 573,
"y": 532
}
}
},
{
"text": "微信团队",
"pos": {
"left_top": {
"x": 670,
"y": 516
},
"right_top": {
"x": 762,
"y": 517
},
"right_bottom": {
"x": 762,
"y": 532
},
"left_bottom": {
"x": 670,
"y": 531
}
}
}
],
"img_size": { //图片大小
"w": 1280,
"h": 720
}
}
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.printedText
Permissions for the ocr.printedText 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 |
items | string | Identify the results |
imgSize | string | The size of the picture |
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. Universal print OCR is suitable for screens, printed photos, and other scenes
const cloud = require('wx-server-sdk')
cloud.init()
exports.main = async (event, context) => {
try {
const result = await cloud.openapi.ocr.printedText({
type: 'photo',
imgUrl: 'ENCODE_URL'
})
return result
} catch (err) {
return err
}
}
Or
// cloud = require('wx-server-sdk')
// ...
// 方法返回 Promise
cloud.openapi.ocr.printedText({
type: 'photo',
img: {
contentType: 'image/png',
value: Buffer
}
})
{
"errcode": 0,
"errmsg": "ok",
"items": [ //识别结果
{
"text": "腾讯",
"pos": {
"left_top": {
"x": 575,
"y": 519
},
"right_top": {
"x": 744,
"y": 519
},
"right_bottom": {
"x": 744,
"y": 532
},
"left_bottom": {
"x": 573,
"y": 532
}
}
},
{
"text": "微信团队",
"pos": {
"left_top": {
"x": 670,
"y": 516
},
"right_top": {
"x": 762,
"y": 517
},
"right_bottom": {
"x": 762,
"y": 532
},
"left_bottom": {
"x": 670,
"y": 531
}
}
}
],
"img_size": { //图片大小
"w": 1280,
"h": 720
}
}