SHARE
TWEET

OneSignal Sender Function

a guest Oct 14th, 2019 99 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top