Отправлять Push-уведомления нескольким токенам с помощью PHP (iOS)


У меня есть база данных со всеми кодами устройств. Я продолжаю забирать токены из базы данных, но мой скрипт больше не работает (толчки не отправляются).

Это мой сценарий:

<?PHP

$db_user = "xxx"; // Gebruiker voor MySQL
$db_pass = "xxx"; // Wachtwoord voor MySQL
$db_host = "localhost"; // Host voor MySQL; standaard localhost
$db_db = "xxx"; // Database

// Als je al ergens anders een database connectie hebt gemaakt,
// maak dan van de volgende twee regels commentaar (# of // ervoor zetten)
mysql_connect($db_host,$db_user,$db_pass);
mysql_select_db($db_db);

$query = mysql_query("SELECT * FROM iospush");

                                while ($row = mysql_fetch_array($query)) {
                                    $deviceToken = $row["devicetoken"];
                                    }

if($_POST['message']){

//  $deviceToken = 'xxx';

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

    $payload = '{
                    "aps" : 

                        { "alert" : "'.$message.'",
"badge" : 1
                        } 
                }';


    $ssl='xx.pem';

    $ctx = stream_context_create();
    stream_context_set_option($ctx, 'ssl', 'local_cert', $ssl);
    stream_context_set_option($ctx, 'ssl', 'passphrase', 'xxx');
    $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="pushios.php" method="post">
    <input type="text" name="message" maxlength="100">
    <input type="submit" value="Send Notification">
</form>

Пожалуйста, помогите мне заставить это работать!

Спасибо в связи с этим!

Author: Rick de Jong, 0000-00-00

2 answers

$deviceToken = ARRAY();
while ($row = mysql_fetch_array($query)) {
  $deviceToken[] = $row["devicetoken"];
}

...

// or use ($devArray = $deviceToken;)

foreach($deviceToken as $token){
    $msg = chr(0) . pack("n",32) . pack('H*', str_replace(' ', '', $token)) . pack        ("n",strlen($payload)) . $payload;
 7
Author: djot, 2013-04-11 22:46:24
function addStoryData() {

    header("Content-Type:application/json");

    $notification = $this->input->post('message');

    $device_id = $this->db->select('device_id')
                               ->from('tbl_device')
                               ->where('device_type','iPhone')
                               ->get()
                               ->result_array();

    //$this->sendApplePushNotification($device_id,$notification,1);

    foreach ($device_id as $d_id) {                           

        $device_id  = $d_id['device_id'];
        $this->sendApplePushNotification($device_id,$notification,1);
    }


}

function sendApplePushNotification($tToken,$tAlert,$notification)
{

     /*
        print_r($tToken);
        echo '----------------------------';
        print_r($tAlert);
        echo '----------------------------';
        print_r($detail);
        echo '----------------------------';
        print_r($notification);
        echo '----------------------------';
        print_r($tToken);
        die;
    */    
        $tPayload="test";
        //$tHost = 'gateway.sandbox.push.apple.com';
        $tHost = 'gateway.push.apple.com';

        $tPort = 2195;

        // Provide the Certificate and Key Data.
        // home/ibliocrq/public_html/shopostreet.com/shopostreet/application/ckShopostreet_development.pem
         //echo $this->config->item('pushcertDevelopment.pem');die;

        //echo base_url('RestAPI/pushcertDevelopment.pem');
        //die;
        $tCert =  '/home/chatstor/public_html/readify/pushcertDistribution.pem';
         //$tCert =  '/home/chatstor/public_html/readify/pushcertDevelopment.pem';


        
 0
Author: ,