如何将URL正确编码到NFC标签上? [英] How to properly encode a URL onto an NFC tag?

查看:945
本文介绍了如何将URL正确编码到NFC标签上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Mifare ULC卡.当我将此卡点击到支持NFC的设备上时,它应该在没有任何其他NFC应用程序的情况下打开手机中的默认浏览器.

I have a Mifare ULC card. When I tap this card to an NFC enabled device, it should open the default browser in phone without any additional NFC application.

我已将下面的NDEF URL数据编码为标签,但是当我扫描标签时,它无法打开浏览器.谁能指导我我在哪里做错了?

I have encoded the below NDEF URL data to the tag, but when i scan the tag, it does not open the browser. Can anyone guide me where I did the mistake?

03 - tag for the NDEF
12 - length of the NDEF msg (18 Bytes)
D3    Record header (of first and only record)
      Bit 7 = MB = 1: first record of NDEF message
      Bit 6 = ME = 1: last record of NDEF message
      Bit 5 = CF = 0: last or only record of chain
      Bit 4 = SR = 1: short record length field
      Bit 3 = IL = 0: no ID/ID length fields
      Bit 2..0 = 011 = 0x3: Absolute URI Record type
01    Type Length = 1 byte
0E    Payload length = 14 bytes
55    Type field "U" (in US-ASCII) = for URI record
02656E02676F6F676C652E636F6D    Payload field (decoded according to the value of the Type field)- 14 Bytes

02    Status byte
      Bit 7 = 0: Text is UTF-8 encoded
      Bit 6 = 0: Not used
      Bit 5..0 = 0x02: Length of IANA language code field
656E  IANA language code field
      "en" (in US-ASCII) = Text is in English
02676F6F676C652E636F6D URL 0x02 = https://www. (URI identifier code) + 676F6F676C652E636F6D = google.com
      "https://www.google.com" (in UTF-8)

推荐答案

您在这里混合了几种不同的记录类型:

You are mixing a few different record types here:

  • 绝对URI记录类型
  • NFC论坛著名的URI类型,和
  • NFC论坛的著名文字类型.

您的记录标题将记录声明为绝对URI记录类型(TNF = 3).此记录类型使用的是类型名称字段(该字段告诉应用程序如何解释记录有效负载)的URI.因此,在这种情况下,URI不是实际的记录有效负载,而仅仅是记录内容的描述符.在您的情况下,这样的记录可能看起来像这样:

You record header declares the record to be an absolute URI record type (TNF = 3). This record type uses are URI for the type name field (the field that tells applications how to interpret the record payload). Hence, the URI is not the actual record payload in that case but only the descriptor for the record contents. In your case, such a record could look like this:


+-------------------------+----------------------------------------------------------------
| D3                      | Record header (MB = ME = 1, CF = 0, SR = 1, IL = 0, TNF = 0x3)
+-------------------------+----------------------------------------------------------------
| 16                      | Type Length (22 bytes)
+-------------------------+----------------------------------------------------------------
| 00                      | Payload Length (0 bytes)
+-------------------------+----------------------------------------------------------------
| 68 74 74 70 73 3A 2F 2F | Type Name ("https://www.google.com")
| 77 77 77 2E 67 6F 6F 67 |
| 6C 65 2E 63 6F 6D       |
+-------------------------+----------------------------------------------------------------

尽管Android仍会将此记录视为URI并应在网络浏览器中打开它,但这肯定不是NDEF规范的创建者想要使用的绝对URI记录.

While Android would still treat this record as a URI and should open it in a web browser, this is certainly not what the creators of the NDEF specification intended absolute URI records to be used for.

相反,NFC论坛为此指定了URI众所周知的类型.由于类型名称("U")和有效负载格式的某些部分与URI众所周知的记录类型的匹配,因此您已经使用了其中的一部分.但是,为了声明您的记录是众所周知的类型记录,您需要将TNF字段设置为1.此外,URI记录类型的有效负载包括一个标识符字节(URI前缀)和截短的URI.

Instead, the NFC Forum specified the URI well-known type for this purpose. You already used parts of that since your type name ("U") and parts of the format of your payload match those of the URI well-known record type. However, in order to declare your record to be a well-known type record, you need to set the TNF field to 1. Moreover, the payload of the URI record type consists of one identifier byte (abbriviated URI prefix) and the truncated URI.


+-------------------------+----------------------------------------------------------------
| D1                      | Record header (MB = ME = 1, CF = 0, SR = 1, IL = 0, TNF = 0x1)
+-------------------------+----------------------------------------------------------------
| 01                      | Type Length (1 byte)
+-------------------------+----------------------------------------------------------------
| 0B                      | Payload Length (11 bytes)
+-------------------------+----------------------------------------------------------------
| 55                      | Type Name ("U")
+-------------------------+----------------------------------------------------------------
| 02 67 6F 6F 67 6C 65 2E | Payload: Identifier code = 2 (prefix "https://www."),
| 63 6F 6D                |          truncated URI = "google.com"
+-------------------------+----------------------------------------------------------------

这篇关于如何将URL正确编码到NFC标签上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆