繁体   English   中英

PHP IOS推送通知不适用于开发

[英]PHP IOS push notifications not working for Development

我想在开发模式下发送推送通知。 我已遵循本指南http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1

我的代码是:

<?php

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

$fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', 
    $err, 
    $errstr, 
    60, 
    STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, 
    $ctx);

if($fp === FALSE){
    exit('error message');
}

// Create the payload body
$body['aps'] = array(
    'badge' => +1,
    'alert' => 'test',
    'sound' => 'default',
    'content-available' => +1
);

$payload = json_encode($body);

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

// Send it to the server
$result = fwrite($fp, $msg, strlen($msg));
 fflush($fp);
if (!$result)
    echo 'Message not delivered' . PHP_EOL;
else
    echo 'Message successfully delivered amar'.$msg. PHP_EOL;

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

问题是当密码文件错误或不存在时,我也总是收到“消息已成功传递”。 如何解决问题? 我哪里错了?

非常感谢

您是否有错误报告? 我只是试图打开您的$ fp连接,但出现了很多错误。

ini_set('display_errors', 1);

到PHP脚本的顶部。

请参阅此代码毒蛇( http://codepad.viper-7.com/PlsftP

警告:stream_socket_client():SSL操作失败,代码为1。OpenSSL错误消息:错误:14090086:SSL例程:SSL3_GET_SERVER_CERTIFICATE:证书验证在第11行的/ code / nyl94y中失败

警告:stream_socket_client():无法在第11行的/ code / nyl94y中启用加密

警告:stream_socket_client():无法连接到第11行PHP / code / nyl94y中的ssl://gateway.sandbox.push.apple.com:2195(未知错误)警告:stream_socket_client():SSL操作失败,代码为1 。OpenSSL错误消息:错误:14090086:SSL例程:SSL3_GET_SERVER_CERTIFICATE:证书在第11行PHP的/ code / nyl94y中验证失败警告:stream_socket_client():无法在第11行PHP的/ code / nyl94y中启用加密警告:stream_socket_client() :无法在第11行的/ code / nyl94y中连接到ssl://gateway.sandbox.push.apple.com:2195(未知错误)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM