GCM设置推送通知的到期日期

编程入门 行业动态 更新时间:2024-10-12 03:27:49
本文介绍了GCM设置推送通知的到期日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已成功使用PHP为我的android用户发送了GCM推送通知,但是我想为我的推送通知设置过期日期,因此,如果用户在1周内没有互联网连接,它将不会收到旧的推送通知. 我如何实现它.

I am successfully sending GCM push notifications for my android users using PHP, but i want to set expiration date for my push notifications so in case the user has no internet connection for 1 week, it will not receive the old push notifications. How i can achieve it.

谢谢.

这是php代码:

private $GOOGLE_API_KEY = "XXXXX"; public function send($registration_id, $data) { // include config // Set POST variables $url = 'android.googleapis/gcm/send'; $fields = array( 'registration_ids' => $registration_id, 'data' => $data, ); $headers = array( 'Authorization: key=' . $this->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_to_live.值以秒为单位(仅一分钟以下)

there is a param time_to_live which you are setting while sending. value is in seconds (below one minute only)

$fields = array( 'registration_ids' => $registration_id, 'data' => $data, 'time_to_live' => 60 );

您可以在发送请求中使用time_to_live参数来指定消息的最大寿命.此参数的值必须为0到2,419,200秒之间的持续时间,并且它对应于GCM将存储并尝试传递消息的最大时间段.不包含此字段的请求的默认最长期限为4周.

You can use the time_to_live parameter in the send request to specify the maximum lifespan of a message. The value of this parameter must be a duration from 0 to 2,419,200 seconds, and it corresponds to the maximum period of time for which GCM will store and try to deliver the message. Requests that don't contain this field default to the maximum period of 4 weeks.

更多此处

更多推荐

GCM设置推送通知的到期日期

本文发布于:2023-10-31 09:06:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1545673.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:日期   通知   GCM

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!