duanang58939 2015-04-21 00:34
浏览 13

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

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://www.androidhive.info/2012/10/android-push-notifications-using-google-cloud-messaging-gcm-php-and-mysql/

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

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.

</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
    • ¥15 关于#hadoop#的问题
    • ¥15 (标签-Python|关键词-socket)
    • ¥15 keil里为什么main.c定义的函数在it.c调用不了
    • ¥50 切换TabTip键盘的输入法
    • ¥15 可否在不同线程中调用封装数据库操作的类
    • ¥15 微带串馈天线阵列每个阵元宽度计算