【发布时间】: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 > " /></center>
</fieldset>
</form>
</div>
</body>
</html>
<?
//}
编辑(@PassKit 的更多信息)
这是我正在使用的证书:
【问题讨论】:
-
您是否在 Apple Developer Portal 中设置了您的通行证类型标识符并从那里生成您的证书?
-
@MikeTaverne 是的,我做到了。你需要截图吗?
-
.pkpass 包的链接或者只是签名文件会很有帮助。