将通行证添加到 Passbook 时 - iPhone 或 iPod 将调用 webServiceURL 告诉您它的设备 ID 和推送令牌。您无法知道这些是什么,因此您需要设置您的 Web 服务器,以便它可以捕获设备 ID 和推送令牌。
设备 ID 作为 URL 的一部分发送,令牌作为 JSON 对象发布。
在您的网络服务器上,您需要设置一个重写规则以将所有流量写入https://192.168.1.105:8888/passesWebserver/....
到https://192.168.1.105:8888/passesWebserver/index.php
(搜索 Google 或 SO 以了解如何执行此操作)
然后设置一个 index.php 是这样的:
// Transfer Request URL into array
$request = explode("/", substr(@$_SERVER['REQUEST_URI'], 1));
/**
* Register Device
*
* POST request to version/devices/<deviceLibraryIdentifier>/registrations/<passTypeIdentifier>/<serialNumber>
* Request will contain an Authorisation header with the value <ApplePass authenticationToken>, where
* authenticationToken equals the authenticationToken in the original voucher payload.
*/
if (strtoupper($_SERVER['REQUEST_METHOD']) === "POST"
&& isset($_SERVER['HTTP_AUTHORIZATION'])
&& strpos($_SERVER['HTTP_AUTHORIZATION'], 'ApplePass') === 0
&& $request[2] === "devices"
&& $request[4] === "registrations") {
$auth_key = str_replace('ApplePass ', '', $_SERVER['HTTP_AUTHORIZATION']);
$device_id = $request[3];
$pass_id = $request[5];
$serial = $request[6];
// Catch the JSON post and decode it
$dt = @file_get_contents('php://input');
$device_token = json_decode($dt);
$device_token = $device_token->pushToken;
if (!$device_token) die('No Token Found'); // Token wasn't found
// Add code to check the Auth Token against the serial number and add the
// device details to your database so you can use them later to push updates
// to the pass. This code should return a 200, 201 or other response depending
// on whether the auth is valid and the device is registered already or not
exit;
}
// Add other conditions to check for unregister, get serials, refresh and log.