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

Posted

技术标签:

【中文标题】无法使用 MobileSafari 将生成的 pkpass 添加到 iPhone【英文标题】:Unable to add generated pkpass to iPhone using MobileSafari 【发布时间】:2014-12-19 02:38:03 【问题描述】:

我正在生成一个带有 php 库 PHP-PKPass 的 .pkpass,但问题是,我无法使用 MobileSafari 将它添加到我的手机中,它会抛出:

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 的更多信息)

这是我正在使用的证书:

【问题讨论】:

您是否在 Apple Developer Portal 中设置了您的通行证类型标识符并从那里生成您的证书? @MikeTaverne 是的,我做到了。你需要截图吗? .pkpass 包的链接或者只是签名文件会很有帮助。 @PassKit pass.keatonburleson.com/pass/starbucks_sample/… 【参考方案1】:

在十六进制编辑器中查看您的签名后,您的问题似乎是您没有使用 Pass Type ID 证书进行签名。具体来说,您已经使用Apple Development ios Push Services 证书com.bittank.kidstation 进行了签名。所有有效的 Pass Type ID 证书都以 pass. 开头,例如pass.com.bittank.kidstation.

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

首先,使用 Apple Developer Portal 中“Certificates, Identities and Profiles”页面左侧的Identifiers选项创建一个 Pass Type ID。

其次,使用 Certificates 部分通过选择 Production 部分下的“Pass Type ID Certificate”来创建证书。需要注意的是,Passbook 没有开发证书。

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

开头

【讨论】:

感谢您的洞察力,我刚刚添加了与您所说的内容有关的更多信息。我看不出有什么问题,只是好奇它为什么会这样做。 我认为您可能需要仔细检查您从 pass.cer 下载到您在代码中使用的 certificate.p12 文件的过程。毫无疑问,您的通行证包已使用推送证书(而不是您在上面显示的证书)进行签名。猜测一下,我会说您从钥匙串中导出了错误的证书。 我将删除所有内容并重新开始,然后再报告。 另外,使用 Finder 快速查看您的 p12 文件。这应该可以确认您是否已成功导出。

以上是关于无法使用 MobileSafari 将生成的 pkpass 添加到 iPhone的主要内容,如果未能解决你的问题,请参考以下文章

将pk传递到Django中的另一个模板

MobileSafari 的正确触摸按钮行为

EF 无法识别 Oracle 中的视图 PK

无法使用 Node 在 iOS 模拟器中连接到 Mobile Safari

使用自动生成的主键 PK 的核心数据

从 MySQL 中的现有表生成更改日志时,liquibase 如何处理自动递增的 PK?