关于GCM的问题,要发送信息到所有移动设备中:
PHP:
$resultcoment = mysql_query("SELECT * FROM notificaciones");
while ($row = mysql_fetch_array($resultcoment)){
$result = '"' . $row['regId'] . '", ';
//print_r($result);
$registrationIDs = array($result);
}
$message = $_POST['message'];
$fields = array(
'registration_ids' => $registrationIDs,
'data' => array( "message" => $message ),
);
结果:
"APA91bHmIHSNCSG_YVHYZMPRrXmw-E_iy7bPA9bo934n67afw8hXJHZvm1MNhrPaRtN6XbkXVjZ9T9YFH9qNi0zM5b9cPGxDhrkhysTXyRwTRLd02lQ- v_e4zWkiGGhQt4BpH_ZLNGGAAU6hWo8ny8Mm2_d7GlEkwcKkZdNhWFO5HXGHWF4gbzM", "APA91bHmIHSNCSG_YVHYZMPRrXmw-E_iy7bPA9bo934n67afw8hXJHZvm1MNhrPaRtN6XbkXVjZ9T9YFH9qNi0zM5b9cPGxDhrkhysTXyRwTRLd02lQ-v_e4zWkiGGhQt4BpH_ZLNGGAAU6hWo8ny8Mm2_d7GlEkwcKkZdNhWFO5HXGHWF4gbzM", "APA91bElWWgUTnoI3YRRunJ_BbaAcdc4PASCB3LxcFWQM9RALQE0hc0c1xVF-EIR7iLYFlbeMDjnMPY-503fqzOPAjJT514zo1j86uhUobhlu79PKtvzjMXiBavoiUcaSKY__JVTbQALvmZ8NJtzzRG81Tf1-svTjw", "APA91bElWWgUTnoI3YRRunJ_BbaAcdc4PASCB3LxcFWQM9RALQE0hc0c1xVF-EIR7iLYFlbeMDjnMPY-503fqzOPAjJT514zo1j86uhUobhlu79PKtvzjMXiBavoiUcaSKY__JVTbQALvmZ8NJtzzRG81Tf1-svTjw", {"multicast_id":8410297698153738741,"success":0,"failure":1,"canonical_ids":0,"results": [{"error":"InvalidRegistration"}]}
怎么会这样?
你在每个迭代中重写了数组。
这样:
$resultcoment = mysql_query("SELECT * FROM notificaciones");
$registrationIDs = array();
while ($row = mysql_fetch_array($resultcoment)){
$result = '"' . $row['regId'] . '", ';
//print_r($result);
$registrationIDs[] = $result;
}
$message = $_POST['message'];
$fields = array(
'registration_ids' => $registrationIDs,
'data' => array( "message" => $message ),
);
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。