简体   繁体   English

如何在查询中发送Google Cloud消息?

[英]how to send google cloud messaging in queing?

Hi i am sending notifications to android mobile from php server. 嗨,我正在从php服务器向Android移动发送通知。 Its working fine with single notifications. 它可以正常处理单个通知。 But if i send 2 notifications at once. 但是,如果我一次发送2条通知。 First notification is replacing by second notifications. 第一个通知将替换为第二个通知。 is there any way i can see 2 notifications in queing (ie like sms inbox message format). 有什么办法可以在排队中看到2条通知(例如,短信收件箱中的邮件格式)。

Below is my php code: 以下是我的php代码:

<?php
define("GOOGLE_API_KEY", "API id");
define("GOOGLE_GCM_URL", "https://android.googleapis.com/gcm/send");

function send_gcm_notify($reg_id, $message) {

$fields = array(
    'registration_ids'  => array( $reg_id ),
    'data'              => array( "message" => $message ),
);

$headers = array(
    'Authorization: key=' . GOOGLE_API_KEY,
    'Content-Type: application/json'
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, GOOGLE_GCM_URL);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));

$result = curl_exec($ch);
if ($result === FALSE) {
    die('Problem occurred: ' . curl_error($ch));
}

curl_close($ch);
echo $result;
}

$reg_id = "device id";
$msg = "Google Cloud Messaging working well";
 for($i=0;$i<=3;$i++){
 send_gcm_notify($reg_id, $msg);}

since you are sending data to the same notification builder.. second one is placed on top of first one. 因为您要将数据发送到同一通知生成器。.第二个放置在第一个放置的顶部。 that is the default way of notification. 这是默认的通知方式。 but if you want to send multiple notifications for two tasks, you should use two notification builders and filter the received messages and call relevant notification builder. 但是如果您要为两个任务发送多个通知,则应使用两个通知构建器并过滤收到的消息并致电相关的通知构建器。 but there are limitations, so this depends on your program requirement. 但是有限制,所以这取决于您的程序要求。

if you are looking for notification as following image 如果您正在寻找通知,如下图

StackYour notifications Stack您的通知

通知栈图像

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM