我正在尝试使用在SO上找到的脚本,这是一个php
脚本,它使用Firebase
推送通知,在我的应用中,我试图将通知推送至我的Android设备不知道如何识别设备的ID /密钥,脚本如下:
$server_key=""; // get this from Firebase project settings->Cloud Messaging
$user_token=""; // Token generated from Android device after setting up firebase
$title="New Message";
$n_msg="The is a message";
$ndata = array('title'=>$title,'body'=>$n_msg);
$url = 'https://fcm.googleapis.com/fcm/send';
$fields = array();
$fields['data'] = $ndata;
$fields['to'] = $user_token;
$headers = array(
'Content-Type:application/json',
'Authorization:key='.$server_key
);
$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));
$result = curl_exec($ch);
if ($result === FALSE) {
die('FCM Send Error: ' . curl_error($ch));
}
curl_close($ch);
我正在尝试标识$user_token
,以便可以使用此脚本来实现自己的目的。