Thursday, October 15, 2020

Curl Notification send Using Php Firebase

 <?php

/* New Server Php */



$token = 'user tken';


  define( 'API_ACCESS_KEY', 'key' );

$registrationIds = array($token);


$msg = array

(

'messages' => 'Order Id',

'title'         => 'Got a new Order',

'subtitle' =>  'Order Id ',

'tickerText' => 4545,

'vibrate' => '2',

'sound' => 1,

'largeIcon' => 'large_icon',

'smallIcon' => 'small_icon'

);

$fields = array

(

'registration_ids' => $registrationIds,

'data' => $msg

);


$headers = array

(

'Authorization: key=' . API_ACCESS_KEY,

'Content-Type: application/json'

);


$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_VERIFYPEER, false );

curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );

$result = curl_exec($ch );

echo $result

curl_close( $ch );


?>



<?php

 /*Old Server php */

define( 'API_ACCESS_KEY', 'xxxxx' );


$singleID = 'user tken' ; 

$registrationIDs = array( 'user tken',     'user tken',     'user tken'

) ;


$fcmMsg = array(

'body' => 'here is a message. message',

'title' => 'This is title #1',

'sound' => "jingle_bell.mp3",

     'content_available' => true, 

     'priority' => 'high', 

);


$fcmFields = array(

'to' => $singleID,

    'sound' => 'jingle_bell.mp3',

    'priority' => 'high',

'notification' => $fcmMsg

);


$headers = array(

'Authorization: key=' . API_ACCESS_KEY,

'Content-Type: application/json'

);

 

$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_VERIFYPEER, false );

curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fcmFields ) );

$result = curl_exec($ch );

curl_close( $ch );

echo $result . "\n\n";

?>

No comments:

Post a Comment