# wx.scanCode(Object object)
Start from base library version 1.0.0. Please remaining backward compatible.
with Promise style call: Supported
Mini Program plugin: Support, need to Mini Program base library version no less than 1.9.6
Set up the client scan interface to scan the code
# parameter
# Object object
| attribute | 初始值 | Default values | 初始值 | 初始值 | 初始值 | 
|---|---|---|---|---|---|
| onlyFromCamera | boolean | false | no | Whether you can only scan the code from the camera, not allow you to select pictures from the album | 1.2.0 | 
| scanType | Array.<string> | ['barCode', 'qrCode'] | no | Scan code type | 1.7.0 | 
| success | function | no | Interface calls the successful callback function | ||
| fail | function | no | Interface calls failed callback functions | ||
| complete | function | no | Callback function at the end of an interface call (both successful and unsuccessful calls are executed) | 
object.scanType Legal value
| value | Introductions | Minimum version | 
|---|---|---|
| barCode | One-dimensional code | |
| qrCode | two-dimensional barcode | |
| datamatrix | Data Matrix code | |
| pdf417 | PDF417 barcode | 
# object.success callback
# parameter
# Object res
| attribute | type | Introductions | 
|---|---|---|
| result | string | The contents of the scanned code | 
| scanType | string | Type of code scanned | 
| charSet | string | Character set of scanned code | 
| path | string | When the scan code is the current Mini Program two-dimensional code, will return this field, the content of two-dimensional code carried path | 
| rawData | string | Raw data, base64 encoding | 
res.scanType Legal value
| value | Introductions | Minimum version | 
|---|---|---|
| QR_CODE | two-dimensional barcode | |
| AZTEC | One-dimensional code | |
| CODABAR | One-dimensional code | |
| CODE_39 | One-dimensional code | |
| CODE_93 | One-dimensional code | |
| CODE_128 | One-dimensional code | |
| DATA_MATRIX | two-dimensional barcode | |
| EAN_8 | One-dimensional code | |
| EAN_13 | One-dimensional code | |
| ITF | One-dimensional code | |
| MAXICODE | One-dimensional code | |
| PDF_417 | two-dimensional barcode | |
| RSS_14 | One-dimensional code | |
| RSS_EXPANDED | One-dimensional code | |
| UPC_A | One-dimensional code | |
| UPC_And | One-dimensional code | |
| UPC_EAN_EXTENSION | One-dimensional code | |
| WX_CODE | two-dimensional barcode | |
| CODE_25 | One-dimensional code | 
# sample code
// Allow scanning from camera and photo album
wx.scanCode({
  success (res) {
    console.log(res)
  }
})
// Scan code only from camera
wx.scanCode({
  onlyFromCamera: true,
  success (res) {
    console.log(res)
  }
})