You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于Flutter与nfc_manager实现Mifare Classic 1K电子钱包增减值步骤问询

Mifare Classic 1K值区块增减值实现(Flutter + nfc_manager)

你已经完成了Mifare Classic 1K扇区访问位修改(887787FF)和值区块配置,以下是针对值区块实现增减值的具体步骤和修正代码:

核心前提

  • 扇区12的区块49已配置为值区块,区块50为对应的备份块(访问位887787FF已赋予KeyB执行值操作的权限)
  • 所有NFC操作均为异步,必须使用await保证执行顺序

增值操作步骤与代码

  1. 认证目标扇区(使用KeyB,确保有权限执行值操作)
  2. 调用increment将增加值写入临时寄存器
  3. 调用transfer将临时寄存器的值同步到值区块,自动更新备份块

修正后的代码:

try {
  // 认证扇区12
  await tech.authenticateSectorWithKeyB(sectorIndex: 12, key: dataKeyDefault); 
  // 向区块49增加值5500
  await tech.increment(blockIndex: 49, value: 5500);
  // 完成值同步
  await tech.transfer(blockIndex: 49);
} on PlatformException catch (e) {
  throw(e.message ?? '增值操作失败');
}

减值操作步骤与代码

流程与增值一致,仅需将increment替换为decrement:

try {
  await tech.authenticateSectorWithKeyB(sectorIndex: 12, key: dataKeyDefault);
  // 从区块49减值2000
  await tech.decrement(blockIndex: 49, value: 2000);
  await tech.transfer(blockIndex: 49);
} on PlatformException catch (e) {
  throw(e.message ?? '减值操作失败');
}

关键注意事项

  • increment/decrement的value参数为32位无符号整数,取值范围0 ~ 4294967295
  • 必须确保操作的是已配置好的值区块,普通数据块无法执行增减值操作
  • 备份块(区块50)会自动同步值区块的反转数据,无需手动写入
  • 操作前需确认标签处于连接状态,避免因断开导致操作中断

内容的提问来源于stack exchange,提问作者ilham

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.21 18:09:25