Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

WeChat program API-device-sweeping code


May 19, 2021 WeChat Mini Program Development Document


Table of contents


wx.scanCode(Object object)

Turn up the client broom interface to scan the code

Parameters

Object object

Property Type The default Required Description The lowest version
onlyFromCamera boolean false Whether Whether you can only sweep the code from the camera, do not allow you to select pictures from the album 1.2.0
scanType Array.<string> ['barCode', 'qrCode'] Whether The type of broom 1.7.0
success function Whether The interface calls a successful callback function
fail function Whether The interface calls the failed callback function
complete function Whether Callback function at end of interface call (call succeeds, fails are executed)

The legal value of object.scanType

Value Description The lowest version
barCode One-dimensional code
qrCode QR code
datamatrix Data Matrix code
pdf417 PDF417 barcode

object.success callback function

Parameters
Object res
Property Type Description
result string The contents of the swept code
scanType string The type of code that was swept
charSet string The character set of the swept code
path string When the swept code is the current small program QR code, this field is returned with the path carried by the QR code
rawData string Raw data, base64 encoding

The legal value of res.scanType

Value Description The lowest version
QR_CODE QR code
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 QR code
EAN_8 One-dimensional code
EAN_13 One-dimensional code
ITF One-dimensional code
MAXICODE One-dimensional code
PDF_417 QR code
RSS_14 One-dimensional code
RSS_EXPANDED One-dimensional code
UPC_A One-dimensional code
UPC_E One-dimensional code
UPC_EAN_EXTENSION One-dimensional code
WX_CODE QR code
CODE_25 One-dimensional code

The sample code

// 允许从相机和相册扫码
wx.scanCode({
  success (res) {
    console.log(res)
  }
})

// 只允许从相机扫码
wx.scanCode({
  onlyFromCamera: true,
  success (res) {
    console.log(res)
  }
})