附上官方文档https://developers.weixin.qq.com/miniprogram/dev/api/device/nfc/wx.getHCEState.html
根据官方文档的做法 我的code如下
console.log('aa')
wx.getHCEState({
success(res) {
console.log(res)
wx.showToast({
title: 'getHCEState' + res.errCode,
duration: 2000
})
const buffer = new ArrayBuffer(1)
const dataView = new DataView(buffer)
dataView.setUint8(0, 0)
console.log(buffer)
wx.startHCE({
aid_list: ['F223344556'],
success: function(res) {
console.log('startHCE')
wx.showToast({
title: 'startHCE',
duration: 2000
})
wx.onHCEMessage(function(res) {
console.log('onHCEMessage',res)
wx.showToast({
title: 'onHCEMessage',
duration: 2000
})
if (res.messageType === 1) {
console.log('res.messageType === 1');
wx.sendHCEMessage({
data: buffer,
success:(res)=>{
console.log('sendHCEMessage'+res)
},
fail:(res)=>{
console.log('sendHCEMessage失败' + res)
}
})
}
})
},
fail(res) {
console.log(res)
}
})
},
fail(res) {
console.log(res)
wx.showToast({
title: res,
duration: 2000
})
}
})
以上代码执行结果如下 我把手机放到读卡器上了 没反应
wx.onHCEMessage(function(res) {
这个函数一直不执行 没任何结果也不返回任何值
请问这个是怎么模拟卡的