/var/www/vhosts/nabawater/common/helpers
NameSizeModeActions
AccessRules.php120510644editdlrm
AuthHandler.php75560644editdlrm
Aws.php57620644editdlrm
ChunkHelper.php9590644editdlrm
Com.php224100644editdlrm
DateTimeHelper.php71550644editdlrm
FBHelper.php41120644editdlrm
FileUploadHelper.php43510644editdlrm
GeoHelper.php125350644editdlrm
GeoMetricHelper.php55140644editdlrm
IPay88Helper.php46420644editdlrm
JwtHelper.php36730644editdlrm
Mailer.php45350644editdlrm
MailerQueueHelper.php31710644editdlrm
ModelHelper.php25530644editdlrm
OneSignal.php73770644editdlrm
PaymentHelper.php57840644editdlrm
QrHelper.php24560644editdlrm
RabbitMQHelper.php24060644editdlrm
SmsGateway.php18620644editdlrm
StripeHelper.php33350644editdlrm
UploadHelper.php161640644editdlrm
Edit: /var/www/vhosts/nabawater/common/helpers/OneSignal.php (7377B)
*/ class OneSignal { /** * One signal API URL */ const URL = 'https://onesignal.com/api/v1/notifications'; /** * @var static */ private static $instance; /** * @var string */ private $appId; /** * @var string */ private $restApiKey; /** * @var string */ private $notify_icon = ''; /** * OneSignal constructor. */ public function __construct() { $this->setAppId(Configuration::get(Configuration::PUSH_NOTIFICATION_APP_ID)); $this->setRestApiKey(Configuration::get(Configuration::PUSH_NOTIFICATION_REST_API_KEY)); } /** * @return static */ public static function getInstance() { if (self::$instance === null) { self::$instance = new self(); } return self::$instance; } /** * @param mixed $restApiKey */ public function setRestApiKey($restApiKey) { $this->restApiKey = $restApiKey; } /** * @param string $appId */ public function setAppId($appId) { $this->appId = $appId; } /** * @param $icon * @return $this */ public function setIcon($icon) { $this->notify_icon = $icon; return $this; } /** * @param array $title * @param array $message * @param array $clientIds * @param array $data * @return mixed * @throws \yii\base\InvalidParamException */ public function push(array $title, array $message, array $clientIds, array $data) { $fields = [ 'app_id' => $this->appId, 'contents' => $message, 'headings' => $title, 'large_icon' => $this->notify_icon, 'small_icon' => $this->notify_icon, ]; if (Configuration::get(Configuration::PUSH_NOTIFICATION_CHANNEL_ID) != '') { $fields['android_channel_id'] = Configuration::get(Configuration::PUSH_NOTIFICATION_CHANNEL_ID); $fields['ios_sound'] = 'notification.wav'; $fields['android_sound'] = 'notification'; } if ($data !== []) { $fields['data'] = $data; } if ($clientIds === []) { $fields['included_segments'] = 'All Users'; } else { $fields['include_player_ids'] = $clientIds; } $fields = Json::encode($fields); $headers = [ 'Content-Type: application/json; charset=utf-8', sprintf('Authorization: Basic %s', $this->restApiKey) ]; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, static::URL); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 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; } public function vendorpush(array $title, array $message, array $clientIds, array $data) { $fields = [ 'app_id' => $this->appId, 'contents' => $message, 'headings' => $title, 'large_icon' => $this->notify_icon, 'small_icon' => $this->notify_icon, ]; if (Configuration::get(Configuration::VENDOR_PUSH_NOTIFICATION_CHANNEL_ID) != '') { $fields['android_channel_id'] = Configuration::get(Configuration::VENDOR_NOTIFICATION_CHANNEL_ID); $fields['ios_sound'] = 'notification.wav'; $fields['android_sound'] = 'notification'; } if ($data !== []) { $fields['data'] = $data; } if ($clientIds === []) { $fields['included_segments'] = 'All Users'; } else { $fields['include_player_ids'] = $clientIds; } $fields = Json::encode($fields); $headers = [ 'Content-Type: application/json; charset=utf-8', sprintf('Authorization: Basic %s', $this->restApiKey) ]; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, static::URL); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 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; } public function sendCustomerNotification(array $title, array $message, $device_type = 3, $user_type = '') { $isIos = True; $isAndroid = True; if ($device_type == 1) { $isIos = False; } if ($device_type == 2) { $isAndroid = False; } $fields = [ 'app_id' => $this->appId, 'contents' => $message, 'headings' => $title, ]; // Add icon if set if (!empty($this->notify_icon)) { $fields['large_icon'] = $this->notify_icon; $fields['small_icon'] = $this->notify_icon; } if (Configuration::get(Configuration::PUSH_NOTIFICATION_CHANNEL_ID) != '') { $fields['android_channel_id'] = Configuration::get(Configuration::PUSH_NOTIFICATION_CHANNEL_ID); $fields['ios_sound'] = 'notification.wav'; $fields['android_sound'] = 'notification'; } // Filter by device type if ($device_type == 1) { // Android only $fields['filters'] = [['field' => 'device_type', 'value' => 1]]; } elseif ($device_type == 2) { // iOS only $fields['filters'] = [['field' => 'device_type', 'value' => 0]]; } $fields['included_segments'] = ['All']; $headers = [ 'Content-Type: application/json; charset=utf-8', sprintf('Authorization: Basic %s', $this->restApiKey) ]; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, static::URL); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, Json::encode($fields)); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); $response = curl_exec($ch); $curlError = curl_error($ch); curl_close($ch); // Log only errors if ($curlError) { $this->log('cURL Error: ' . $curlError); } return $response; } /** * @param $msg * @throws \yii\base\InvalidParamException */ private function log($msg) { Com::log($msg, 'one-signal'); } }