You need to save the token of the user device during user registration in the system. And when the administrator activates the user from the backend, you need to send a notification to the user using the FCM service on the device token.
If you have no idea about FCM, visit: https://firebase.google.com/docs/cloud-messaging/concept-options
Confirm sending notification code with PHP below.
function sendFCMPushnotification($arr) {
$device_token = $arr['device_token'];
$message = $arr['message'];
$url = 'https://fcm.googleapis.com/fcm/send';
$fields = array (
'registration_ids' => array (
$device_token
),
'data' => array (
"message" => $message,
"sound" => "default"
),
'notification' => array(
'body' => $message,
'title' => 'ProjectName',
)
);
$fields = json_encode ( $fields );
$headers = array (
'Authorization: key=' . "PUT_YOUR_FCM_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_POSTFIELDS, $fields );
$result = curl_exec ( $ch );
var_dump($result);
curl_close ( $ch );
}
$arr = [
'device_token' => "PLACE_YOUR_DEVICE_TOKEN",
'message' => 'PLACE_YOUR_MESSAGE',
];
sendFCMPushnotification($arr);
source
share