2013-10-04 09:27


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.

    $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);
        print "Failed to connect $err $errstrn";
    } 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);
<form action="send-notification.php" method="post">
    <input type="text" name="message" maxlength="100">
    <input type="submit" value="Send Notification">

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.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • dongza3124 dongza3124 8年前

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

    点赞 评论 复制链接分享
  • doufang8282 doufang8282 8年前

    i think thats issue of p12 files if its not making properly then this error will came and to make sure it again just use follow code to generate pem file then also if not working then its wrong p12 file

    openssl pkcs12 -in server_certificates_bundle_sandbox.p12 -out server_certificates_bundle_sandbox.pem -nodes -clcerts

    点赞 评论 复制链接分享