带有PHP未授权错误401的GCM
我正在使用GCM服务从服务器推送信息。 我试着喜欢这个样品。 我把一切都安排好了 1-我启用GCM服务 2-I获取API密钥带有PHP未授权错误401的GCM,php,android,Php,Android,我正在使用GCM服务从服务器推送信息。 我试着喜欢这个样品。 我把一切都安排好了 1-我启用GCM服务 2-I获取API密钥 单击“创建新密钥” 单击服务器密钥。(我的IP不是静态IP,我使用我的服务器IP) 还有我的PHP代码 function sendPushNotificationToGCM($registatoin_ids, $message) { //Google cloud messaging GCM-API url $url = 'https://
function sendPushNotificationToGCM($registatoin_ids, $message) {
//Google cloud messaging GCM-API url
$url = 'https://android.googleapis.com/gcm/send';
$fields = array(
'registration_ids' => $registatoin_ids,
'data' => $message,
);
// Google Cloud Messaging GCM API Key
define("GOOGLE_API_KEY", "my-api-key");
$headers = array(
'Authorization: key=' . GOOGLE_API_KEY,
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
if ($result == FALSE) {
die('Curl failed: ' . curl_error($ch));
}
curl_close($ch);
return $result;
}
<html>
<head>
<title>Google Cloud Messaging (GCM) Server in PHP</title>
</head>
<body>
<h1>Google Cloud Messaging (GCM) Server in PHP</h1>
<form method="post" action="index.php/?push=1">
<div>
<textarea rows="2" name="message" cols="23" placeholder="Message to transmit via GCM"></textarea>
</div>
<div><input type="submit" value="Send Push Notification via GCM" /></div>
</form>
<p><h3><?php echo $pushStatus; ?></h3></p>
</body>
</html>
函数sendPushNotificationToGCM($registatoin\u id,$message){
//谷歌云消息GCM-API url
$url='1https://android.googleapis.com/gcm/send';
$fields=数组(
“注册ID”=>$RegistratoIn\u ID,
“数据”=>$message,
);
//谷歌云消息GCM API密钥
定义(“谷歌API密钥”、“我的API密钥”);
$headers=数组(
“Authorization:key=”。GOOGLE_API_key,
'内容类型:应用程序/json'
);
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$URL);
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,0);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch,CURLOPT_POSTFIELDS,json_encode($fields));
$result=curl\u exec($ch);
如果($result==FALSE){
模具('Curl失败:'。Curl_错误($ch));
}
卷曲关闭($ch);
返回$result;
}
PHP中的Google云消息传递(GCM)服务器
PHP中的Google云消息传递(GCM)服务器
我得到了未经授权的错误401。
请帮忙。
多谢各位
我的英语有点弱。
非常抱歉