GCM PHP服务器超过1000个用户无法正常工作

时间:2015-04-21 00:34:46

标签: php cloud google-cloud-messaging server messaging

我是PHP的新手,需要一些帮助。我有一个GCM(谷歌云消息传递)服务器,但现在有超过1000个用户,不再使用我使用的代码来自本教程,并进行了一些更改http://www.androidhive.info/2012/10/android-push-notifications-using-google-cloud-messaging-gcm-php-and-mysql/

现在这是我认为错误的地方

<?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 = 'https://android.googleapis.com/gcm/send';

	// 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;
	
    }
 
}
 
?>

但是我在send_message.php上收到403(Forbidden)错误,该错误是:

<?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;
}
?>

我真的迷路了,欢迎任何帮助。

0 个答案:

没有答案