설정 Google 개발자 콘솔 Google Cloud Messaging for Android.GCM 서버 측 PHP - 무단 401 오류
신임장에서는 참조에 0.0.0.0을 입력하는 브라우저 API 키를 작성합니다. 사실 나는 다른 튜토리얼에서 다른 표시를 발견했기 때문에 두 종류의 키를 생성합니다. 두 키 (
나는<?
/**
* The following function will send a GCM notification using curl.
*
* @param $apiKey [string] The Browser API key string for your GCM account
* @param $registrationIdsArray [array] An array of registration ids to send this notification to
* @param $messageData [array] An named array of data to send as the notification payload
*/
function sendNotification($apiKey, $registrationIdsArray, $messageData)
{
$headers = array("Content-Type:" . "application/json", "Authorization:" . "key=" . $apiKey);
$data = array(
'data' => $messageData,
'registration_ids' => $registrationIdsArray
);
$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));
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
?>
<?
// Message to send
$message = "the test message";
$tickerText = "ticker text message";
$contentTitle = "content title";
$contentText = "content body";
$registrationId = '372CBFD0C4BFE728';
$apiKey = "AIzaSyDeNN1XJBFGE_lJ_35VMUmx5cUbRCUGkjo";
$response = sendNotification(
$apiKey,
array($registrationId),
array('message' => $message, 'tickerText' => $tickerText, 'contentTitle' => $contentTitle, "contentText" => $contentText));
echo $response;
?>
내가 그
{"multicast_id":6782339717028231855,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}
뭔가를 얻을 것으로 예상이 PHP 스크립트를 사용하여 키를 테스트하지만 취득) Unauthori zed 401 오류.
도움 주셔서 감사합니다.
나를 가리켜 주셔서 감사합니다. curl_setopt ($ ch, CURLOPT_SSL_VERIFYHOST, 0); 이 권한이 없으면 401 오류 – HiB