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条)

报告相同问题?

悬赏问题

  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?