1

我对 GCM 有疑问,需要有关此主题的一些帮助。向所有移动设备发送消息

PHP:

    $resultcomment = mysql_query("SELECT * FROM notificaciones");

    while ($row = mysql_fetch_array($resultcomment)){
    $result = '"' . $row['regId'] . '", ';
    //print_r($result);
    $registrationIDs = 数组($result);

}

    $message = $_POST['message'];

    $字段 = 数组(
                'registration_ids' => $registrationIDs,
                '数据' => 数组(“消息” => $消息),
                );

结果:

"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"}]}

有什么问题?

4

1 回答 1

0

您在每次迭代中都覆盖了数组。您想将元素推送到 registrationIds 数组的末尾。就是这样:

$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 ),
            );
于 2013-08-13T00:06:04.483 回答