Вы должны добавить этот код в сторону php:
function sendFCM($notif_array, $id) {
$API_KEY = "api_key";
$url = 'https://fcm.googleapis.com/fcm/send';
$message = [
'body' => 'Hello, This is a notification.',
'title' => 'Your Title',
'notification_type' => 'Test'
];
$notification = [
'body' => 'Hello, This is a notification.',
'title' => 'Your Title',
];
$fields = array (
'registration_ids' => array (
$id
),
'notification' => $notification,
'data' => $message,
'priority' => 'high',
);
$fields = json_encode ( $fields );
$headers = array (
'Authorization: key=' . $API_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 );
curl_close ( $ch );
return 'success';
}
Для IOS:
function iospush( $id ) {
$msg = 'Test notification';
$host = 'gateway.push.apple.com'; /Here is ecample */
$passphrase = YourIOSpassphrase;
$ios_notifiaction_certificate = '/add full path where ios certiticate stay';
try {
$streamContext = stream_context_create();
stream_context_set_option( $streamContext, 'ssl', 'local_cert', $ios_notifiaction_certificate );
stream_context_set_option( $streamContext, 'ssl', 'passphrase', $passphrase);
$apns = stream_socket_client( 'ssl://'.$host, $error, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $streamContext );
$payload[ 'aps' ] = array( 'alert' => $msg, 'badge' => '0', 'sound' => 'default', 'notification_type' => 'Test' );
$payload = json_encode( $payload );
$apnsMessage = chr(0) . pack( 'n', 32 ) . pack( 'H*', $id ) . pack( 'n', strlen( $payload ) ) . $payload;
$fwriteRes = fwrite( $apns, $apnsMessage, strlen( $apnsMessage ) );
fclose( $apns );
return 'Success';
} catch( Exception $e ) {
return true;
// return $e->getMessage();
}
}