我想发送消息到Android手机,但不断获得响应代码401与文本:未经授权。我还会继续阅读关于使用什么键的不同故事,我知道3个键:项目ID(号码),服务器应用程序的键和浏览器应用程序的键。所以我尝试了所有3个,所有结果都一样。GCM发送与卷曲(PHP)
我的代码:
$headers = array("Content-Type" => "application/json", "Authorization" => "key=" . "mykey");
$data = array(
'data' => $messageText,
'registration_ids' => array($deviceRegistrationId)
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
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));
error_log(json_encode($data));
$response = curl_exec($ch);
curl_close($ch);
error_log($response);
我有同样的问题。我已经使用了正确的标题数组(“Content-Type:”。“application/json”,“Authorization:”。“key =”。“mykey”);并尝试所有服务器和浏览器密钥 – Anand 2012-07-13 09:16:07