我试图通知推送发送到用户,但是没有办法完成的是,Android的通知将PHP错误
还有就是我在PHP中使用的代码
$message = new gcm();
$message->sendMessageToPhone(2, $message,$valor);
class gcm
{
function sendMessageToPhone($collapseKey, $messageText, $gcmcode)
{
$apiKey = 'there is my apikey';
$headers = array('Authorization:key=' . $apiKey);
$data = array( 'registration_id' => $gcmcode, 'collapse_key' => $collapseKey, 'data.message' => $messageText);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://android.googleapis.com/gcm/send");
if ($headers) curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (curl_errno($ch)) { return 'fail'; }
if ($httpCode != 200) { return 'status code 200'; }
curl_close($ch);
return $response;
}
和我得到这个错误,当我执行的PHP
开捕致命错误:类GCM的对象无法在/path/gcm.php在线25
第25行= curl_setopt($ CH转换为字符串,CURLOPT_POSTFIELDS,$ data);