PKPASS 未在 Passbook 中打开

PKPASS not opennig in Passbook

我是存折新手。我使用 PHP-PKPass 库创建了一个 Web 应用程序来为 Passbook 创建通行证。我使用了必要的许可证。当我提交创建表单时,它会创建一个通行证,但通行证不适用于存折。如果我将它作为电子邮件附件发送,它显示为空。它在 android 上运行良好。我在 Windows PC 上,所以我无法使用 iphone 模拟器查看日志。这是我创建的通行证的 link - http://tanvir.tennisads.com/passbook/passes/pass-36252.pkpass

有人可以帮我确定通行证有什么问题吗?提前致谢。

更新: 我已经删除了信标和位置部分,但遇到了同样的问题。这是生成的 json 代码。

{
  "description": "Kenedy Store",
  "formatVersion": 1,
  "organizationName": "Kenedy Store",
  "passTypeIdentifier": "pass.com.retailness.testing.passbook",
  "serialNumber": "449925",
  "teamIdentifier": "NBN8H8W46L",
  "coupon": {
    "primaryFields": [
      {
        "key": "offer",
        "label": "Any purchase",
        "value": "25% off"
      }
    ],
    "auxiliaryFields": [
      {
        "key": "expires",
        "label": "EXPIRES",
        "value": "30-06-2015"
      }
    ],
    "backFields": [
      {
        "key": "terms",
        "label": "TERMS AND CONDITIONS",
        "value": "tos"
      }
    ]
  },
  "backgroundColor": "rgb(255,255,255)",
  "foregroundColor": "rgb(15, 15, 15)",
  "labelColor": "rgb(85, 85, 85)",
  "logoText": "Kenedy Store"
}

这是我用来创建通行证的 PHP 代码...

<html>
<head>
    <title>Passbook Demo</title>
    <meta charset="UTF-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="styles/bootstrap.min.css">
    <link rel="stylesheet" href="styles/smoke.min.css">
    <link rel="stylesheet" href="styles/custom.css">
    <script src='scripts/jquery.min.js'></script>
    <script src='scripts/bootstrap.min.js'></script>
    <script src='scripts/smoke.min.js'></script>
</head>
<body>
<?php

    function RandomString($length)
    {
        $characters = 'abcdefghijklmnopqrstuvwxyz0123456789';
        $randstring = '';
        for ($i = 0; $i < $length; $i++) {
            $randstring .= $characters[rand(0, strlen($characters))];
        }
        return $randstring;
    }

    $flag = false;

    $name = urldecode($_POST['name']);
    $amount = urldecode($_POST['amount']);
    $message = urldecode($_POST['message']);
    $expires = urldecode($_POST['expires']);
    $email = urldecode($_POST['email']);
    $uuid = urldecode($_POST['uuid']);
    $major = urldecode($_POST['major']);
    $minor = urldecode($_POST['minor']);
    $tos = urldecode($_POST['tos']);
    $appURL = urldecode($_POST['appURL']);
    $lat = urldecode($_POST['lat']);
    $lon = urldecode($_POST['lon']);
    $beacon_msg = urldecode($_POST['beacon_msg']);
    $location_msg = urldecode($_POST['location_msg']);

    $target = "";

    if($_FILES['file']['name']){

        $flag = true;
        $file = $_FILES['file'];
        $n = $file['name'];
        $ext = end((explode(".", $n)));

        $target = "images/up/logo." .$ext;
        move_uploaded_file($file['tmp_name'], $target);

    }   

    require 'includes/PKPass/PKPass.php';

    $pass = new PKPass\PKPass();

    $pass->setCertificate('certificates/Certificate.p12');
    $pass->setCertificatePassword('tanvir123');
    $pass->setWWDRcertPath('certificates/AppleWWDRCA.pem');


    $standardKeys         = array(
        'description'        => "{$name}",
        'formatVersion'      => 1,
        'organizationName'   => "{$name}",
        'passTypeIdentifier' => 'pass.com.retailness.testing.passbook', // 4. Set to yours
        'serialNumber'       => RandomString(6), //CHANGE IT TO RANDOMIZE
        'teamIdentifier'     => 'NBN8H8W46L'
    );

    $associatedAppKeys    = array(
    );
    $relevanceKeys        = array(
    );
    $styleKeys            = array(
        'coupon' => array(
            'primaryFields' => array(
                array(
                    'key'   => 'offer',
                    'label' => "{$message}",
                    'value' =>  "{$amount}% off"
                )
            ),
            'auxiliaryFields' => array(
                array(
                    'key'   => 'expires',
                    'label' => 'EXPIRES',
                    'value' => "{$expires}"
                )
            ),
            'backFields' => array(
                array(
                    'key'   => 'terms',
                    'label' => 'TERMS AND CONDITIONS',
                    'value' => "{$tos}"
                )
            )
        )
    );

    $visualAppearanceKeys = array(
        'backgroundColor' => 'rgb(255,255,255)',
        'foregroundColor' => 'rgb(15, 15, 15)',
        'labelColor' => 'rgb(85, 85, 85)',
        'logoText'        => "{$name}"

    );

    $webServiceKeys       = array();

    // Merge all pass data and set JSON for $pass object
    $passData = array_merge(
        $standardKeys,
        $associatedAppKeys,
        $relevanceKeys,
        $styleKeys,
        $visualAppearanceKeys,
        $webServiceKeys
    );
    $pass->setJSON(json_encode($passData));

    // Add files to the PKPass package
    $pass->addFile('images/icon.png');
    $pass->addFile('images/icon@2x.png');

    if($flag == false) $pass->addFile('images/logo.png');
    else $pass->addFile($target);
    $pass->addFile($target);

    $data = $pass->create(true);
    $path = 'passes/pass-'.RandomString(5).'.pkpass';

    file_put_contents($path, $data);
    //unlink($new_file_path);

    $fullpath = 'http://' . $_SERVER['SERVER_NAME'] . '/passbook/' . $path;

    ?>

    <div class="container">
        <div class="row">
            <div class="col-md-12">
                <div class="col-md-2">
                    <img src="images/logo.png" height="93" width="156" alt="">
                </div>
                <div class="col-md-10 text-center">
                    <h2>Passbook / iBeacon Demo</h2>
                </div>
            </div>
        </div>
        <div class="col-md-6 col-md-offset-3 text-center">
            <a href="<?php echo $fullpath; ?>">Download</a> the pass.<br>
            Or use the QR Code instead: <br>
    <?php
        require 'includes/phpqrcode/qrlib.php';
        QRCode::png($fullpath, $path . '.png');
    ?>
            <img src="<?php echo $path . '.png'; ?>" width=500>

        </div>
    </div>
</body>
</html>

这是我尝试从 iphone 下载通行证时发生的情况的屏幕截图:http://i.imgur.com/5NLAl3g.jpg

查看您的 pass.json 我可以看到两个错误。

"beacons": [{
    "proximityUUID": "",
    "relevantText": "",
    "major": "0",
    "minor": "0"
}],
"locations": [{
    "longitude": "90.42607140943142",
    "latitude": "23.7636902410487",
    "relevantText": "office"
}],

第一个错误是您的信标字典包含无效条目。您尚未提供 proximityUUIDrelevantText

第二个错误被 Xcode 捕获。

Jun 10 09:09:02 pfr MobileSafari[4660] <Warning>: Invalid data error reading pass pass.com.retailness.testing.passbook/314548. Value for key 'latitude' must be of class NSNumber, but is actually of class __NSCFString.

当需要以小数形式提供时,您将纬度和经度值作为字符串提供。

删除信标数组和纬度值和经度值周围的引号,你应该没问题。


更新

你的新通行证没问题。它没有在 phone 上加载,因为您的 Web 服务器没有应用 Content-Type header,因此 iOS 无法将此文件识别为通过。

HTTP/1.1 200 OK
Date: Fri, 12 Jun 2015 17:25:58 GMT
Server: Apache
Last-Modified: Thu, 11 Jun 2015 07:44:56 GMT
Accept-Ranges: bytes
Content-Length: 20604

向此文件添加 Content-Type: application/vnd.apple.pkpass header,您应该会发现它加载正常。

有关如何添加 header 的更多信息,请参阅 this question 的答案。