简体   繁体   中英

PHP how to unpack Apple APNS feedback data

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM