PHP Apple iOS 推送通知:Command2:二进制接口和通知格式 [英] PHP Apple iOS Push Notifications: Command2 : Binary Interface and Notification Format
本文介绍了PHP Apple iOS 推送通知:Command2:二进制接口和通知格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如今,带有 Command 2 的 PHP 和 Apple/iOS 推送通知越来越流行.但是不确定如何准备相同的格式,根据
function error_response($fp){$read = 数组($fp);$null = 空;$changedStreams = stream_select($read, $null, $null, 0, 1000000);如果($changedStreams === false){echo ("错误:无法等待流可用性");}elseif ($changedStreams > 0){$responseBinary = fread($fp, 6);if ($responseBinary !== false || strlen($responseBinary) == 6){$response = unpack('Ccommand/Cstatus_code/Nidentifier', $responseBinary);var_dump($response);}}}
Nowadays, PHP and Apple/iOS Push Notifications with Command 2 has been becoming popular. However not sure, how to prepare the format for same, as per Apple guideline here, How to achieve below packet format:
Also would like to know, how to receive Format of error-response packet
as mentioned below:
At present, I am using below simple format:
$msg =
// new: Command "1"
chr(1)
// new: Identifier "1111"
. chr(1) . chr(1) . chr(1) . chr(1)
// new: Expiry "tomorrow"
. pack('N', time() + 86400)
// old
. chr(0) . chr(32) . pack('H*', str_replace(' ', '', $deviceToken)) . chr(0) . chr(strlen($payload)) . $payload;
with
fwrite($fp, $msg, strlen($msg));
解决方案
//command 2
$msgInner =
chr(1)
. pack('n', 32)
. pack('H*', $deviceToken)
. chr(2)
. pack('n', strlen($payload))
. $payload
. chr(3)
. pack('n', 4)
. chr(1).chr(1).chr(1).chr(1)
. chr(4)
. pack('n', 4)
. pack('N', time() + 86400)
. chr(5)
. pack('n', 1)
. chr(10);
$msg=
chr(2)
. pack('N', strlen($msgInner))
. $msgInner;
and for command 8 use this function: (by Yudmt) at About the apple Enhanced notification format
function error_response($fp)
{
$read = array($fp);
$null = null;
$changedStreams = stream_select($read, $null, $null, 0, 1000000);
if ($changedStreams === false)
{
echo ("Error: Unabled to wait for a stream availability");
}
elseif ($changedStreams > 0)
{
$responseBinary = fread($fp, 6);
if ($responseBinary !== false || strlen($responseBinary) == 6)
{
$response = unpack('Ccommand/Cstatus_code/Nidentifier', $responseBinary);
var_dump($response);
}
}
}
这篇关于PHP Apple iOS 推送通知:Command2:二进制接口和通知格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文