This API is called using wx.scanCode(Object object).
Property | Type | Valid values and description | Default value | Required | Description |
onlyFromCamera | boolean | - | false | False | Whether to only allow scanning from the camera, not from the photo album. |
scanType | Array.<string> | barCode: Barcode qrCode: QR code datamatrix: Data Matrix code pdf417: PDF417 barcode | ['barCode', 'qrCode'] | False | Types of codes to scan. |
success | function | - | - | False | Callback function for successful API calls. |
fail | function | - | - | False | Callback function for failed API calls. |
complete | function | - | - | False | Callback function executed after API call ends (regardless of success or failure). |
Property | Type | Valid values and description | Description |
result | string | - | Content of the scanned code. |
scanType | string | QR_CODE: QR code AZTEC: Barcode CODABAR: Barcode CODE_39: Barcode CODE_93: Barcode CODE_128: Barcode DATA_MATRIX: QR code EAN_8: Barcode EAN_13: Barcode ITF: Barcode MAXICODE: Barcode PDF_417: QR code RSS_14: Barcode RSS_EXPANDED: Barcode UPC_A: Barcode UPC_E: Barcode UPC_EAN_EXTENSION: Barcode WX_CODE: QR code CODE_25: Barcode | Type of the scanned code. |
charSet | string | - | Character set of the scanned code. |
path | string | - | If the scanned code is a QR code for the current mini program, this field will be returned with the path carried by the QR code |
rawData | string | - | Base64-encoded raw data. |
// Allow scanning from both camera and photo albumwx.scanCode({success (res) {console.log(res)}})// Only allow scanning from the camerawx.scanCode({onlyFromCamera: true,success (res) {console.log(res)}})