谷歌云消息:发送邮件到"所有的"用户 [英] Google Cloud Messaging: Send message to "all" users
问题描述
我下面<一个href=\"http://www.androidhive.info/2012/10/android-push-notifications-using-google-cloud-messaging-gcm-php-and-mysql/\"相对=nofollow>本教程了解GCM制度。我有一个关于这部分的问题:
有可能将消息发送到每一个registred用户,但如何改变code这样我就可以发送一个消息给所有regisrted设备?
我已经找了答案:
<一个href=\"http://stackoverflow.com/questions/25859898/sending-push-notifications-to-multiple-android-devices-using-gcm\">sending使用推GCM 通知到多个Android设备
和
<一个href=\"http://stackoverflow.com/questions/17018027/sending-push-notification-on-multiple-devices\">Sending在多个设备上推送通知
(几乎相同的问题) - 但找不到任何答案解决我的问题。
&LT;身体GT;
&LT; PHP
include_once'db_functions.php';
$ DB =新DB_Functions();
$用户= $ DB-GT&; getAllUsers();
如果($用户!= FALSE)
$ NO_OF_USERS = mysql_num_rows($用户);
其他
$ NO_OF_USERS = 0;
?&GT;
&LT; DIV CLASS =容器&GT;
&LT; H1&GT;没有设备注册:&LT; PHP的echo $ NO_OF_USERS; ?&GT;&LT; / H1&GT;
&LT;小时/&GT;
&LT; UL类=设备&GT;
&LT; PHP
如果($ NO_OF_USERS大于0){
?&GT;
&LT; PHP
而($行= mysql_fetch_array($用户)){
?&GT;
&LT;立GT;
&LT;表ID =&LT; PHP的echo $行[身份证]≥? NAME =方法=邮报的onsubmit =返回sendPushNotification('&LT; PHP的echo $行[身份证]&GT;')&GT;
&LT;标签&gt;名称:LT; /标签&gt; &LT;跨度&GT;&LT; PHP的echo $行[名称]&GT;&LT; / SPAN&GT;
&LT; DIV CLASS =清除&GT;&LT; / DIV&GT;
&LT;标签&gt;电子邮件:&LT; /标签&gt; &LT;跨度&GT;&LT; PHP的echo $行[电子邮件]&GT;&LT; / SPAN&GT;
&LT; DIV CLASS =清除&GT;&LT; / DIV&GT;
&LT; DIV CLASS =send_container&GT;
&LT; textarea的行数=3NAME =消息COLS =25级=txt_message占位符=请在此处输入消息&GT;&LT; / textarea的&GT;
&LT;输入类型=隐藏的名字=REGIDVALUE =&LT; PHP的echo $行[gcm_regid]&GT;/&GT;
&LT;输入类型=提交级=send_btnVALUE =发送的onclick =/&GT;
&LT; / DIV&GT;
&LT; /表及GT;
&LT; /李&GT;
&LT; PHP}
?}其他{&GT;
&LT;立GT;
没有用户尚未登记!
&LT; /李&GT;
&LT; PHP}&GT?;
&LT; / UL&GT;
&LT; / DIV&GT;
&LT; /身体GT;
我试图改变code,但与我的变化这是行不通的。
我希望把所有REGID作为数组sendPushNofiy ...
&LT;身体GT;
&LT; PHP
include_once'db_functions.php';
$ DB =新DB_Functions();
$用户= $ DB-GT&; getAllUsers();
如果($用户!= FALSE)
$ NO_OF_USERS = mysql_num_rows($用户);
其他
$ NO_OF_USERS = 0;
?&GT;
&LT; DIV CLASS =容器&GT;
&LT; H1&GT;没有设备注册:&LT; PHP的echo $ NO_OF_USERS; ?&GT;&LT; / H1&GT;
&LT;小时/&GT;
&LT; UL类=设备&GT;
&LT; PHP
如果($ NO_OF_USERS大于0){
?&GT;
&LT; PHP &LT;立GT;
$行=阵列();而(($行= mysql_fetch_array($用户))){
$行[] = $行['身份证']; }
&LT;表ID =&LT; PHP的echo $行&GT;? NAME =方法=邮报的onsubmit =返回sendPushNotification('&LT; PHP的echo $行&GT;')&GT;
&LT;标签&gt;名称:LT; /标签&gt; &LT;跨度&GT;&LT; PHP的echo $行[名称]&GT;&LT; / SPAN&GT;
&LT; DIV CLASS =清除&GT;&LT; / DIV&GT;
&LT;标签&gt;电子邮件:&LT; /标签&gt; &LT;跨度&GT;&LT; PHP的echo $行[电子邮件]&GT;&LT; / SPAN&GT;
&LT; DIV CLASS =清除&GT;&LT; / DIV&GT;
&LT; DIV CLASS =send_container&GT;
&LT; textarea的行数=3NAME =消息COLS =25级=txt_message占位符=请在此处输入消息&GT;&LT; / textarea的&GT;
&LT;输入类型=隐藏的名字=REGIDVALUE =&LT; PHP的echo $行[gcm_regid]&GT;/&GT;
&LT;输入类型=提交级=send_btnVALUE =发送的onclick =/&GT;
&LT; / DIV&GT;
&LT; /表及GT;
&LT; /李&GT;
&LT; PHP
?}其他{&GT;
&LT;立GT;
没有用户尚未登记!
&LT; /李&GT;
&LT; PHP}&GT?;
&LT; / UL&GT;
&LT; / DIV&GT;
&LT; /身体GT;
这个我可以得到所有regids到数组行...但我怎么可以在阵列转移到如何形成的?
而($行= mysql_fetch_array($用户)){
$行[] = $行[gcm_regid]; }
我的问题是如何把我的阵列行到send_message.php?
$ registatoin_ids =阵列($ REGID); &LT;&LT;它已经处理了数组,但我的投入只能与一个值,我想转移阵列^^
编辑:
send_message.php
如果(使用isset($ _ GET [REGID])及和放大器;使用isset($ _ GET [消息])){
$ REGID = $ _GET [REGID];
$消息= $ _GET [消息]; include_once'./GCM.php'; $ GCM =新GCM(); $ registatoin_ids =阵列($ REGID);
$消息=阵列(价格=&GT; $消息); $结果= $ gcm-&GT; send_notification($ registatoin_ids,$消息); 回声$结果;
}
?&GT;
这是你的责任,以维护所有注册用户的注册ID的列表。有没有API调用将消息发送给所有注册用户。您最多可以与1000的注册ID发送到GCM服务器发送请求。如果您拥有注册用户超过1000,你必须给他们分裂多个请求。
I am following this tutorial to understand the system of GCM. I have a question regarding this part:
It is possible to send messages to every single registred user, but how to change that code so I can send a single message to ALL regisrted devices?
I've already looked for answers:
sending push notifications to multiple android devices using GCM
and
Sending Push Notification on multiple devices
(nearly same question) - but could not find any answer solving my question.
<body>
<?php
include_once 'db_functions.php';
$db = new DB_Functions();
$users = $db->getAllUsers();
if ($users != false)
$no_of_users = mysql_num_rows($users);
else
$no_of_users = 0;
?>
<div class="container">
<h1>No of Devices Registered: <?php echo $no_of_users; ?></h1>
<hr/>
<ul class="devices">
<?php
if ($no_of_users > 0) {
?>
<?php
while ($row = mysql_fetch_array($users)) {
?>
<li>
<form id="<?php echo $row["id"] ?>" name="" method="post" onsubmit="return sendPushNotification('<?php echo $row["id"] ?>')">
<label>Name: </label> <span><?php echo $row["name"] ?></span>
<div class="clear"></div>
<label>Email:</label> <span><?php echo $row["email"] ?></span>
<div class="clear"></div>
<div class="send_container">
<textarea rows="3" name="message" cols="25" class="txt_message" placeholder="Type message here"></textarea>
<input type="hidden" name="regId" value="<?php echo $row["gcm_regid"] ?>"/>
<input type="submit" class="send_btn" value="Send" onclick=""/>
</div>
</form>
</li>
<?php }
} else { ?>
<li>
No Users Registered Yet!
</li>
<?php } ?>
</ul>
</div>
</body>
i tried to change the code, but with my change it does not work..
I want to put all regID as array into sendPushNofiy...
<body>
<?php
include_once 'db_functions.php';
$db = new DB_Functions();
$users = $db->getAllUsers();
if ($users != false)
$no_of_users = mysql_num_rows($users);
else
$no_of_users = 0;
?>
<div class="container">
<h1>No of Devices Registered: <?php echo $no_of_users; ?></h1>
<hr/>
<ul class="devices">
<?php
if ($no_of_users > 0) {
?>
<?php
<li>
$rows = array();
while(($row = mysql_fetch_array($users))) {
$rows[] = $row['id'];
}
<form id="<?php echo $rows ?>" name="" method="post" onsubmit="return sendPushNotification('<?php echo $rows ?>')">
<label>Name: </label> <span><?php echo $row["name"] ?></span>
<div class="clear"></div>
<label>Email:</label> <span><?php echo $row["email"] ?></span>
<div class="clear"></div>
<div class="send_container">
<textarea rows="3" name="message" cols="25" class="txt_message" placeholder="Type message here"></textarea>
<input type="hidden" name="regId" value="<?php echo $row["gcm_regid"] ?>"/>
<input type="submit" class="send_btn" value="Send" onclick=""/>
</div>
</form>
</li>
<?php
} else { ?>
<li>
No Users Registered Yet!
</li>
<?php } ?>
</ul>
</div>
</body>
with this I can get all regids into the array rows... but how can i transfer the array into the form?
while ($row = mysql_fetch_array($users)) {
$rows[] = $row["gcm_regid"];
}
my problem is how to send my array "row" to send_message.php?
$registatoin_ids = array($regId); << it does already handles array, but my input works only with one value, i want to transfer array^^
EDIT: send_message.php
if (isset($_GET["regId"]) && isset($_GET["message"])) {
$regId = $_GET["regId"];
$message = $_GET["message"];
include_once './GCM.php';
$gcm = new GCM();
$registatoin_ids = array($regId);
$message = array("price" => $message);
$result = $gcm->send_notification($registatoin_ids, $message);
echo $result;
}
?>
It's your responsibility to maintain a list of the Registration IDs of all the registered users. There's no API call to send a message to all registered users. You can send to GCM server a request with up to 1000 Registration IDs. If you have more than 1000 registered users, you'll have to split them to multiple requests.
这篇关于谷歌云消息:发送邮件到&QUOT;所有的&QUOT;用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!