关于使用PHP的GCM的警告

关于使用PHP的GCM的警告,php,google-cloud-messaging,yii2,Php,Google Cloud Messaging,Yii2,我在php中使用GCM。一切都很好。但我得到的回应是 "Field \"data\" must be a JSON array: example\n" 我的GCM代码是 function sendNotification($registrationIdsArray, $messageData) { $data = array( 'data' => $messageData, 'registration_ids' =>

我在php中使用GCM。一切都很好。但我得到的回应是

"Field \"data\" must be a JSON array: example\n"
我的GCM代码是

function sendNotification($registrationIdsArray, $messageData) {
        $data = array(
            'data' => $messageData,
            'registration_ids' => $registrationIdsArray
        );
        var_dump($data);
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_HTTPHEADER, $this->header);
        curl_setopt($ch, CURLOPT_URL, "https://android.googleapis.com/gcm/send");
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
        $response = curl_exec($ch);
        curl_close($ch);
        return $response;
    }
我的$data对象是

{"data":"example","registration_ids":["apikey1", "apikey2"]}

这里缺少的GCM代码是什么。

您传递的数据应该是一个数组,而不是像这样的字符串

  $messageData =  array(
    'success' => 1,
    'title' => $data['title'],
    'desc' => $data['message']
  );

$messageData应该是一个数组而不是字符串我如何才能更改为数组?我已将$messageData更改为数组。但是现在我得到了“{\'multicast\'u id\”:8115817839537145784,\'success\':0,\'failure\':1,\'canonical\'u id\:0,\'results\':[{\'error\':\'mistchsenderid\'}}”检查这个链接是否有这个错误我已经解决了这个错误。但是我收到了无效的通知。我的$data对象是{“data”:{“title”:“testing”,“text”:“example”,“time”:“},“registration_id”:[“apikey1”]}