代码之家  ›  专栏  ›  技术社区  ›  Rahul Shelke

增强的Apple推送通知:提供程序服务器上的响应错误

  •  0
  • Rahul Shelke  · 技术社区  · 14 年前

    我正在用PHP开发一个项目,它要求我在APNS服务器上推送一个警报通知。我使用了增强的推送通知格式。但我没有收到APNS文档指定的响应。我得到的答复是三位数,通常是133、132、154、138等,我认为这是状态标志,例如133是1、3、3。但现在我也收到了139份。所以我怀疑我对反应的解释是错误的。但我不知道错在哪里。重要的是,尽管我收到了这些回复,但我的手机和iPad都收到了通知。

    我的代码如下:

    $payload['aps'] = array('alert' => $message, 'badge' => 1, 'sound' => 'default');
    
    $apnsHost = 'gateway.sandbox.push.apple.com'; 
    
    $apnsPort = 2195; // default port
    
    $apnsCert = 'apns-dev.pem'; // APNS crtificate.
    
    $passPhrase = '';
    
    $streamContext = stream_context_create();
    
    stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);
    
    stream_context_set_option($streamContext, 'ssl', 'passphrase', $passPhrase);
    
    try{
    
    $apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 60, STREAM_CLIENT_CONNECT, $streamContext);
    
    if (!$apns) {
        print "Failed to connect {$error} {$errorString}\n";
    }
    else {   
        // Sending the payload
    
        $apnsMessage = chr(0) . pack('n', 1) . pack('n', $nid) . pack('n', time() + 604800) . pack('n', 32) . pack('H*', str_replace(' ', '', $alert_device_token)) .  pack('n', strlen($payload)) . $payload;
    
        echo 'APNS Message: ' . $apnsMessage;
    
        $fwrite = fwrite($apns, $apnsMessage);
    
        echo 'APNS response: ' . $fwrite;
    

    执行此操作时,浏览器上会显示以下响应:

    有人能告诉我这139在这里是什么意思吗。我做错什么了。

    1 回复  |  直到 14 年前
        1
  •  1
  •   Daan    14 年前

    回显的“139”是fwrite()的返回值。它是fwrite()写入的字节数

    见: PHP: fwrite