function wc_push_notification($title, $message, $token){
define( 'API_ACCESS_KEY', 'AIzaSyAWmIMxm6uCGOilk2TNCAAYXBVrDXT0k74'); //Server API KEY(usually you can find it by settings > project setting > cloudmessaging)
$msg = array('body' => $message,'title' => $title);
$fields = array('to' => $token,'notification' => $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 );
curl_close( $ch );
}
Usage:
wc_push_notification('Push Notification Title', 'Push Notification Body', 'DEVICE_TOKEN');