【问题标题】:apple push notification service using php使用php的苹果推送通知服务
【发布时间】:2012-10-20 13:01:28
【问题描述】:

我使用以下代码获取推送通知。但我收到类似 Warning: stream_socket_client() [function.stream-socket-client]: 无法连接到 ssl://gateway.sandbox.push.apple.com:2195 的错误(无法找到套接字传输“ssl” - 您在配置 PHP 时是否忘记启用它?)在第 21 行的 D:\xampp\htdocs\push_test\push_test.php 连接失败:5 无法找到套接字传输“ssl” - 您在配置 PHP 时是否忘记启用它? 我不知道该怎么办。请帮忙..

// Put your device token here (without spaces):
$deviceToken = 'xxxxxxxxxxxxxxxxxxxxxx';

// Put your private key's passphrase here:
$passphrase = 'xxxxxxxxx';

// Put your alert message here:
$message = 'My first push notification!';

////////////////////////////////////////////////////////////////////////////////

$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert',      'server_certificates_bundle_sandbox.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);

// Open a connection to the APNS server
$fp = stream_socket_client(
'ssl://gateway.sandbox.push.apple.com:2195', $err,
$errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);

if (!$fp)
exit("Failed to connect: $err $errstr" . PHP_EOL);

echo 'Connected to APNS' . PHP_EOL;

// Create the payload body
$body['aps'] = array(
'alert' => $message,
'sound' => 'default'
);

// Encode the payload as JSON
$payload = json_encode($body);

// Build the binary notification
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;

// Send it to the server
$result = fwrite($fp, $msg, strlen($msg));

if (!$result)
echo 'Message not delivered' . PHP_EOL;
else
echo 'Message successfully delivered' . PHP_EOL;

// Close the connection to the server
fclose($fp);

【问题讨论】:

    标签: php iphone


    【解决方案1】:

    这表明您尚未在服务器上启用 OpenSSL 支持,请检查并告诉我。

    【讨论】:

    • 我怎么知道 OpenSSL 支持是启用还是禁用。我正在我的电脑上运行我的代码..所以我怎么知道它是启用还是禁用..如果它在 phpifo();然后它是这样的: OpenSSL support disabled (install ext/openssl)
    • “OpenSSL support disabled (install ext/openssl)”行表示您的 ssl 支持已禁用。解决方法如下: 启动服务器并在 phpinfo 中查找“配置文件 (php.ini) 路径”和“加载的配置文件” 打开配置文件 (php.ini) 路径 C:\WINDOWS,找到 ;extension= php_openssl.dll 并删除分号 Open Loaded Configuration File C:\xampp\php\php.ini 并在扩展部分添加此代码 extension=php_openssl.dll。
    • 我有两个 php.ini 文件..一个用于 ini 生产,另一个用于 ini 开发..所以我应该在哪里更改它..thanss 的帮助..
    • 更改 `D:\xampp\php` 中的 php.ini 文件(根据您的系统),我想只有一个 php.ini 文件,这就是目标。
    猜你喜欢
    • 2010-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-08
    相关资源
    最近更新 更多