【问题标题】:Push Notification API output coming as message_id推送通知 API 输出作为 message_id
【发布时间】: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


    【解决方案1】:

    成功时,它将返回包含消息 ID 以及成功或失败的输出,如下所示。它不会返回通知参数。

    {
      "multicast_id":1737172589085289593,
      "success":1,
      "failure":0,
      "canonical_ids":0,
      "results":[{
         "message_id":"0:1608011476021426%dbb9b5fbf9fd7ecd"
      }]
    }
    

    【讨论】:

      【解决方案2】:

      唯一的问题与参数有关,将“数据”更改为“通知”,效果很好。

      【讨论】:

        猜你喜欢
        • 2019-04-01
        • 1970-01-01
        • 2018-04-17
        • 2019-01-25
        • 1970-01-01
        • 2014-07-27
        • 2019-08-22
        • 1970-01-01
        • 2016-03-12
        相关资源
        最近更新 更多