将 vCard 编码为 Apple 钱包的 QR/条形码

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

我正在尝试使用 vCard 作为 Apple Wallet 中的 QR 或条形码的内容。我已经能够对内容进行编码,但二维码不可读 - 我相信这是因为我无法提前正确准备/格式化数据。

当我使用 PHP 时,这不是一个特定于语言的问题。

这是我一直在使用的示例 vCard:

BEGIN:VCARD
VERSION:3.0
REV:2023-11-08T00:00:00Z
N:Murphy;Jill;;;
ORG:Company
TITLE:Developer
EMAIL;INTERNET;WORK:[email protected]
URL:https://example.com
END:VCARD

在Apple的钱包格式中,条形码数据以JSON格式指定:

"barcode": {
    "format": "PKBarcodeFormatQR",
    "message": "VCARD_DATA_HERE",
    "messageEncoding": "iso-8859-1"
},

我尝试了以下各种组合:

  1. 直接传入vCard文本
  2. 使用“
    \n
    ”分隔符将 vCard 数据连接成一行
  3. 使用
    urlencode
    (PHP)
  4. 以上所有内容均包含Apple支持的各种条形码格式

这些格式是: PKBarcodeFormatQR、PKBarcodeFormatPDF417、PKBarcodeFormatAztec 和 PKBarcodeFormatCode128

我知道我可以托管 vCard 并且只需将条形码作为 URL,但我有意选择独立版本。

任何人都可以提供有关如何在将 vCard 文本放入

pass.json
之前对其进行格式化以使其具有可读条形码的指导吗?

ios barcode vcf-vcard passkit apple-wallet
1个回答
0
投票

经过进一步的尝试和错误,我偶然发现了答案。问题在于数据的准备方式。我一直用错误的分隔符连接 vCard 的每一行。

我应该使用“

\n\r
”,就我而言,一旦逃脱将是“
\\r\\n
”。

function getVCard($pass_name) {
    $vcard = '';
    $vcfFilePath = "./passes/$pass_name/vcard.vcf";
    if (file_exists($vcfFilePath)) {
        $vcard = '';
        $file = fopen($vcfFilePath, 'r');
        $vcard = '';
        while (!feof($file)) {
            $line = fgets($file);
            $vcard .= trim($line) . "\\r\\n";
        }
        fclose($file);
    }
    return $vcard;
}

在我的 Apple Wallet

pass.json
中,相关的 JSON 片段如下所示:

"barcode": {
    "format": "PKBarcodeFormatQR",
    "message": "BEGIN:VCARD\r\nVERSION:3.0\r\nREV:2023-11-08T00:00:00Z\r\nN:Murphy;Jill;;;\r\nORG:Company\r\nTITLE:Developer\r\nEMAIL;INTERNET;WORK:[email protected]\r\nURL:https://example.com\r\nEND:VCARD\r\n\r\n",
    "messageEncoding": "iso-8859-1"
},
© www.soinside.com 2019 - 2024. All rights reserved.