0

我填充了 的某些部分webserviceURL,但是对于deviceID,我要为它添加什么?这是我用来注册设备和传递 web 服务的代码。添加 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 );
?>
4

1 回答 1

1

将通行证添加到 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.
于 2013-03-18T05:00:59.187 回答