推送通知 API 输出为 message_id
Push Notification API output coming as message_id
我正在使用测试消息发送推送通知 API。
在 运行 API 之后,获得成功作为输出,而不是仅获得 message_id 的通知参数。
{"multicast_id":1737172589085289593,"成功":1,"失败":0,"canonical_ids":0,"结果":[{"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;
成功后,它将 return 输出包含消息 ID 以及成功或失败,如下所示。它不会 return 通知参数。
{
"multicast_id":1737172589085289593,
"success":1,
"failure":0,
"canonical_ids":0,
"results":[{
"message_id":"0:1608011476021426%dbb9b5fbf9fd7ecd"
}]
}
唯一的问题与参数有关,将 'data' 更改为 'notification' 并且效果很好。
我正在使用测试消息发送推送通知 API。 在 运行 API 之后,获得成功作为输出,而不是仅获得 message_id 的通知参数。 {"multicast_id":1737172589085289593,"成功":1,"失败":0,"canonical_ids":0,"结果":[{"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;
成功后,它将 return 输出包含消息 ID 以及成功或失败,如下所示。它不会 return 通知参数。
{
"multicast_id":1737172589085289593,
"success":1,
"failure":0,
"canonical_ids":0,
"results":[{
"message_id":"0:1608011476021426%dbb9b5fbf9fd7ecd"
}]
}
唯一的问题与参数有关,将 'data' 更改为 'notification' 并且效果很好。