I've successfully managed to connect to Apple's feedback APNS server but I'm not sure how to unpack the binary data you get from fread(). Does anyone know how to do this? The documentation says the first 4 bytes are the timestamp, the next 2 are the token length and the rest are the device token.
How does this info get unpacked into readable characters after the call to fread?
Once you have your binary stream, you can process it like this:
while ($data = fread($stream, 38)) {
$feedback = unpack("N1timestamp/n1length/H*devtoken", $data);
// Do something
}
$feedback will be an associative array containing elements "timestamp", "length" and "devtoken".
Actually figured it out, this seems to be more reliable:
$arr = unpack("H*", $devconts);
$rawhex = trim(implode("", $arr));
$feedbackTime = hexdec(substr($rawhex, 0, 8));
$feedbackDate = date('Y-m-d H:i', $feedbackTime);
$feedbackLen = hexdec(substr($rawhex, 8, 4));
$feedbackDeviceToken = substr($rawhex, 12, 64);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With