Send FCM messages from server side to android device

前端 未结 7 1541
情话喂你
情话喂你 2020-12-03 05:45

With the new update, FCM is now going to be used.

I tried the sample app from git and it\'s working all fine. I can send notifications from the console.

But

7条回答
  •  爱一瞬间的悲伤
    2020-12-03 06:08

    function send_fcm($tokens,$message)
              {
    
    	    $url = 'https://fcm.googleapis.com/fcm/send';
    	    $priority="high";
    	  
    	
    	    $fields = array(
    	         'registration_ids' =>$tokens,         
    	          'data' =>$message
    	           
    	        );
    
    	 
    		   $headers = array(
    		        'Authorization:key=your key',
    		        'Content-Type: application/json'
    		        );
    
    		   $ch = curl_init();
    		   curl_setopt($ch, CURLOPT_URL, $url);
    		   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_POSTFIELDS, json_encode($fields));
    		 echo  json_encode($fields);
    		   $result = curl_exec($ch);           
    		   curl_error($ch);
    		   if ($result === FALSE)
    		    {
    		       die('Curl failed: ' . curl_error($ch));
       		    }
                      curl_close($ch);
                      return $result;
                 }

    store device ids in token variable in an array format

提交回复
热议问题