【问题标题】:Getting errors using APNS PHP使用 APNS PHP 获取错误
【发布时间】:2010-12-26 06:42:18
【问题描述】:

这是我正在使用的代码

<?php
$deviceToken = 'my device key';  // not putting in for security

$payload['aps'] = array('alert' => 'This is the alert text', 'badge' => 1, 'sound' => 'default');
$payload = json_encode($payload);

$apnsHost = 'gateway.sandbox.push.apple.com';
$apnsPort = 2195;
$apnsCert = 'apns-dev.pem';

$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);

$apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext);

$apnsMessage = chr(0) . chr(0) . chr(32) . pack('H*', str_replace(' ', '', $deviceToken)) . chr(0) . chr(strlen($payload)) . $payload;
fwrite($apns, $apnsMessage);

socket_close($apns);
fclose($apns);
?>

我得到了这些错误

警告:stream_socket_client() [function.stream-socket-client]: Unable to set private key file `apns-dev.pem' in /home/bryan/sendpush.php on line 14

警告:stream_socket_client() [function.stream-socket-client]:未能在第 14 行的 /home/bryan/sendpush.php 中创建 SSL 句柄

警告:stream_socket_client() [function.stream-socket-client]:无法在第 14 行的 /home/bryan/sendpush.php 中启用加密

警告:stream_socket_client() [function.stream-socket-client]:无法连接到 /home/bryan/sendpush.php 中的 ssl://gateway.sandbox.push.apple.com:2195(未知错误)第 14 行

警告:fwrite():提供的参数不是第 17 行 /home/bryan/sendpush.php 中的有效流资源

警告:socket_close() 期望参数 1 是资源,布尔值在 /home/bryan/sendpush.php 第 19 行给出

警告:fclose():提供的参数不是第 20 行 /home/bryan/sendpush.php 中的有效流资源

实际上我现在已经把它归结为这些错误

警告:stream_socket_client() [function.stream-socket-client]:SSL 操作失败,代码为 1。OpenSSL 错误消息:错误:14094410:SSL 例程:SSL3_READ_BYTES:sslv3 警报 /home/bryan/PushService 中的握手失败。第27行的php

警告:stream_socket_client() [function.stream-socket-client]:无法在第 27 行的 /home/bryan/PushService.php 中启用加密

警告:stream_socket_client() [function.stream-socket-client]:无法连接到 /home/bryan/PushService.php 中的 ssl://gateway.sandbox.push.apple.com:2195(未知错误)上线

【问题讨论】:

标签: php push-notification apple-push-notifications


【解决方案1】:
  1. 使用私钥的绝对路径而不是相对路径。

  2. 1234563 @)。

【讨论】:

    【解决方案2】:

    我也遇到了这个错误。发现我在包含证书文件的文件夹上设置了错误的权限。这对我有用:

    chmod 755 your_folder_that_has_certificate_files
    

    【讨论】:

    • 我看不出证书目录将如何从拥有任何写入或执行证书中受益。 444(全球阅读)肯定就够了吗?
    • 有人不会简单地 chmod 777/755 整个服务器。这是一个私钥是有原因的。
    猜你喜欢
    • 2017-10-04
    • 2010-11-06
    • 2013-10-02
    • 1970-01-01
    • 1970-01-01
    • 2013-04-04
    • 1970-01-01
    • 1970-01-01
    • 2023-04-09
    相关资源
    最近更新 更多