【发布时间】:2015-06-30 22:19:12
【问题描述】:
我正在尝试以 1000 个块发送批处理 GCM 消息。但是,以下代码返回错误
Array to string conversion in C:\xampp\htdocs\index.php on line 651
在线:echo updateDataGCM($db); 行动内:
case "sendGroupMessage":
if ($userId = authenticateUser($db, $username, $password, $gcmregid))
{
if (isset($_REQUEST['toGroupId']))
{ // instead of toUserName it's to a groupId
$toGroupName = $_REQUEST['toGroupName'];
$toGroupId = $_REQUEST['toGroupId'];
$message = $_REQUEST['messageText'];
$campaign = $_REQUEST['campaign_id'];
$location = $_REQUEST['location_id'];
// Query to get the users id's who are in the group but not the user sending the message
$sqlGroupMembers = "SELECT DISTINCT usersId from users_groups
WHERE usersId != '".$userId."' AND groupId = '".$toGroupId."'";
// Loop to create a copy of message for all users taht are part of that group
if($getGroupMembersId = $db->query($sqlGroupMembers))
{
while($rowGroupMembers = $db -> fetchObject($getGroupMembersId))
{
$sql22 = "INSERT INTO `group_messages`...";
error_log("$sql22", 3 , "error_log");
if ($db->query($sql22))
{
$out = SUCCESSFUL;
}
else
{
$out = FAILED;
}
}
}
// Send GCM to turn on devices:
echo updateDataGCM($db);
}
else
{
$out = FAILED;
}
}
else
{
$out = FAILED;
}
break;
updateDataGCM() 函数:
function updateDataGCM($db) {
// Get all the GCM regIDs for anyone with new, "unseen" data:
$sqlAllRegIds = 'select distinct gcm_registration_id
from users';
// Execute
if ($resultIds = $db->query($sqlAllRegIds))
{
$gcmRegIds = array();
$i = 0;
while($query_row = $db -> fetchObject($resultIds)) {
$i++;
$gcmRegIds[floor($i/1000)][] = $query_row;
}
$pushMessage = $_POST["syncNewData"];
$message = array("syncNewData" => $pushMessage);
$pushStatus = array();
foreach($gcmRegIds as $val) $pushStatus[] = sendPushNotificationToGCM($val, $message);
return $pushStatus;
}
}
我怎样才能让它正确发送 GCM 消息?
【问题讨论】:
-
这与批量执行gcm有关,而不是明确的php数组
-
这与 PHP 数组有关。正确阅读错误信息。
标签: php android google-cloud-messaging