PHP how to unzip Apple APNS feedback data

I managed to establish a connection to the APNS server with Apple feedback, but I'm not sure how to unpack the binary data received from fread (). Does anyone know how to do this? The documentation says that the first 4 bytes are the timestamp, the next 2 bytes are the token length, and the rest are the device token.

How is this information unpacked into readable characters after calling in fread?

+4
source share
2 answers

Actually, it turned out that it seems more reliable:

$arr = unpack("H*", $devconts); $rawhex = trim(implode("", $arr)); $feedbackTime = hexdec(substr($rawhex, 0, 8)); $feedbackDate = date('Ymd H:i', $feedbackTime); $feedbackLen = hexdec(substr($rawhex, 8, 4)); $feedbackDeviceToken = substr($rawhex, 12, 64); 
+2
source

Once you have a binary stream, you can process it as follows:

 while ($data = fread($stream, 38)) { $feedback = unpack("N1timestamp/n1length/H*devtoken", $data); // Do something } 

$ feedback will be an associative array containing the elements "timestamp", "length" and "devtoken".

+6
source

All Articles