duanliu8998 2013-10-04 09:27
浏览 57
已采纳

推送通知不适用于iOS,.php文件会出现连接错误

For APNS, I had tried with my certificate and web script (.php file) and its working everything fine. Now I am trying the same thing with client provided certificate, he has sent me his .p12 file, I have done all correct stpes and generated .pem file for server but its not working. I didn't get why its happening?? Any one has an idea about it? Here is my server file which I am using to send notifications.

    <?PHP
if($_POST['message'])
{   
    $deviceToken = '<my device token id>';
    $message = stripslashes($_POST['message']);
    $payload = '{
                    "aps" : 

                        { "alert" : "'.$message.'",
                          "badge" : 3,
                          "sound" : "bingbong.aiff"
                        } 
                }';
    $ctx = stream_context_create();
    stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem');
    stream_context_set_option($ctx, 'ssl', 'passphrase', '<my passPharse>');
    $fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
    if(!$fp){
        print "Failed to connect $err $errstrn";
        return;
    } else {
        print "Notifications sent!";
    }
    $devArray = array();
    $devArray[] = $deviceToken;
    foreach($devArray as $deviceToken){
        $msg = chr(0) . pack("n",32) . pack('H*', str_replace(' ', '', $deviceToken)) . pack        ("n",strlen($payload)) . $payload;
        //print "sending message :" . $payload . "n";
        fwrite($fp, $msg);
    }
    fclose($fp);
}
?>
<form action="send-notification.php" method="post">
    <input type="text" name="message" maxlength="100">
    <input type="submit" value="Send Notification">
</form>

This file working well with my .pem file but giving error "Failed to connect 0" with my client's file. I can't able to find the reason for it.

If any one having idea of it then please guide/show me path to solve the problem, Please.

Thank you in advance.

  • 写回答

2条回答 默认 最新

  • dongza3124 2013-10-28 11:51
    关注

    Its was a bug with .pem file. If you not providing the correct password while creating the .pem file from .p12 then the file will be created but it will not work. I checked that process with remote login and caught the issue.

    Thank you all for your help and support :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历