我想在开发模式下发送推送通知。 我已按照本指南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);
?>
问题是当密码o pem文件错误或不存在时,我也会收到“邮件已成功发送”。 如何解决问题?哪里我错了?
非常感谢
答案 0 :(得分:2)
您是否有错误报告?我只是试图打开你的$ fp连接,并且遇到了很多错误。
添加
ini_set('display_errors', 1);
到PHP脚本的顶部。
请参阅此代码viper(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():无法连接 ssl://gateway.sandbox.push.apple.com:2195(未知错误)in 第11行上的/ code / nyl94y PHP警告:stream_socket_client():SSL 代码1操作失败.OpenSSL错误消息: 错误:14090086:SSL例程:SSL3_GET_SERVER_CERTIFICATE:证书 第11行上的/ code / nyl94y验证失败PHP警告: stream_socket_client():无法在/ code / nyl94y上启用加密 第11行PHP警告:stream_socket_client():无法连接 ssl://gateway.sandbox.push.apple.com:2195(未知错误)in 第11行/ code / nyl94y