【发布时间】:2017-11-07 02:05:39
【问题描述】:
我正在构建一个用于在 youtube 频道上上传视频的 api。其中一项要求是,每当视频成功上传到 youtube 服务器时,都必须使用 Firebase Cloud Messaging 向 ios app bundle id 发送通知。 我已经在 fcm 控制台中使用 bundle id com.tbox.ygtp 注册了我的应用程序 我曾尝试用谷歌搜索如何向 ios 应用程序发送通知,我发现以下 API
$url = 'https://fcm.googleapis.com/fcm/send';
$server_key = 'AAAAylThdyA:APA91bGISSU********VTqHJqBnV81B3jfJzAice07E********HHLXTVylMU1OWSHvdyoZMVNlM8t9p9tXH_4OKm********fEOatp_alw9qMlQNT507lLWLt1N_FMHel1JCCWcuQjD';
$fields = array();
//$fields['data'] = $data;
$fields['notification'] = array('body'=>$data);
if(is_array($target)){
$fields['registration_ids'] = $target;
}else{
$fields['to'] = $target;
}
//header with content_type and api key
$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);
return $result;
此 Api 向设备令牌发送通知。但我需要在应用程序包 ID 上发送通知。 有人可以指导我如何使用 FCM 将通知发送到应用程序包 ID。
【问题讨论】:
标签: javascript php firebase firebase-cloud-messaging