doudou6719 2014-02-24 10:47
浏览 38

推送通知无法在设备上运行

Hi I’m trying to create push notification in my app I’m getting device token and php script I have written by see some tutorials but now I’m not getting the push notification in my device not don’t where I have done wrong here please help me out..

this is my php script ...

<?php

   if($_POST['message']){

   $deviceToken ='here i have given my device token ';

   $message = stripcslashes($_POST['message']);

    $payload = '{
         "aps" :
      {
      "alert" :"'.$message.'",
      "badge" : 1,
      "sound" : "bingbong.aiff"
     }  
    }';
    $ctx = stream_context_create();
    stream_context_set_option($ctx,'ssl', 'local_cert','ck.pem');
    stream_context_set_option($ctx,'ssl','passphrase', 'bali');
    $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);
       }

      ?>

i worte this script using this tutorial here

using this php script im trying to run on my local host but not working pls tell where im doing wrong in the script

thanks.

  • 写回答

2条回答 默认 最新

  • dsdtumf776629385 2014-02-24 11:19
    关注

    server should provide some error/success response, read answer from socket before closing it, also check connection error.

    评论

报告相同问题?