使用 Flutter 的 NFC 详细信息

问题描述 投票:0回答:2

我如何使用 Flutter 读取 NFC 信用卡详细信息,例如卡号、到期日期和 cvv。我尝试过使用 flutter nfc kitNfc manager 等软件包,但它似乎没有达到我想要的效果。

Future<void> readCardData() async {
    try {
      // Check if NFC is supported on the device
      bool isAvailable = await NfcManager.instance.isAvailable();
      if (!isAvailable) {
        throw Exception('NFC is not available on this device');
      }

      // Start the NFC session
      await NfcManager.instance.startSession(onDiscovered: (NfcTag tag) async {
        Ndef? ndef = Ndef.from(tag);
        if (ndef == null) {
          throw Exception('Tag is not compatible with NDEF');
        }

        // Read NDEF message from tag
        NdefMessage message = await ndef.read();
        if (message == null) {
          Get.snackbar('Error', 'Tag is empty',
              snackPosition: SnackPosition.BOTTOM);
          throw Exception('Tag is empty');
        } else {
          // Parse the message and extract card data
          NdefRecord record = message.records.first;
          String payload = String.fromCharCodes(record.payload);
          List<String> fields = payload.split('|');
          if (fields.length != 4) {
            throw Exception('Invalid card data format');
          }

          cardNumber = fields[0];
          cardHolderName = fields[1];
          expiryDate = fields[2];
          cvv = fields[3];

          // Update the UI with the card data
          update();
          Get.toNamed(
            '/debit-sms',
            arguments: receiveController.text,
          );
        }
      });
    } catch (e) {
      print(e);
    }
  }
flutter nfc payment emv
2个回答
0
投票

我发帖作为回应,因为我没有足够的声誉来发表评论。

我对 Flutter 没有太多经验,但在 ReactNative 中帮助过类似的事情,你可以在here找到该存储库。

观察:通过 NFC 无法从卡中读取 CVV。

步骤如下:

  1. 您需要获取对 NFC 标签的 IsoDep 引用(此库可能有帮助:https://pub.dev/packages/nfc_manager
  2. 向卡发送 APDU 命令以选择 PPSE 并列出所有应用程序
  3. 向卡发送 APDU 命令以选择要提取数据的应用程序
  4. 构建 PDOL(卡从读卡器请求的信息列表以便继续)
  5. 解析 AFL(卡上可供读取的记录列表)
  6. 读取所有记录并筛选出您想要的特定标签(5A是卡号,5f24是过期日期)

所有这些步骤都是在我共享的存储库上的 ReactNative 中完成的,从这里

开始

0
投票

抱歉,您找到了颤振的解决方案吗?请我现在需要它。谢谢

© www.soinside.com 2019 - 2024. All rights reserved.