为什么NfcA.transceive发送数据返回13017?
发布于 4 年前 作者 maomin 9112 次浏览 来自 问答

如题,大致流程是先调用wx.getNFCAdapter,然后调用adapter.startDiscovery,然后调用adapter.onDiscovered,然后调用nfcA.connect,然后调用nfcA.transceive,此时返回13017错误。

基础库版本:2.14.1

Android版本:10

手机型号:一加5t

NFC相关代码如下:

NFCReadCard: function(){
    let _this = this

    let adapter = wx.getNFCAdapter()
    console.log(adapter)

    adapter.startDiscovery({success:(e)=>{
      console.log('开始监听贴卡',e)

      adapter.onDiscovered(function (res){
        console.log('读到卡片了', res);
        //console.log(res.techs);
  
        if(res.techs.includes(adapter.tech.nfcA)){
          console.log('发现'+adapter.tech.nfcA+'卡'); 
  
          let nfcA = adapter.getNfcA();
          app.nfcA = nfcA;
  
          nfcA.connect({
            successfunction(res){
              console.log('设备已连接', res)

              // nfcA.getAtqa({
              //   success: function(res){
              //     console.log('Atqa', res)
              //   }
              // });

              // nfcA.getSak({
              //   success: function(res){
              //     console.log('Sak', res)
              //   }
              // });

              nfcA.isConnected({
                successfunction(res){
                  console.log('Connected')
                }
              });

              // let byteArr = [0x00, 0xa4, 0x00, 0x00, 0x02, 0xdf, 0x01]
              // let byteArrBuffer = new Uint8Array(byteArr).buffer

              let dataBytes = [0x000x840x000x000x02]
              let dataBuffer = new Uint8Array(dataBytes).buffer

              nfcA.transceive({
                // data:new ArrayBuffer(0),
                data: dataBuffer,
                successfunction(res){
                  console.log('发送数据成功, 接收数据如下:', res);
                },
                failfunction(err){
                  console.log('发送数据失败', err);
                }
              })
            },
            failfunction(err){
              console.log('设备联接错误', err);
            }
          });
        }
      })
    }})
  }
回到顶部