

English
Call up the code scanning interface of the client, and return the corresponding result after the code scanning is successful.
Platform Difference Description
App | H5 | 微信小程序 | 支付宝小程序 | 百度小程序 | 抖音小程序、飞书小程序 | QQ小程序 | 快手小程序 | 京东小程序 | 元服务 | 小红书小程序 |
---|---|---|---|---|---|---|---|---|---|---|
√ | x | √ | √ | √ | √ | √ | √ | √ | √ | √ |
HarmonyOS |
---|
HBuilderX 4.23 |
OBJECT parameter description
Parameter Name | Type | Required | Description | Platform Difference Description |
---|---|---|---|---|
onlyFromCamera | Boolean | 否 | 是否只能从相机扫码,不允许从相册选择图片 | 抖音小程序、百度小程序、支付宝小程序不支持此参数 |
scanType | Array | 否 | 扫码类型,参考下方scanType的合法值 | 抖音小程序不支持此参数 |
autoDecodeCharset | Boolean | No | Whether to enable the automatic character encoding function, the default is No | App |
autoZoom | Boolean | No | Whether to enable auto zoom, enabled by default | Only supported by App-Android (3.5.4+) |
barCodeInput | Boolean | No | Whether to support manual barcode input | Only supported by Feishu MiniApp(V3.14.0) |
hideAlbum | Boolean | No | Whether to hide the album (not allowed to select pictures from the album), only scan the code from the camera. The default value is false. | Only supported by Alipay MiniApp |
success | Function | No | The callback of the successful interface call. For the return content, please refer to the return parameter description. | |
fail | Function | No | Callback function for interface call failure (triggered when identification fails, user cancels, etc.) | |
complete | Function | No | The callback function of the end of the interface call (it will be executed when the call succeeds or fails) |
Legal value of scanType
value | description |
---|---|
barCode | one-dimensional code |
qrCode | QR code |
datamatrix | Data Matrix code |
pdf417 | PDF417 Barcode |
success return parameter description
Parameter | Description | Platform Difference Description |
---|---|---|
result | 所扫码的内容 | |
scanType | 所扫码的类型 | App、微信小程序、百度小程序、QQ小程序、京东小程序、支付宝小程序、小红书小程序 |
charSet | 所扫码的字符集 | App、微信小程序、百度小程序(所扫码的字符集,仅支持 Android 系统)、QQ小程序、京东小程序、小红书小程序 |
path | 当所扫的码为当前应用的合法二维码时,会返回此字段,内容为二维码携带的 path。 | 微信小程序、QQ小程序、京东小程序、小红书小程序 |
rawData | 原始数据,base64 编码 | 微信小程序、QQ小程序、京东小程序、支付宝小程序、小红书小程序 |
code | Data obtained by scanning the code | Alipay MiniApp |
qrCode | Return QR code data when scanning a QR code | Alipay MiniApp |
barCode | Return barcode data when scanning a barcode | Alipay MiniApp |
imageChannel | 来源 | 支付宝小程序 |
errMsg | 小红书小程序 |
example
// Allow scanning codes from camera and album
uni.scanCode({
success: function (res) {
console.log('条码类型:' + res.scanType);
}
});
// Only allow scanning codes through the camera
uni.scanCode({
onlyFromCamera: true,
success: function (res) {
console.log('条码类型:' + res.scanType);
}
});
// invoke barcode scanning
uni.scanCode({
scanType: ['barCode'],
success: function (res) {
console.log('条码类型:' + res.scanType);
}
});
Tip
fail
callbackcharSet
, path
in success
callback