lundi 20 avril 2015

GCM PHP server more than 1000 users not working

Vote count: 0

I´m new with PHP and need some help. I had a GCM(Google Cloud Messaging) server but now there are more than 1000 users and no longer works the code I used is from this tutorial with some changes http://ift.tt/R4qKMa

Now this is where I think is wrong

<?php
 
class GCM {
 
    //put your code here
    // constructor
    function __construct() {
         
    }
 
    /**
     * Sending Push Notification
     */
    public function send_notification($registation_ids, $message) {
        // include config
        include_once './config.php';
 
        // Set POST variables
        $url = 'http://ift.tt/YbbTRA';

        // set group
        $groups = array_chunk($registation_ids, 1000);

        foreach($groups as $group) { 
        $fields = array(
            'registration_ids' => $group,
            'data' => array('contentTitle'=>'The Title','contentText'=>$message,'tickerText' => 'New Video!!!','type'=>'notification'),
        );
 
        $headers = array(
            'Authorization: key=' . GOOGLE_API_KEY,
            'Content-Type: application/json'
        );
        // Open connection
        $ch = curl_init();
 
        // Set the url, number of POST vars, POST data
        curl_setopt($ch, CURLOPT_URL, $url);
 
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 
        // Disabling SSL Certificate support temporarly
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
 
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
 
        // Execute post
        $result = curl_exec($ch);
        if ($result === FALSE) {
            die('Curl failed: ' . curl_error($ch));
        }
        
        }
        // Close connection
        curl_close($ch);
        echo $result;
        
    }
 
}
 
?>

But I get a 403(Forbidden) error on send_message.php which is:

<?php

if (isset($_POST["regId"]) && isset($_POST["message"])) {
    $regId = $_POST["regId"];
    $message = $_POST["message"];
    $strRegID = strval($regId);
     
    include_once './GCM.php';
    include_once './db_functions.php';
    $gcm = new GCM();
 
    $registation_ids = $regId;
    //$message = array("messageTyped" => $message);

    $result = $gcm->send_notification($registation_ids, $message);
    $db = new DB_Functions();

    if (strcasecmp ( strval($result) , 'NotRegistered' )) {
        //print "No Registrado";
                $db->deleteUser($regId);
    }
 
    echo $result;
}
?>

I´m really lost please any help is appreciated.

asked 27 secs ago



GCM PHP server more than 1000 users not working

Aucun commentaire:

Enregistrer un commentaire