开发者社区> 问答> 正文

GCM PHP发送到设备的问题

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

怎么会这样?

展开
收起
小旋风柴进 2016-03-05 16:24:12 1962 0
1 条回答
写回答
取消 提交回答
  • 你在每个迭代中重写了数组。

    这样:

    $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 ),
                );
    2019-07-17 18:53:42
    赞同 展开评论 打赏
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
阿里云栖开发者沙龙PHP技术专场-深入浅出网络编程与swoole内核-吴镇宇 立即下载
PHP安全开发:从白帽角度做安全 立即下载
PHP 2017.北京 全球开发者大会——高可用的PHP 立即下载