如何设置webServiceURL并成功注册 [英] How to set webServiceURL and register successfully

查看:173
本文介绍了如何设置webServiceURL并成功注册的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我填写 webserviceURL 的部分内容,但是对于 deviceID ,我该怎么办呢?这是我用来注册设备和传递webservice的代码。添加pass后我需要更改才能注册?

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 );
?>


推荐答案

将通行证添加到Passbook时 - iPhone或iPod会调用webServiceURL来告诉你它的设备ID和推送令牌。您无法知道这些是什么,因此您需要设置您的Web服务器,以便它可以同时捕获设备ID和推送令牌。

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.

设备ID作为URL的一部分发送,令牌作为JSON对象发布。

The Device ID is sent as part of the URL and the token is posted as a JSON object.

在Web服务器上,您需要设置重写规则以写入所有流量从 https://192.168.1.105:8888 / passesWebserver / .... https://192.168.1.105:8888/passesWebserver/index .php (搜索Google或SO如何执行此操作)

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)

然后设置index.php,如下所示:

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.

这篇关于如何设置webServiceURL并成功注册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆