问题
I fill some parts of webserviceURL, but for deviceID, what do I put for it? This is the code I use to register device and pass for webservice. What do I need to change in order to register after adding pass ?
<?php
echo "<a href= 'genericPass.php'> Click here to add Generic Pass</a><br/>";
echo "<a href= 'couponPass.php'> Click here to add Coupon Pass</a>";
$url = 'https://192.168.1.105:8888/passesWebserver/v1/devices/{deviceID}/registrations/pass.cam-mob.passbookpasstest/E5982H-I2';
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_POST, 1);
//curl_setopt( $ch, CURLOPT_POSTFIELDS, $myvars);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt( $ch, CURLOPT_HEADER, 0);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec( $ch );
?>
回答1:
When a pass is added to Passbook - the iPhone or iPod will call the webServiceURL to tell you it's device ID and push token. There is no way you can know what these are, so you need to set your web server up so that it can catch both the device ID and the push token.
The Device ID is sent as part of the URL and the token is posted as a JSON object.
On your web server, you need to set a rewrite rule to write all traffic from https://192.168.1.105:8888/passesWebserver/.... to https://192.168.1.105:8888/passesWebserver/index.php (search Google or SO on how to do this)
Then set up a index.php something like this:
// 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.
来源:https://stackoverflow.com/questions/15469533/how-to-set-webserviceurl-and-register-successfully