PHP 스크립트에서 Android 앱으로 푸시 알림을 보내기 위해 JSON 구조 아래에 있지만 그렇게 할 수 없습니다. POSTMAN을 사용 중이며 상태 코드 200이 표시되지만 알림이 수신되지 않습니다.
내가 따르는 JSON 구조 :
https://firebase.google.com/docs/cloud-messaging/concept-options
{
"message":{
"token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
"notification":{
"title":"Portugal vs. Denmark",
"body":"great match!"
}
}
}
PHP 스크립트
<?php
$API_KEY="AAAAoyz8W_Q:APA91bFIJxTqoBnQo218QIIXi7uCmHFRP604RTC......";
$url = "https://fcm.googleapis.com/fcm/send";
$headers = array(
'Authorization:key='.$API_KEY,
'Content-Type:application/json'
);
$token="2tJfPjKZQ6UTVG....";
$notify=array("message"=>
array('token' =>$token,
'notification'=>array('title'=>"Title",
'body'=>"Body")));
$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_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($notify));
$result = curl_exec($ch);
if ($result === FALSE) {
die('Curl failed: ' . curl_error($ch));
}else{
echo $ch;
}
curl_close ( $ch );
?>
실제로 아래 링크에 정의 된대로 미리 정의 된 매개 변수를 전달해야하므로 $ notifyArray 변수에 문제가있었습니다.
https://firebase.google.com/docs/cloud-messaging/http-server-ref
$notify=array('to'=>$token,'notification'=>
array('title'=>"Title",body'=>"Subtitle"));
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다