Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace common\components;
- class OneSignal
- {
- const APP_API = '';
- const REST_KEY = '';
- /**
- * Отправка push пользователю
- * @param string $pushId
- * @param string $content
- * @param string $title
- * @param mixed $data дополнительные данные
- * @return mixed
- */
- public static function sendMessage($pushId, $content, $title= '', $data = [])
- {
- $content = [
- "en" => $content,
- 'ru' => $content
- ];
- $fields = [
- 'app_id' => self::APP_API,
- 'data' => $data,
- 'contents' => $content,
- 'headings' => [
- "en" => $title,
- 'ru' => $title
- ],
- 'include_player_ids' => [$pushId],
- ];
- $fields = json_encode($fields);
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, "https://onesignal.com/api/v1/notifications");
- curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json',
- 'Authorization: Basic ' . self::REST_KEY));
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
- curl_setopt($ch, CURLOPT_HEADER, FALSE);
- curl_setopt($ch, CURLOPT_POST, TRUE);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- $response = curl_exec($ch);
- curl_close($ch);
- return $response;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement