我正在使用服务工作者处理网络推送通知。但是我在使用FCM(Firebase云消息传递)从服务器发送通知时遇到了麻烦。这是我的PHP脚本,我没有得到如何在服务工作者中调用它。请指导我。
define( 'API_ACCESS_KEY', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
$msg = array(
'message' => 'Wakeup Wakeup!!',
'title' => 'Wakeup call !',
);
$fields = array(
'registration_id' => xxxxxxxxxx,
'data' => $msg
);
$headers = array
(
'Authorization: key=' . API_ACCESS_KEY,
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, '//gcm-http.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;