2024 还没看到这个问题解决方案
NFC 方法 wx.onHCEMessage(function callback)怎么监听不到消息?小程序开发NFC虚拟卡的时候 wx.onHCEMessage(function callback)这个监听不到回调消息是为啥啊??我就按照官方文档来写的,Android 5.0 OPPO手机可以监听到,但是大于5.0安卓版本的华为手机就收不到消息。请官方给个解释,加急!!
02-25多少年了,没搜到一个确切的解决方案
关于小程序nfc卡模拟中的wx.onHCEMessage(callback)附上官方文档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) { 这个函数一直不执行 没任何结果也不返回任何值 [代码] 请问这个是怎么模拟卡的
02-25