程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> php-GCM PHP發送到設備

php-GCM PHP發送到設備

編輯:編程綜合問答
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"}]}

怎麼會這樣?

最佳回答:


你在每個迭代中重寫了數組。

這樣:

$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 ),
            );
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved