如何从Web UI读取数据并使用NFC卡共享

发布于 2025-02-12 08:42:20 字数 139 浏览 2 评论 0 原文

我是NFC的新手,我们想要的是我们有一个网页,其中有所有用户详细信息,例如名称,电子邮件,Facebook URL,在URL中链接并存储在数据库中。现在我的问题是,NFC卡或任何应用都可以读取该数据并使用NFC卡共享。

请遵守我的问题,可能是错误的。

I am new to NFC ,what we want is that we have a web page where we have all user details like Name, Email, Facebook URL, Linked in URL and is stored in a database. Now my question is is it possible that an NFC card or any app can read that data and share using the NFC card.

Please bear with my question and may be wrong .

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你穿错了嫁妆 2025-02-19 08:42:20

Web NFC 允许您在Android上读取和编写NFC标签。

要编写一个简单的文本记录,请将字符串传递到 ndefreader write()方法。

const ndef = new NDEFReader();
await ndef.write("Hello World");

scannibg附近的NFC标签也很容易:

const ndef = new NDEFReader();
await ndef.scan();

ndef.addEventListener("reading", ({ message, serialNumber }) => {
  console.log(`> Serial Number: ${serialNumber}`);
  console.log(`> Records: (${message.records.length})`);
});

我建议您阅读 https://web.dev/nfc 与 https://googlechrome.githrome.githrome.github.io/samples/web-nfc/那就是您要寻找的。

在您的具体情况下,我将以JSON格式存储数据,然后稍后阅读:

const encoder = new TextEncoder();
const data = {
  firstname: "François",
  lastname: "Beaufort"
};
const jsonRecord = {
  recordType: "mime",
  mediaType: "application/json",
  data: encoder.encode(JSON.stringify(data))
};

const ndef = new NDEFReader();
await ndef.write({ records: [jsonRecord] });
// Scan NFC tags and go trough |message.records|. 
// Once you have a record, check its |mediaType| and read |data|.
if (record.mediaType === "application/json") {
  const textDecoder = new TextDecoder();
  console.log(`JSON: ${JSON.parse(decoder.decode(record.data))}`);
}

Web NFC allows you to read and write NFC tags on Chrome for Android.

To write a simple text record, pass a string to the NDEFReader write() method.

const ndef = new NDEFReader();
await ndef.write("Hello World");

Scannibg nearby NFC tags is pretty easy as well:

const ndef = new NDEFReader();
await ndef.scan();

ndef.addEventListener("reading", ({ message, serialNumber }) => {
  console.log(`> Serial Number: ${serialNumber}`);
  console.log(`> Records: (${message.records.length})`);
});

I'd recommend you read https://web.dev/nfc and play with https://googlechrome.github.io/samples/web-nfc/ to see if that's what you're looking for.

In your specific case, I'd store data in a JSON format and read them later:

const encoder = new TextEncoder();
const data = {
  firstname: "François",
  lastname: "Beaufort"
};
const jsonRecord = {
  recordType: "mime",
  mediaType: "application/json",
  data: encoder.encode(JSON.stringify(data))
};

const ndef = new NDEFReader();
await ndef.write({ records: [jsonRecord] });
// Scan NFC tags and go trough |message.records|. 
// Once you have a record, check its |mediaType| and read |data|.
if (record.mediaType === "application/json") {
  const textDecoder = new TextDecoder();
  console.log(`JSON: ${JSON.parse(decoder.decode(record.data))}`);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文