Advertisement
Guest User

method kirim notifikasi

a guest
Jan 23rd, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.43 KB | None | 0 0
  1. <?php
  2.  
  3.             $url = "https://fcm.googleapis.com/fcm/send";
  4.  
  5.             $headers = array(
  6.                 "Authorization : key=AAAAVowCLac:APA91bGdY5WrVjAbVfKpqoRmehjfV2wu8Zkd_rQI3kSbTtVELkWDX8kEsGbKnOpRMrF26kD8kHpwdJ781JdkWKL2_KqGt5hFdHYmfS_TJB0fc2YqW0bQy8CVPCTdPS8DqpJEpLlwUifv",
  7.                 "Content-Type : application/json",
  8.             );
  9.  
  10.             $post_data = array(
  11.                 'to' => "/topics/all",
  12.                 'notification' => array(
  13.                     'sound' => "default"
  14.                 ),
  15.                 'data' => [
  16.                     'stage' => "LOC"             // LOC => LOCAL, DEV => DEVELOPMENT, TES => TEST, REL => RELEASE
  17.                     'show' => "1"                // 0 => tidak ditampilkan, 1 => ditampilkan
  18.                     'title' => "judul",
  19.                     'body' => "isi",
  20.                     'id_skk' => "LOG001".
  21.                     'refresh' => ["1", "2"]      // 0 => TIDAK ADA REFRESH, 1 => REFRESH PENGAJUAN, 2 => REFRESH LAPORAN, 3 => REFRESH MUTASI
  22.  
  23.                 ],
  24.                 'priority' => "high"             // HIGH, NORMAL
  25.             );
  26.  
  27.             $ch = curl_init();
  28.             curl_setopt($ch, CURLOPT_URL, $url);
  29.             curl_setopt($ch, CURLOPT_POST, true);
  30.             curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  31.             curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  32.             curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  33.             curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post_data));
  34.             $result = curl_exec($ch);
  35.             curl_close($ch);
  36.            
  37.             return json_decode($result, true)['message_id'] ?? "tidak terkirim";
  38.  
  39. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement