Advertisement
Guest User

OneSignal Sender Function

a guest
Oct 14th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.86 KB | None | 0 0
  1. function sendMessage($app_id, $api_key, $message)
  2. {
  3.     $content = array("en" => $message);
  4.     $fields = array(
  5.         'app_id' => $app_id,
  6.         'included_segments' => array('All'),
  7.         'data' => array("foo" => "bar"),
  8.         'contents' => $content);
  9.  
  10.     $fields = json_encode($fields);
  11.     $ch = curl_init();
  12.     curl_setopt($ch, CURLOPT_URL, "https://onesignal.com/api/v1/notifications");
  13.     curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8', 'Authorization: Basic ' . $api_key));
  14.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  15.     curl_setopt($ch, CURLOPT_HEADER, false);
  16.     curl_setopt($ch, CURLOPT_POST, true);
  17.     curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
  18.     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  19.  
  20.     $response = curl_exec($ch);
  21.     curl_close($ch);
  22.  
  23.     return $response;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement