mpx.scanCode(Object object)
调起客户端扫码界面进行扫码
支持情况: 微信、支付宝
参数
Object object
| 属性 | 类型 | 默认值 | 必填 | 说明 | 最低版本 | |||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| onlyFromCamera | boolean | false | 否 | 是否只能从相机扫码,不允许从相册选择图片 | 1.2.0 | |||||||||||||||||||||||||||
| scanType | Array.<string> | ['barCode', 'qrCode', 'wxCode'] | 否 | 扫码类型 | 1.7.0 | |||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||
| success | function | 否 | 接口调用成功的回调函数 | |||||||||||||||||||||||||||||
| fail | function | 否 | 接口调用失败的回调函数 | |||||||||||||||||||||||||||||
| complete | function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) | |||||||||||||||||||||||||||||
object.success 回调函数
参数
Object res
| 属性 | 类型 | 说明 | 支付宝 | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| result | string | 所扫码的内容 | ✓ | ||||||||||||||||||||||||||||||||||||||||
| scanType | string | 所扫码的类型 | ✓ | ||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||
| charSet | string | 所扫码的字符集 | ✗ | ||||||||||||||||||||||||||||||||||||||||
| path | string | 当所扫的码为当前小程序二维码时,会返回此字段,内容为二维码携带的 path | ✗ | ||||||||||||||||||||||||||||||||||||||||
| rawData | string | 原始数据,base64编码 | ✗ | ||||||||||||||||||||||||||||||||||||||||
示例代码
js
// 允许从相机和相册扫码
mpx.scanCode({
success (res) {
console.log(res)
}
})
// 只允许从相机扫码
mpx.scanCode({
onlyFromCamera: true,
success (res) {
console.log(res)
}
})