FCM没有回复

时间:2017-09-23 20:57:59

标签: php android firebase push-notification firebase-cloud-messaging

我安装了Apache和PHP5的raspberryPI。我找到了FCM通知的代码:

<?php
define( 'API_ACCESS_KEY', 'MYAPIACCESSKEY' );

$messaggio = "Prova 1";
  $registrationIds="MYDEVICEID";

$body="There's something new!";
$title = "Touch here to open";
$registrationIds = (array)$registrationIds;


$msg = array
(
     "body" => $body,
     "title" => $title,
     "sound" => "default"
);

$data = array
(

     "Messaggio" => $messaggio,

);

$fields = array
(
    'registration_ids' => $registrationIds,
    'notification' => $msg,
    'data' => $data
);



$headers = array
(
    'Authorization: key='.API_ACCESS_KEY,
    'Content-Type: application/json'
);

$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send' );
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( $fields ) );
$result = curl_exec($ch );
curl_close( $ch );
echo $result;

?>

问题在于,从我的本地网络(具有动态IP地址)发送和接收消息,而从另一个位置(具有静态IP地址),我从FCM得到文字上没有响应(但具有200状态代码)。可能有一些IP配置与Firebase控制台有关吗?

1 个答案:

答案 0 :(得分:0)

您必须将IP添加到允许的IP,该IP可以向您的firebase推送应用程序服务发送请求。 console.cloud.google.com

You have to add the IP to the allowed IP that can send request to your firebase push application service. console.cloud.google.com