赞
踩
微信小程序官方文档中提供了调用NFC功能,直接在uniapp小程序中直接调用就行
—> wx.getNFCAdapter()
getNFC(){ const nfc = wx.getNFCAdapter() this.nfc = nfc let _this = this function discoverHandler(res) { _this.$refs.popup.close() const data = new Uint8Array(res.id) let str = "" data.forEach(e => { let item = e.toString(16) if (item.length == 1) { item = '0' + item } item = item.toUpperCase() str += item }) /* str就是我们读取出的UID码 */ // console.log(str) /* ------根据需求 16转10进制------ */ let parStr = parseInt(str,16) if (parStr) { /*--在这里进行业务逻辑处理--*/ }else { uni.showToast({ title:'获取失败', icon:'error' }) } } nfc.startDiscovery({ success(res) { uni.showToast({ title: 'NFC读取功能已开启!', icon: 'none' }) nfc.onDiscovered(discoverHandler) }, fail(err) { if (!err.errCode) { uni.showToast({ title: '请检查NFC功能是否正常!', icon: 'none' }) return } } }) },
使用uni.scanCode(),调用小程序中的扫码功能。
getQR(){ let _sanm = this uni.scanCode({ onlyFromCamera: true, // 只允许通过相机扫码 success: function (res) { console.log(res) // console.log('条码类型:' + res.scanType); // console.log('条码内容:' + res.result); if(res.result !== '') { /*在这里进行业务逻辑处理*/ } }, fail(error) { console.log(error) } }); },
官方参数:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。