Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $serverKey = 'Chave da sua api Firebase';
- $msg_notificacao = "Mensagem da notificacao";
- $pushUrl = "https://fcm.googleapis.com/fcm/send";
- $key = $serverKey;
- $headers = [];
- $headers[] = 'Content-Type: application/json';
- $headers[] = 'Authorization:key=' . $key;
- $data = array(
- 'registration_ids' => //'Aqui vai um array com os tokens fcm dos usuarios que irao receber essa notificacao',
- "notification" => array(
- "title" => "Titulo da sua notificacao",
- "body" => $msg_notificacao,
- "click_action" =>"FCM_PLUGIN_ACTIVITY",
- "icon" => "fcm_push_icon",
- "priority" => "high",
- "show_in_foreground" => true,
- "targetScreen" => 'detail'
- ),
- "data" => array(
- "notification" => array(
- "title" => "Titulo da sua notificacao",
- "body" => $msg_notificacao,
- "click_action" =>"FCM_PLUGIN_ACTIVITY",
- "icon" => "fcm_push_icon",
- "priority" => "high",
- "show_in_foreground" => true,
- "targetScreen" => 'detail',
- //dados de seu backend que queira mandar para o ionic esses 3 abaixos
- "dia" => "Convite para um jogo",
- "email_cancelou" => 'blablabla',
- "aviso" => "sim",
- )
- ),
- "priority" => 10,
- );
- $json_data = json_encode($data);
- $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_data);
- $res = curl_exec($ch);
- curl_close($ch);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement