无法使用MobileSafari将生成的pkpass添加到iPhone

时间:2014-12-19 02:38:04

标签: php ios json passbook

我正在使用PHP库PHP-PKPass生成一个.pkpass,但问题是,我不能将它添加到我的手机上,而且它会抛出:

Invalid data error reading pass pass.com.bittank.kidstation/1243. The passTypeIdentifier or teamIdentifier provided may not match your certificate, or the certificate trust chain could not be verified.

我有相应的证书(Certificate.p12,WWDCRA.pem) 通常,此错误意味着缺少证书,但它不是真的。

<?php

//if(isset($_POST['name'])){
    // User has filled in the card info, so create the pass now

    setlocale(LC_MONETARY, 'en_US');
    require('../src/PKPass.php');

    // Variables
    $id = rand(100000,999999) . '-' . rand(100,999) . '-' . rand(100,999); // Every card should have a unique serialNumber
    $balance = '$'.rand(0,30).'.'.rand(10,99); // Create random balance
    $name = stripslashes($_GET['name']);
    $children = stripslashes($_GET['children']);
    $date = stripslashes($_GET['date']);
    $allergies = stripslashes($_GET['allergies']);
    // Create pass
$pass = new PKPass\PKPass();

    $pass->setCertificate('../Certificate.p12');  // 2. Set the path to your Pass Certificate (.p12 file)
$pass->setCertificatePassword('password');     // 2. Set password for certificate
$pass->setWWDRcertPath('../WWDCRA.pem'); // 3. Set the path to your WWDR Intermediate certificate (.pem file)

    $pass->setJSON('{ 
    "passTypeIdentifier": "pass.com.bittank.kidstation",
    "formatVersion": 1,
    "organizationName": "Kid Station",
    "teamIdentifier": "Z48RKT6B3T",
    "serialNumber": "1243",
    "expirationDate": "'.$date.'",
    "backgroundColor": "rgb(240,240,240)",
    "logoText": "Kid Station",
    "description": "Demo pass",
    "storeCard": {
        "secondaryFields": [
            {
                "key": "balance",
                "label": "Children",
                "value": "'.$children.'"
            },
            {
                "key": "name",
                "label": "Parent",
                "value": "'.$name.'"
            }

        ],
        "backFields" : [
        {
            "key" : "special-concerns",
            "label" : "Special Concerns",
            "value" : "'.$allergies.'"
        },
        {
            "key" : "website",
            "label" : "Track my checked bags",
            "value" : "http://www.example.com/track-bags/XYZ123"
        },
        {
            "key" : "customer-service",
            "label" : "Customer service",
            "value" : "(800) 555-0199"
        },
        {
            "key" : "terms",
            "label" : "Terms and Conditions",
            "value" : "O Fortuna velut luna statu variabilis, semper crescis aut decrescis; vita detestabilis nunc obdurat et tunc curat ludo mentis aciem, egestatem, potestatem dissolvit ut glaciem.\n\n Sors immanis et inanis, rota tu volubilis, status malus, vana salus semper dissolubilis, obumbrata et velata michi quoque niteris; nunc per ludum dorsum nudum fero tui sceleris.\n\n Sors salutis et virtutis michi nunc contraria, est affectus et defectus semper in angaria.  Hac in hora sine mora corde pulsum tangite; quod per sortem sternit fortem, mecum omnes plangite!"
        }
    ]


    },
    "barcode": {
        "format": "PKBarcodeFormatPDF417",
        "message": "'.$id.'",
        "messageEncoding": "iso-8859-1",
        "altText": "'.$id.'"
    }
    }');

    // add files to the PKPass package
    $pass->addFile('icon.png');
    $pass->addFile('icon@2x.png');
    $pass->addFile('logo.png');
    $pass->addFile('background.png', 'strip.png');

    if(!$pass->create(true)) { // Create and output the PKPass
        echo 'Error: '.$pass->getError();
    }
    exit;

//*}else{
    // User lands here, there are no $_POST variables set   
    ?>
    <html>
        <head>
            <title>Starbucks pass creator - PHP class demo</title>

            <!-- Reusing some CSS from another project of mine -->
            <link href="http://www.lifeschool.nl/static/bootstrap.css" rel="stylesheet" type="text/css" />
            <meta name="viewport" content="width=320; user-scalable=no" />
            <style>
                .header { background-color: #CCC; padding-top: 30px; padding-bottom: 30px; margin-bottom: 32px; text-align: center; }
                .logo { width: 84px; height: 84px; margin-bottom: 20px; }
                .title { color: black; font-size: 22px; text-shadow: 1px 1px 1px rgba(0,0,0,0.1); font-weight: bold; display: block; text-align: center; }
                .userinfo { margin: 0px auto; padding-bottom: 32px; width: 280px;}
                form.form-stacked { padding: 0px;}
                legend { text-align: center; padding-bottom: 25px; border-bottom: none; clear: both;}
                input.xlarge { width: 280px; height: 26px; line-height: 26px;}
            </style>
        </head>
        <body>
            <div class="header">
                <img class="logo" src="logo_web.png" />
                <span class="title">Starbucks</span>
            </div>
            <div class="userinfo">
                <form action="index.php" method="post" class="form-stacked">
            <fieldset>
                <legend style="padding-left: 0px;">Please enter your info</legend>

                <div class="clearfix">
                    <label style="text-align:left">Nickname</label>
                    <div class="input">
                        <input class="xlarge" name="name" type="text" value="Johnny's card" />
                    </div>
                </div>

                <br /><br />
                <center><input type="submit" class="btn primary" value=" Create pass &gt; " /></center>
            </fieldset>
        </form>

            </div>
        </body>
    </html>
    <?
//}

编辑(@PassKit的更多信息)

这是我使用的证书: KeyChain Cert ID

1 个答案:

答案 0 :(得分:2)

在十六进制编辑器中查看了您的签名后,您的问题似乎是您没有使用Pass Type ID证书进行签名。具体而言,您已使用Apple Development IOS Push Services证书com.bittank.kidstation进行了签名。所有有效的通行证类型ID证书均以pass.开头。 pass.com.bittank.kidstation

Hex Editer Screenshot

创建Pass Type ID证书是一个2阶段的过程(在发布时是正确的):

首先,使用&#39; 证书,身份和配置文件&#39; 左侧的标识符选项创建通行证类型ID Apple Developer Portal中的页面。

Apple Developer Portal

其次,使用证书部分通过选择&#39; 通行证类型ID证书&#39;来创建证书。在生产部分下。值得注意的是,Passbook没有开发证书。

Apple Developer Portal

在Finder中检查有效的Pass Type ID证书时,您应该看到证书公用名以 Pass Type ID开头:

Valid Pass Type ID Certificate