# QR Code / Barcode Identification
Interface should be called on the server side, not in the front end (Weixin Mini Program, web pages, APP, etc.) directly called, specific reference interface call guide
Interface English name: img Qrcode
Identify 2D codes, barcodes, DataMatrix and PDF417 in images
# 1. How to call
# HTTPS calls
POST https://api.weixin.qq.com/cv/img/qrcode?access_token=ACCESS_TOKEN&img_url=IMG_URL
# Cloud Calls
Call method: img.scanQRCode
The input and exit parameters are the same as the HTTPS call, which can be called in the cloud call documentation
# Third party invocation
This interface supports Third Party Platform generation business call.
The permission set to which this interface belongs is id: 117
When a service provider is authorized by one of the permissions set, it can call on behalf of the merchant by using authorizer_access_token , which can be viewed in the third-party call documentation.
# 2. Request parameters
# Query parametersQuery String parameters
Parameter Name | type | Required to fill in | Example | Introductions |
---|---|---|---|---|
access_token | string | yes | ACCESS_TOKEN | Interface invocation credentials, using access_token , authorizer_access_token |
img_url | string | no | https://example.com/img.jpg | Image URL Address |
# Request BodyRequest Payload
Parameter Name | type | Required to fill in | Introductions |
---|---|---|---|
img | formdata | no | Image file, limit less than 2 M |
# 3. Return Parameters
# Response Payload
Parameter Name | type | Introductions |
---|---|---|
errcode | number | Error code |
errmsg | string | Error message |
code_results | objarray | Results of processing |
img_size | object | Image size |
# Res.code_results(Array)Object Payload
Results of processing
Parameter Name | type | Introductions |
---|---|---|
type_name | string | Type of code |
data | string | Information about the code |
pos | object | The coordinates of the code |
# Res.img_sizeObject Payload
Image size
Parameter Name | type | Introductions |
---|---|---|
w | number | width |
h | number | height |
# Res.code_results(Array).posObject Payload
The coordinates of the code
Parameter Name | type | Introductions |
---|---|---|
left_top | object | Position in the upper left corner |
right_top | object | Position in the top right |
right_bottom | object | Position in the lower right |
left_bottom | object | Position in the lower left corner |
# Res.code_results(Array).pos.left_topObject Payload
Position in the upper left corner
Parameter Name | type | Introductions |
---|---|---|
x | number | X-coordinate |
y | number | Y-coordinate |
# Res.code_results(Array).pos.right_topObject Payload
Position in the top right
Parameter Name | type | Introductions |
---|---|---|
x | number | X-coordinate |
y | number | Y-coordinate |
# Res.code_results(Array).pos.right_bottomObject Payload
Position in the lower right
Parameter Name | type | Introductions |
---|---|---|
x | number | X-coordinate |
y | number | Y-coordinate |
# Res.code_results(Array).pos.left_bottomObject Payload
Position in the lower left corner
Parameter Name | type | Introductions |
---|---|---|
x | number | X-coordinate |
y | number | Y-coordinate |
# 4. Note
- Image support using img parameter real-time upload, also support using img_url parameter transfer image address, by WeChat background download image recognition
- File must be less than 2 MB
- Supports identification of barcodes, 2D codes, DataMatrix and PDF417.
- Two-dimensional codes, DataMatrix return location coordinates, barcodes and PDF417 do not.
# 5. Code examples
# 5.1 File Link Request
Example Requests
curl 'https://api.weixin.qq.com/cv/img/qrcode?img_url=ENCODE_URL&access_token=ACCESS_TOCKEN'
Return an example
{
"errcode": 0,
"errmsg": "ok",
"code_results": [
{
"type_name": "QR_CODE",
"data": "https://www.qq.com",
"pos": {
"left_top": {
"x": 585,
"y": 378
},
"right_top": {
"x": 828,
"y": 378
},
"right_bottom": {
"x": 828,
"y": 618
},
"left_bottom": {
"x": 585,
"y": 618
}
}
}
],
"img_size": {
"w": 1000,
"h": 900
}
}
# 5.2 File upload request
Example Requests
curl -F 'img=@test.jpg' 'https://api.weixin.qq.com/cv/img/qrcode?access_token=ACCESS_TOCKEN'
Return an example
{
"errcode": 0,
"errmsg": "ok",
"code_results": [
{
"type_name": "QR_CODE",
"data": "https://www.qq.com",
"pos": {
"left_top": {
"x": 585,
"y": 378
},
"right_top": {
"x": 828,
"y": 378
},
"right_bottom": {
"x": 828,
"y": 618
},
"left_bottom": {
"x": 585,
"y": 618
}
}
}
],
"img_size": {
"w": 1000,
"h": 900
}
}
# 6. Error code
The following is a list of error codes for this interface, other error codes can refer to General error codes
Error code | Error Description | Solutions |
---|---|---|
-1 | system error | A system error |
40001 | invalid credential access_token isinvalid or not latest | AppSecret error while getting access_token, or access_token is invalid.Developers should check that AppSecret is correct, or that they are calling interfaces for the appropriate Official Account |
101000 | invalid image url | Image URL error |
101002 | invalid image data | Image data is not valid |
# 7. Scope of application
Weixin Mini Program | Official Account | Service Account |
---|---|---|
✔ | Certification only | Certification only |
- ✔: The account can call this interface
- Authentication only: means that only authenticated accounts are allowed to be invoked by the enterprise entity, and accounts that are not authenticated or do not support authentication cannot be invoked.
- Other account types that are not expressly stated may not be called on this interface without special instructions;