【问题标题】:1000 User GCM: Array to String Conversion Error1000 用户 GCM:数组到字符串转换错误
【发布时间】: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 消息?

【问题讨论】:

标签: php android google-cloud-messaging


【解决方案1】:

您的代码中没有任何内容表明 GCM 未正确发送;所以我们无法为您提供帮助。

但是,这表明您正在尝试回显updateDataGCM 函数的返回值,即数组$pushStatus;,您使用return $pushStatus; 从该函数返回该数组。

为了知道您正在使用什么,您应该使用gettype($var),并且至少始终使用var_dump($var);

旁注

您应该有一个read about Making the most of Google Cloud Messaging。诸如速率限制和质量控制之类的东西可能会妨碍您发送 1000 个 GCM 的能力(这本身并没有任何意义。)

【讨论】:

    猜你喜欢
    • 2015-02-26
    • 2012-07-15
    • 2017-12-02
    • 2013-06-23
    • 2013-08-24
    • 1970-01-01
    • 1970-01-01
    • 2019-05-01
    相关资源
    最近更新 更多