
Yesterday I added Apple Wallet passes to the DNA Lounge ticketing system: now when you buy a ticket, the confirmation email comes with an attachment that will dump the ticket into your phone such that it will automatically pop up on your lock screen when you are in physical proximity of the club on the day of the event. It's kinda neat.
What I haven't figured out is how to send push notifications.
When someone adds the pass to their phone, their phone registers with my server, sending it the device ID, the serial number of the pass, and a "pushToken". I should be able to take this info and tell Apple, "tell the device to re-download the pass from my server".
The Binary Provider API document explains how to pack up a request to ship off to Apple. The "device ID" is a 32-digit hex number, meaning a 16-byte value; and the "pushToken" is a 64-digit hex number, meaning a 32-byte value, so I assume that when that doc says "32 byte device token" it means the "pushToken" and not the "device ID".
So I'm packing it up like this, and getting neither an error message back, nor a return connection from the phone. What am I missing?
- $note_id = time();
$expires = time() + (60 * 60 * 24);
$payload = "{}";
// Decode the 64-digit hex string to a 32-byte number.
$push_token = pack ('H*', $push_token);
$items = (chr(1) . // ID 1 = device token
pack('n', strlen($push_token)) .
$push_token .
chr(2) . // ID 2 = payload
pack('n', strlen($payload)) .
$payload .
chr(3) . // ID 3 = notification ID
pack('n', 4) .
pack('N', $note_id) .
chr(4) . // ID 4 = expiration date
pack('n', 4) .
pack('N', $expires) .
chr(5) . // ID 5 = priority
pack('n', 1) .
chr(10));
$cmd = (chr(2) . // Command = 2
pack ('N', strlen($items)) .
$items);
...
stream_context_set_option ($ctx, 'ssl', 'local_cert', $CERT_FILE);
$fp = stream_socket_client ('ssl://gateway.push.apple.com:2195', ...
Please do not answer with "pay some third-party web service to do this for you" or "install this multi-gigabyte black-box framework".
Update: Got it working, woo...