duan39779 2013-08-05 17:14
浏览 55

PHP上的推送通知错误(iOS上的简单推送通知)

Im developing iPhone application for push notification and Im getting an error when I run the php file on my localhost. I have created the Certificates, .pem file correctly. And then when I test the app on my localhost host, Warnings are displayed.


Warning: stream_socket_client() [function.stream-socket-client]: Unable to set private key file `/Applications/XAMPP/xamppfiles/htdocs/PushNotificationProject/ck.pem' in /Applications/XAMPP/xamppfiles/htdocs/PushNotificationProject/simplepush.php on line 21

Warning: stream_socket_client() [function.stream-socket-client]: failed to create an SSL handle in /Applications/XAMPP/xamppfiles/htdocs/PushNotificationProject/simplepush.php on line 21

Warning: stream_socket_client() [function.stream-socket-client]: Failed to enable crypto in /Applications/XAMPP/xamppfiles/htdocs/PushNotificationProject/simplepush.php on line 21

Warning: stream_socket_client() [function.stream-socket-client]: unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error) in /Applications/XAMPP/xamppfiles/htdocs/PushNotificationProject/simplepush.php on line 21 Failed to connect: 0


Im getting this errors. What might be the cause of this errors?

This is my php Code.

<?php
// Put your device token here (without spaces):
$deviceToken = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
// Put your private key's passphrase here:
$passphrase = 'xxxxxxxxxx';

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

$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.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',
    'badge' => '1'
);

// 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);
?>

Please help me to fix this errors.

  • 写回答

3条回答 默认 最新

  • dspvin19712 2013-08-05 17:36
    关注

    I have seen that you didn't use any SSL Certificate. Create you SSL Certificate for your app first.

    enter image description here

    评论

报告相同问题?

悬赏问题

  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图