Skip to content

Scan Code

scanCode

TIP

The API usage is as follows: wx.scanCode(Object object)
This API is supported by mini programs, but not by mini games.

  • Functional description: Call up the client code scanning interface to scan

  • Parameters and descriptions: Object object。

    PropertiesTypeLegal values Default valueRequiredDescription
    onlyFromCameraboolean-falseNoWhether the code can only be scanned from the camera, and pictures cannot be selected from the album
    scanTypeArray.<string>1. barCode:One-dimensional code
    2. qrCode:Two-dimensional code
    3. datamatrix:Data Matrix code
    4.pdf417:PDF417 barcode
    ['barCode', 'qrCode']NoScanning type
    successFunction--NoCallback function for successful interface call
    failFunction--NoCallback function for failed interface call
    completeFunction--NoCallback function for interface call completion (executed regardless of success or failure)
  • object.success callback function parameters: Object object。

    PropertiesTypeLegal values Description
    resultstring-Content of the scanned code
    scanTypestring1.QR_CODE:Two-dimensional code
    2. AZTEC:One-dimensional code
    3. CODABAR:One-dimensional code
    4.CODE_39:One-dimensional code
    5. CODE_93:One-dimensional code
    6. CODE_128:One-dimensional code
    7. DATA_MATRIX:Two-dimensional code
    8.EAN_8:One-dimensional code
    9.EAN_13:One-dimensional code
    10. ITF:One-dimensional code
    11. datamatrix:One-dimensional code
    12.PDF_417:Two-dimensional code
    13. RSS_14:One-dimensional code
    14. RSS_EXPANDED:One-dimensional code
    15. UPC_A:One-dimensional code
    16.UPC_E:One-dimensional code
    17. UPC_EAN_EXTENSION:One-dimensional code
    18. WX_CODE:Two-dimensional code
    19.CODE_25:One-dimensional code
    Type of the scanned code
    charSetstring-Character set of the scanned code
    pathstring-When the scanned code is the current mini program QR code, this field will be returned, and the content is the path carried by the QR code
    rawDatastring-Original data, base64 encoding
  • Sample code:

js
// Allow scanning from both the camera and album
wx.scanCode({
  success(res) {
    console.log(res);
  },
});

// Allow scanning from the camera only
wx.scanCode({
  onlyFromCamera: true,
  success(res) {
    console.log(res);
  },
});