forked from tschoffelen/php-pkpass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.php
87 lines (80 loc) · 2.66 KB
/
example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
require('src/PKPass.php');
$pass = new PKPass\PKPass();
$pass->setCertificate('../Certificate.p12'); // 2. Set the path to your Pass Certificate (.p12 file)
$pass->setCertificatePassword('test123'); // 2. Set password for certificate
$pass->setWWDRcertPath('../AppleWWDRCA.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' => 'Demo pass',
'formatVersion' => 1,
'organizationName' => 'Flight Express',
'passTypeIdentifier' => 'pass.com.apple.test', // 4. Set to yours
'serialNumber' => '123456',
'teamIdentifier' => 'AGK5BZEN3E' // 4. Set to yours
);
$associatedAppKeys = array();
$relevanceKeys = array();
$styleKeys = array(
'boardingPass' => array(
'primaryFields' => array(
array(
'key' => 'origin',
'label' => 'San Francisco',
'value' => 'SFO'
),
array(
'key' => 'destination',
'label' => 'London',
'value' => 'LHR'
)
),
'secondaryFields' => array(
array(
'key' => 'gate',
'label' => 'Gate',
'value' => 'F12'
),
array(
'key' => 'date',
'label' => 'Departure date',
'value' => '07/11/2012 10:22'
)
),
'backFields' => array(
array(
'key' => 'passenger-name',
'label' => 'Passenger',
'value' => 'John Appleseed'
)
),
'transitType' => 'PKTransitTypeAir'
)
);
$visualAppearanceKeys = array(
'barcode' => array(
'format' => 'PKBarcodeFormatQR',
'message' => 'Flight-GateF12-ID6643679AH7B',
'messageEncoding' => 'iso-8859-1'
),
'backgroundColor' => 'rgb(107,156,196)',
'logoText' => 'Flight info'
);
$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/icon@2x.png');
$pass->addFile('images/logo.png');
if(!$pass->create(true)) { // Create and output the PKPass
echo 'Error: '.$pass->getError();
}