Skip to content

Instantly share code, notes, and snippets.

@psprokofiev
Created December 23, 2019 08:33
Show Gist options
  • Select an option

  • Save psprokofiev/1854e36fc8f40bc32bf20d17c477e501 to your computer and use it in GitHub Desktop.

Select an option

Save psprokofiev/1854e36fc8f40bc32bf20d17c477e501 to your computer and use it in GitHub Desktop.
$this->instance->request_body = [
'to' => $this->token->token,
'collapseKey' => $this->instance->topic,
'apns-collapse-id' => $this->instance->topic,
'Topic' => $this->instance->topic,
'collapse_key' => $this->instance->topic,
'time_to_live' => $this->instance->ttl ?: 3600,
'data' => [
'title' => $this->instance->notification['title'] ?? env('APP_NAME'),
'body' => $this->instance->notification['body'],
'url' => $this->instance->notification['action'] ?: '/',
],
'notification' => [
'title' => $this->instance->notification['title'] ?? env('APP_NAME'),
'body' => $this->instance->notification['body'],
'image' => $this->instance->icon ?: asset('assets/manifest/Icon-96.png'),
'sound' => 'notification',
],
'android' => [
'notification' => [
'sound' => 'notification',
],
],
];
try {
$curl = curl_init();
curl_setopt_array( $curl, [
CURLOPT_POST => true,
CURLOPT_URL => 'https://fcm.googleapis.com/fcm/send',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => json_encode( $this->instance->request_body ),
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_HTTPHEADER => [
'Content-Type:application/json',
sprintf( "Authorization:key=%s", env( 'FCM_API_KEY' ) ),
],
] );
$response = curl_exec( $curl );
}
catch (\Exception $e) {
report($e);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment