收藏
回答

小程序NFC识别身份证为啥报发送数据失败,是我传的参数不对吗?那要传什么?

onShow: function () {
    var that = this;


    var adapter = wx.getNFCAdapter();//获取NFCAdapter实例对象
    console.log(adapter);
  
    //启动监听NFC标签
    adapter.startDiscovery({
      successres => {
        that.setData({
          title:'success-->请将设备放入识别区NFC'
        })
        console.log('开始监听贴卡',res);


        //初始化监听回调事件
        adapter.onDiscovered(res => {
          console.log('读到卡片了', res);


          let arrbuf = that.strToArrayBuffer('GET DATA')//字符串转ArrayBuffer  发送IC卡adpu指令 


          if(res.techs.includes(adapter.tech.nfcB)){
            console.log('发现'+adapter.tech.nfcB+'卡'); 
    
            let nfcB = adapter.getNfcB();
            app.nfcB = nfcB;
    
            nfcB.connect({
              successfunction(res){
                console.log('设备已连接', res)
                nfcB.transceive({
                  // data:new ArrayBuffer(0),
                  data:arrbuf,
                  successfunction(res){
                    console.log('发送数据成功, 接收数据如下:', res);
                    that.setData({
                      title:'发送数据成功, 接收数据...'
                    })
                  },
                  failfunction(err){
                    console.log('发送数据失败', err);
                  }
                })
              },
              failfunction(err){
                console.log('设备联接错误', err);
              }
            });
          }
        
        });


      },
      failerror => {
        that.setData({
          title:'错误信息-->' + error.errMsg
        })
        console.log(error);
      },
      completeres => {
        console.log('complete');
        console.log(res);
      }
    });



  },

回答关注问题邀请回答
收藏
登录 后发表内容
问题标签