先获取使用wx.getNFCAdapter获取实例
IsoDep支持ISO-DEP (ISO 14443-4)标准的读写(有不同的芯片,文档有支持其他的),刚好对应我所发指令的卡片,获取实例的getIsoDep
开始startDiscovery->监听onDiscovered,传入要监听的函数
根据文档IsoDep的操作
连接->复位->发送指令-》获取到ArrayBuffer转成十六制,再根据具体需求转换,如果读取的是中文要转gbk,图片直接十六进制转base64
代码如下
getNFC() {
let that = this
const nfc = wx.getNFCAdapter()
this.nfc = nfc
let isoDep = nfc.getIsoDep()
this.isoDep = isoDep
nfc.startDiscovery({
success(res) {
nfc.onDiscovered(discoverHandler)
},
fail(err) {
if (!err.errCode) {
wx.showToast({
title: '请检查NFC功能是否正常!',
icon: 'none'
})
return
}
switch (err.errCode) {
case 13000:
wx.showToast({
title: '设备不支持NFC!',
icon: 'none'
})
break;
case 1