如何使用FCM发送图像

时间:2018-06-23 10:29:31

标签: php android firebase firebase-cloud-messaging

我没有进行android开发的经验,但是我仍然能够创建webview应用。现在,我希望发送通知(FCM),但部分成功,下面是我的代码。

<?php

define('API_ACCESS_KEY','i define key');
 $fcmUrl = 'https://fcm.googleapis.com/fcm/send';
 $token='user token';

     $notification = [
            'title' =>'My Title',
            'body' =>'the body',
            'image' =>'http://www.androiddeft.com/wp-content/uploads/2017/11/Shared-Preferences-in-Android.png',
        #'click_action' => 'MainActivity',
            'sound' => 'default'
        ];
        $extraNotificationData = ["message" => $notification,"moredata" =>'dd'];

        $fcmNotification = [
            //'registration_ids' => $tokenList, //multple token array
            'to'        => $token, //single token
            'notification' => $notification,
            'data' => $extraNotificationData
        ];

        $headers = [
            'Authorization: key=' . API_ACCESS_KEY,
            'Content-Type: application/json'
        ];


        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL,$fcmUrl);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fcmNotification));
        $result = curl_exec($ch);
        curl_close($ch);

        echo $result;

问题:

  
      
  1. 即使我通过了图像URL,图像也没有显示。   Evem尝试使用https图像,但没有运气。

  2.   
  3. 是否可以将一些变量传递给通知,并且当有人单击通知时,我可以访问这些变量。

  4.   

0 个答案:

没有答案