-1
MySql PHP 서버와 Firebase를 사용하여 Android 장치에서 알림을 보내려고했습니다. Firebase 토큰은 내 DB에서 성공적으로 검색되지만 PHP에서 모든 장치에 알림을 보내려고하면 내 db에 저장된 첫 번째 장치로 보내집니다.PHP에서 가져온 푸시 알림 PHP MySQL 서버가 다중 장치에서 작동하지 않습니다.
저는 PHP 코드를 게시하고 있습니다. 조금 분석했지만 코드는 하나의 firebase 토큰에 대해 수행되었습니다.
function sendPushNotification() {
require "init.php";
$message="Notification Details";
$title="Notification Title";
$url='https://fcm.googleapis.com/fcm/send';
$server_key="MY_FIREBASE_KEY";
$sql="select fcm_token from fcm_info";
$result=mysqli_query($con,$sql);
$row=mysqli_fetch_row($result);
$key=$row[0];
$headers=array(
'Authorization:key ='.$server_key,
'Content-Type: application/json'
);
$fields=array('to'=>$key,'notification'=>
array('title'=>$title,'body'=>$message));
$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));
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
$result = curl_exec($ch);
curl_close($curl_session);
mysqli_close($con);}
나중에 나는 조금 변경 DB의 모든 토큰을 쿼리하고 ASSOC 배열을하고 다음 키와 그 배열을 전달했습니다. 이 경우 통지를 보내고 저에게 @Selvin 말했듯이, 나는
registration_ids
대신
to
를 사용하여 내 문제를 해결
"to" must be json
json이'https : // fcm.googleapis.com/fcm/send'에 어떻게 보내야하는지에 대한 문서가 있다는 것을 알고 있습니까? ... 'to'는 하나의 메시지를위한 것입니다 (어려운 단어 앞에 ** loop **) ... 여러 메시지를 동시에 보내야 할 경우 - 문서를 읽으십시오 (' registration_ids') – Selvin
위의 코드는 쿼리 결과에서 하나의 레코드를 가져옵니다. 모든 사용자에게 알림을 보내려는 경우 결과를 반복하십시오. – Shadow
oyur 시나리오에 대해 자세히 설명해 주시겠습니까? 모든 기기에 동일한 메시지 알림을 보내려고하십니까? 그렇다면 왜 Topic Messaging을 사용하지 않는 것이 좋습니까? –