如何创建执行命令的二维码?

How to create a QR code that execute command?

我见过一些例子,人们在像这样的 QR 码上编写可执行代码 https://itsmattkc.com/etc/snakeqr/。我想创建一个 QR 码来执行命令以打开任何 phone(android & IOS)的特定 phone 应用程序。
过程是这样的,

  1. 用phone扫描二维码。
  2. Phone 执行存储在二维码中的命令(C 语言中类似 "start C:\...\specific app" 的代码) 并打开应用程序或提示用户下载它,如果应用程序未安装在 phone.
  3. 关闭用于执行命令(如果有)的window。

我现在的问题是,

  1. 像我上面说的那样,可以使用什么语言编写打开 phone 应用程序的命令?
  2. 如何将二维码转成二维码?

Background A QR code doesn't itself execute anything, at a high level QR code is just a method of serializing an array of bytes into a visual form, the reader can de-serialize the image back into an array of bytes which must then be interpreted.

Generic QR readers will generally assume that the original data represented an encoded string and so will decode the bytes into a string.

The instructions in SnakeQR tell you to use a QR reader that allow you to save the bytes to disk, instead of decoding them into a string, which just demonstrates that the QR code contains binary data and that the data on its own doesn't do anything, the user needs to take that data and complete the next step to action it, but that action is up to the user.

这就是奇迹开始发生的时候,如果 QR 码表示或包含 URL,那么大多数 reader 应用程序将自动启动网络浏览器并导航到该 URL.

在应用开发领域,我们可以劫持这些 QR 码 reader 的默认行为,以通过 3 种方式与设备交互:

  1. 编写一个网页,该网页将执行脚本以完成您在导航到该页面的设备上的操作,将其托管在全球可访问的某个地方并将 URL 存储到您的 QR 中的该页面代码。

  2. 使用设备将识别为内部位置的 URI,此 post How to launch my android app from a QR reader 描述此过程,在 android 应用程序 API 您可以定义这些 intents,有效地注册具有特定操作的 URI。

    • 这方面的细节不在讨论范围内,这个问题是关于二维码本身的,但大多数操作系统都有类似的过程,其中有绑定到 URI 的标准操作,并且通常有一种机制供您创建自定义绑定。
  3. 编写您自己的专有 QR Reader 应用程序,可以本机理解 QR 码中的命令并可以直接执行它们。

就支持此功能的语言而言,它不是特定于语言的东西,在 Android 应用程序中,您要利用的机制是 Android Intents Tutorial (Android Developers - Intents)。

在 iOS 中,多年来一直存在 URL 绑定的混合版本,但 SiriKit 在功能方面可能是最接近的,它比 [=45] 受到更多限制=],但足以启动应用程序并传递参数。

在 Windows OS 中,您可以注册 URI 方案来做同样的事情...

When it comes to proprietary logic, we can use all 3 methods to build a seemless experience for the users:

  1. Make a landing web page with a message like "If you see this page then you should install my app for an enhanced experience..." (on this page there should be instructions for how to find and install your app)
  2. Make the QR code a URL to the landing page with the parameters that you want passed to the app as URL parameters.
  3. Build and publish your app, in this app you should register the URI to the landing page with the native device OS so that after the device is installed, your app runs instead of the user going to the landing page. Don't forget to map any parameters as startup arguments for your app.