PHP苹果iOS推送通知:命令2:二进制接口和通知格式 [英] PHP Apple iOS Push Notifications: Command2 : Binary Interface and Notification Format

查看:129
本文介绍了PHP苹果iOS推送通知:命令2:二进制接口和通知格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如今,随着命令2 PHP和苹果/ iOS的推送通知已经越来越受欢迎。但是不知道如何prepare为相同的格式,按<一个href=\"https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/CommunicatingWIthAPS.html#//apple_ref/doc/uid/TP40008194-CH101-SW6\"相对=nofollow>苹果方针这里,如何实现以下数据包格式:

另外要知道,错误响应数据包如何获得格式如下所述:

在present,我用下面简单的格式:

  $味精=
//新:命令1
字符(1)
//新:标识符1111
。字符(1)。字符(1)。字符(1)。字符(1)
//新:到期明天
。包('N',时间()+ 86400)
//老
。字符(0)。字符(32)。包(H *',str_replace函数('','',$ deviceToken))。字符(0)。字符(strlen的($有效载荷))。 $有效载荷;

 的fwrite($计划生育,$味精,strlen的($味精));


解决方案

  //命令2
$ msgInner =
  字符(1)
。包('N',32)
。包(H *',$ deviceToken)。字符(2)
。包('N',strlen的($负载))
。 $有效载荷。 CHR(3)
。包('N',4)
。字符(1).CHR(1).CHR(1).CHR(1)。字符(4)
。包('N',4)
。包('N',时间()+ 86400)。字符(5)
。包('N',1)
。字符(10);$味精=
字符(2)
。包('N',strlen的($ msgInner))
。 $ msgInner;

和命令8使用此功能:在About苹果增强通知格式

 函数error_response($ FP)
{
    $读=阵列($ FP);
    $空= NULL;
    $ changedStreams = stream_select($读$空,$ NULL,0,1000000);    如果($ changedStreams ===假)
    {
        回声(错误:Unabled等待流可用性);
    }
    ELSEIF($ changedStreams大于0)
    {
        $ responseBinary = FREAD($ FP,6);
        如果($ responseBinary!== ||假的strlen($ responseBinary)== 6)
        {
            $响应=解压('的CCommand / Cstatus_ code / Nidentifier',$ responseBinary);
            后续代码var_dump($响应);
        }
    }
}

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苹果iOS推送通知:命令2:二进制接口和通知格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆