【问题标题】:How to remove FCM android push notification result如何删除 FCM android 推送通知结果
【发布时间】:2016-10-21 13:12:24
【问题描述】:

我得到了这个结果

 {
"multicast_id":4913280949692448120,
"success":1,
"failure":0,
"canonical_ids":0,
"results":[{"message_id":"0:1473389987003950%ab9a0bb6ab9a0bb6"}]
}

在 Android 设备上将采用 JSON 格式,所以我想通过 web 服务将其删除。

我们怎样才能删除那个结果?

【问题讨论】:

    标签: php android json web-services


    【解决方案1】:

    要删除结果,您必须添加此行

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    

    之后

    curl_setopt($ch, CURLOPT_POSTFIELDS,
        "{  \"to\" : \"" . $token
        . "\",\"priority\":10,\"notification\" : {\"body\" : \""
        . $message . "\",\"title\" : \"" . $title
        . "\",\"icon\" : \"myicon\"},\"data\" : " . json_encode($arr) . "}");
    

    curl_exe($ch);之前

    这将从您的响应中删除 fcm 多播结果。

    【讨论】:

      【解决方案2】:

      在你的代码中添加这一行

              $pushToken = 'Your device token';
              $title= 'Your Title';
              $message= 'Your Message';
              $serverKey= 'Your ServerKey';
              $ch = curl_init("https://fcm.googleapis.com/fcm/send");
              $notification = array('title' => $title, 'text' => $message, "message" => $message);
              $arrayToSend = array('to' => $pushToken, 'notification' => $notification, 'data' => $notification, 'priority' => 'high');
              $json = json_encode($arrayToSend);
              $headers = array();
              $headers[] = 'Content-Type: application/json';
              $headers[] = 'Authorization: key=' . $serverKey; // key here
              //Setup curl, add headers and post parameters.
              curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
              curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
              curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
              curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
              //Send the request
              $response = curl_exec($ch);
              //Close request
              curl_close($ch);
      

      【讨论】:

      • 虽然这段代码可以回答问题,但最好解释一下如何解决问题,并提供代码作为示例或参考。仅代码的答案可能会令人困惑且缺乏上下文。
      【解决方案3】:

      你不会在你的安卓手机上收到上述结果,它只是你通过发送推送通知得到的结果。 您传递的“数据”参数将是您将在 android 上收到的 JSON。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-01-17
        • 1970-01-01
        • 1970-01-01
        • 2017-12-22
        • 2018-07-11
        • 2022-09-28
        相关资源
        最近更新 更多