脚本宝典收集整理的这篇文章主要介绍了在php中为passbook创建pass,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
如果我从终端创建传球它工作正常.但在PHP中使用PHP-PKPass.
我在PHP下面留下了代码,它在我的计算机中出现了通行证,但它没有添加到存折中(如果我通过电子邮件发送)
我100%确定passTyPEIdentifier,teamidentifier,Certificate和WWDR 100%正确
注意:所有图像都存在
<?PHP include ("conexion.PHP"); require('passpk/PKPass.PHP'); if (isset($_GET['cupon']) and $_GET['cupon'] != '' and $_GET['cupon'] > 0) { $cuponID = $_GET['cupon']; $pass = new PKPass\PKPass(); $pass->setCertificate('./Certificate.p12'); // 2. Set the path to your Pass Certificate (.p12 file) $pass->setCertificatePassword('*******'); // 2. Set password for certificate $pass->setWWDRcertPath('./WWDR.pem'); // 3. Set the path to your WWDR Intermediate certificate (.pem file) // Top-Level Keys http://developer.apple.COM/library/ios/#documentation/userexperience/Reference/PassKIT_Bundle/Chapters/TopLevel.htML $standardKeys = array( 'description' => 'Store','formatVersion' => 1,'organizationName' => 'Store','passTypeidentifier' => 'pass.store.store',// 4. Set to yours 'serialNumber' => $cupon['id'],'teamIdentifier' => '********' // 4. Set to yours ); $associatedAppKeys = array(); $relevanceKeys = array(); $styleKeys = array( 'coupon' => array( 'PrimaryFields' => array( array( 'key' => 'key','label' => "Label" ) ),'secondaryFields' => array( array( 'key' => 'name','label' => 'Tienda','value' => "Name" ),array( 'key' => 'date','label' => 'Válido hasta','value' => "Vigencia" ) ),'backFields' => array( array( 'key' => 'tienda','value' => "tienda" ),array( 'key' => 'sucursales','label' => 'Sucursales','value' => 'Valido en las sucursales y sus horarios' ),array( 'key' => 'description','label' => 'Descripción','value' => "descr" ),array( 'key' => 'terms','label' => 'Términos y Condiciones','value' => "cupon" ) ) ) ); $VisualAppearanceKeys = array( 'barcode' => array( 'format' => 'PKBarcodeFormatPDF417','message' => "cupon",'messageEncoding' => 'iso-8859-1' ),'foregroundColor' => 'rgb(255,255,255)','backgroundColor' => 'rgb(4,148,203)','logoText' => 'cupon' ); $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)); //creating a temp file called strip.png //generamos un directorio temporal y creamos el strip $uniqID = uniqid('',true); $dir = './tempDir/'.$uniqID; mkdir($dir,0777); //copiamos el Archvio al nuevo directorio copy('../'.$img,'./tempDir/'.$uniqID.'/strip.png'); // Add files to the PKPass package $pass->addFile($dir.'/strip.png'); $pass->addFile('images/icon.png'); $pass->addFile('images/icon@2x.png'); $pass->addFile('images/logo.png'); $pass->addFile('images/logo@2x.png'); if(!$pass->create(true)) { // Create and output the PKPass echo 'Error: '.$pass->getError(); } //borramos el folder temp unlink($dir.'/strip.png'); rmdir($dir); }
Mar 25 10:45:40 iPhone mobileSafari[279] <Warning>: Invalid data error reading pass pass.cuponice.cuponice/9. Pass dictionary must contain key 'value'. Mar 25 10:45:40 iPhone MobileSafari[279] <Warning>: PassBook Pass download Failed: The pass cannot be read because it isn't valid.
深入研究pass.json,我发现你的PRimaryFields字典不包含’value’键.
"primaryFields": [{ "key": "key","label": "30% de Descuento en Persianas" } ],
要修复,请更改PHP以将值键添加到primaryFields字典中.
$styleKeys = array( 'coupon' => array( 'primaryFields' => array( array( 'key' => 'key','label' => "Label",'value' => "" ) ),//...
以上是脚本宝典为你收集整理的在php中为passbook创建pass全部内容,希望文章能够帮你解决在php中为passbook创建pass所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。