【发布时间】:2021-03-25 18:46:33
【问题描述】:
我正在使用测试消息制作推送通知 API。 运行 API 后,将成功作为输出,但不是通知参数,而是仅获取 message_id。 {"multicast_id":1737172589085289593,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1608011476021426%dbb9b5fbf9fd7ecd"}]}
这是我的 API 的代码
define( 'API_ACCESS_KEY', 'AAAAPt6Fa78:AXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXENtL-BRLMt5-sdMnJpMy' );
if(isset($_POST['fcm_token']) && !empty($_POST['fcm_token'])) {
$registrationIds = array($_POST['fcm_token']);
}
else if(isset($_GET['fcm_token']) && !empty($_GET['fcm_token'])) {
$registrationIds = array($_GET['fcm_token']);
}
$headers = array('Authorization: key='.API_ACCESS_KEY, 'Content-Type: application/json');
$msg = array(
'message' => 'here is a message. message',
'title' => 'This is a title. title',
'subtitle' => 'This is a subtitle. subtitle',
'tickerText' => 'Ticker text here...Ticker text here...Ticker text here',
'vibrate' => 1,
'sound' => 1,
);
$fields = array('registration_ids'=>$registrationIds, 'data'=> $msg);
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send' );
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_IPRESOLVE, CURL_IPRESOLVE_V4 );
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $fields ) );
$result = curl_exec($ch );
curl_close( $ch );
echo $result;
【问题讨论】:
标签: php reactjs api rest firebase-cloud-messaging