php pk,php-pkpass

PHP library to create passes for iOS wallet app

This class provides the functionality to create passes for Wallet in Apple's iOS 6 and newer on-the-fly. It creates, signs and packages the pass as a .pkpass file according to Apple's documentation.

Requirements

PHP 5.6 or higher

PHP ZIP Support (may be installed by default)

Access to filesystem (script must be able to create temporary folders)

Installation

Composer

Simply run the following command in your project's root directory to install via Composer:

composer require pkpass/pkpass

Or add to your composer.json: "pkpass/pkpass": "^1.2.0"

Manually

Include the PKPass.php file in your PHP project:

require('src/PKPass.php');

Usage

Please take a look at the example.php file for example usage. For more info on the JSON for the pass and how to style it, take a look at the docs at developers.apple.com.

Requesting the Pass Certificate

Create a new Pass Type ID, and write down the Pass ID you choose, you'll need it later.

Click the edit button under your newly created Pass Type ID and generate a certificate according to the instructions shown on the page. Make sure not to choose a name for the Certificate but keep it empty instead.

Download the .cer file and drag it into Keychain Access.

Find the certificate you just imported and click the triangle on the left to reveal the private key.

Select both the certificate and the private key under it, then right click the certificate in Keychain Access and choose Export 2 items….

Choose a password and export the file to a folder.

guide-export.gif

Getting the example.php sample to work

Request the Pass certificate (.p12) as described above and upload it to your server.

Set the correct path and password on line 22.

Change the passTypeIdentifier and teamIndentifier to the correct values on lines 29 and 31 (teamIndentifier can be found on the Developer Portal).

After completing these steps, you should be ready to go. Upload all the files to your server and navigate to the address of the examples/example.php file on your iPhone.

Included demos

Functions to add files

addFile : add a file without locale like icon.png

addRemoteFile : add a file from a url without locale like https://xyz.io/icon.png

addLocaleFile : add a localized file like strip.png

addLocaleRemoteFile : add a localized file from a url like https://xyz.io/strip.png

Debugging passes

If you aren't able to open your pass on an iPhone, plug the iPhone into a Mac and open the 'Console' application. On the left, you can select your iPhone. You will then be able to inspect any errors that occur while adding the pass:

9db282f301b2b832be252f2531cd1c7d.png

Trust evaluate failure: [leaf TemporalValidity]: If you see this error, your pass was signed with an outdated certificate.

Trust evaluate failure: [leaf LeafMarkerOid]: You did not leave the name of the certificate empty while creating it in the developer portal.

Support & documentation

Please read the instructions above and consult the Wallet Documentation before submitting tickets or requesting support. It might also be worth to check Stackoverflow, which contains quite a few questions about this library.

Email me at thomas [at] scholica.com or tweet me @tschoffelen.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值