# QR Code / Barcode Identification

Debugging Tools

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 NametypeRequired to fill inExampleIntroductions
access_tokenstringyesACCESS_TOKENInterface invocation credentials, using access_token , authorizer_access_token
img_urlstringnohttps://example.com/img.jpgImage URL Address

# Request BodyRequest Payload

Parameter NametypeRequired to fill inIntroductions
imgformdatanoImage file, limit less than 2 M

# 3. Return Parameters

# Response Payload

Parameter NametypeIntroductions
errcodenumberError code
errmsgstringError message
code_resultsobjarrayResults of processing
img_sizeobjectImage size

# Res.code_results(Array)Object Payload

Results of processing

Parameter NametypeIntroductions
type_namestringType of code
datastringInformation about the code
posobjectThe coordinates of the code

# Res.img_sizeObject Payload

Image size

Parameter NametypeIntroductions
wnumberwidth
hnumberheight

# Res.code_results(Array).posObject Payload

The coordinates of the code

Parameter NametypeIntroductions
left_topobjectPosition in the upper left corner
right_topobjectPosition in the top right
right_bottomobjectPosition in the lower right
left_bottomobjectPosition in the lower left corner

# Res.code_results(Array).pos.left_topObject Payload

Position in the upper left corner

Parameter NametypeIntroductions
xnumberX-coordinate
ynumberY-coordinate

# Res.code_results(Array).pos.right_topObject Payload

Position in the top right

Parameter NametypeIntroductions
xnumberX-coordinate
ynumberY-coordinate

# Res.code_results(Array).pos.right_bottomObject Payload

Position in the lower right

Parameter NametypeIntroductions
xnumberX-coordinate
ynumberY-coordinate

# Res.code_results(Array).pos.left_bottomObject Payload

Position in the lower left corner

Parameter NametypeIntroductions
xnumberX-coordinate
ynumberY-coordinate

# 4. Note

  1. Image support using img parameter real-time upload, also support using img_url parameter transfer image address, by WeChat background download image recognition
  2. File must be less than 2 MB
  3. Supports identification of barcodes, 2D codes, DataMatrix and PDF417.
  4. Two-dimensional codes, DataMatrix return location coordinates, barcodes and PDF417 do not.

# 5. Code examples

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 codeError DescriptionSolutions
-1system errorA system error
40001invalid credential  access_token isinvalid or not latestAppSecret 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
101000invalid image urlImage URL error
101002invalid image dataImage data is not valid

# 7. Scope of application

How this interface can be invoked under different account types:
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;