PHP如何解压Apple APNS反馈数据

发布于 2024-08-07 14:00:25 字数 148 浏览 7 评论 0原文

我已成功连接到 Apple 的反馈 APNS 服务器,但我不确定如何解压从 fread() 获得的二进制数据。有谁知道该怎么做?文档说前 4 个字节是时间戳,接下来的 2 个字节是令牌长度,其余是设备令牌。

在调用 fread 之后,如何将这些信息解压缩为可读字符?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

栀梦 2024-08-14 14:00:26

一旦你有了二进制流,你可以像这样处理它:

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

$feedback 将是一个包含元素“timestamp”、“length”和“devtoken”的关联数组。

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".

烧了回忆取暖 2024-08-14 14:00:26

实际想了一下,这个似乎更靠谱:

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

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文