2015-06-10 28 views
0

我是新來的存摺。我使用PHP-PKPass庫創建了一個Web應用程序來爲Passbook創建通行證。我使用了必要的許可證。當我提交創建表單時,它會創建一個通行證,但通行證不適用於存摺。如果我將它作爲電子郵件附件發送,則顯示爲空。它在Android上正常工作。我在Windows PC上,所以我不能使用iPhone模擬器來查看日誌。這裏是我創建的一個通行證的鏈接 - http://tanvir.tennisads.com/passbook/passes/pass-36252.pkpassPKPASS沒有在存摺opennig

有人能幫我找出通行證有什麼問題嗎?提前致謝。

更新:我已經刪除了信標和位置部分,但具有相同的問題。這是生成的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 = 'abcdefghijklmnopqrstuvwxyz'; 
     $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/[email protected]'); 

    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> 

這裏是什麼hapenning截圖當我嘗試下載從iphone通:http://i.imgur.com/5NLAl3g.jpg

回答

0

看着你的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. 

當您需要以小數形式提供您的緯度和經度值作爲字符串時。

將信標陣列和引號圍繞經度值和長度值,並且您應該沒問題。


更新

你的新通罰款。它不會在手機上加載,因爲您的網絡服務器未應用Content-Type標題,因此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頭添加到這個文件,你會發現,它加載確定。

有關如何添加標題的更多信息,請參閱this question的答案。

+0

感謝您的回覆。我嘗試過,但仍然是同樣的問題。我正在創建json文件。我還會添加php代碼以及在嘗試下載iPhone上的通行證時發生什麼的屏幕截圖。 –

+0

你可以上傳你的新通行證嗎? – PassKit

+0

我已經生成了一個新的... [這裏](http://tanvir.tennisads.com/passbook/passes/pass-9487.pkpass) –