Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/179.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在gcm中设置生存时间选项_Android_Google Cloud Messaging - Fatal编程技术网

Android 在gcm中设置生存时间选项

Android 在gcm中设置生存时间选项,android,google-cloud-messaging,Android,Google Cloud Messaging,我正在做一个使用gcm的android应用程序。我必须在服务器端设置,因为如果消息未送达,一天后应该将其删除。请帮助我。以下是向gcm服务器发送通知的功能 public function send_notification($registatoin_ids, $message, $coll_key) { // include config include_once './config.php'; // Set POST variables

我正在做一个使用gcm的android应用程序。我必须在服务器端设置,因为如果消息未送达,一天后应该将其删除。请帮助我。以下是向gcm服务器发送通知的功能

public function send_notification($registatoin_ids, $message, $coll_key) {
        // include config
        include_once './config.php';

        // Set POST variables
        $url = 'https://android.googleapis.com/gcm/send';

        $fields = array(
            'collapse_key' => $coll_key,
            'registration_ids' => $registatoin_ids,
            'data' => $message,
        );

        $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;
    }
只需将time_添加到_live参数中,并为其指定一个值,该值等于您希望将消息存储在GCM服务器中而不发送的最大秒数

$fields = array(
    'collapse_key' => $coll_key,
    'registration_ids' => $registatoin_ids,
    'data' => $message,
    'time_to_live' => $time_to_live,
);