我安装了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控制台有关吗?