push notification

Please take a look here
https://firebase.google.com/docs/cloud-messaging/js/client

and my github FREE source code push web notification demo
https://github.com/zidane168/WebPushDemo

0
3
Genie Wanted 100 points

                                    public function push($device_data, $message, $push_params) {
  $ch = curl_init();

  // Set POST variables
  $this->set_credential(true);
  $url = $this->server_feedback_url;

  $headers = array(
    'Connection: keep-alive',
    'Authorization: key=' . $this->server_key,
    'Content-Type: application/json'
  );

  $fields  = array();

  $failed_case = array();
  $succeed_case = array();

  try {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

    // device_data
    // Array
    // (
    // 	[0] => arrayfSiW2K4tzpY:APA91bGxwkrBAI2FR3Dt5iAMwfhxLeCdSz62HCzF_4xRT4dcWw61bQxUjV7T0JK4hSKYTP2wG--A_pWGAfXlxH9vO68rR_h0crChNnGR0vnDUkgpe2KzGNsZgICEuYX0xCs5KilX3RhJ
    // 	[1] => fSiW2K4tzpY:APA91bGxwkrBAI2FR3Dt5iAMwfhxLeCdSz62HCzF_4xRT4dcWw61bQxUjV7T0JK4hSKYTP2wG--A_pWGAfXlxH9vO68rR_h0crChNnGR0vnDUkgpe2KzGNsZgICEuYX0xCs5KilX3RhJ
    // )

    // $fields = array(
    // 	// 'to' => $device_data[0]['device_token'],
    // 	'registration_ids' => $device_data,	// $device_data[0]['device_token'],
    // 	'notification' 	=> array(
    // 		'body'		=> $message['notification']['body'],
    // 		'title'		=> $message['notification']['title'],
    // 	),
    // 	'priority' => 'high',
    // 	'data' => isset($push_params['custom_data']) ? $push_params['custom_data'] : '',

    //   );

    $fields = array(
      'registration_ids' => $device_data,		// array
      'notification' 	=> array(
        'body'		=> $message['notification']['body'],
        'title'		=> $message['notification']['title'],
      ),
      'priority' => 'high',
      'data' => isset($push_params['custom_data']) ? $push_params['custom_data'] : '',

    );

    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));

    $result = curl_exec($ch);

    // {"multicast_id":9114866147884203417,"success":1,"failure":3,"canonical_ids":0,
    //	"results":[{"message_id":"0:1576208394681875%cb43adbbcb43adbb"},{"error":"InvalidRegistration"},
    //				{"error":"NotRegistered"},{"error":"NotRegistered"}]}

    $temp = json_decode($result, true);
    if ($temp['failure'] == 0) {		// dont have fail case
      $succeed_case = $device_data;
      $failed_case = array();

    } else {		// exist fail case
      $index = 0;
      foreach ($temp['results'] as $value) {

        if (isset($value['error'])) {
          $failed_case[] = $device_data[$index];

        } else {
          $succeed_case[] = $device_data[$index];
        }

        $index = $index + 1;
      }
    }

    $pushed = array(
      'status' => true,
      'params' => array(
        'result'		=> $result,
        'succeed' 		=> $succeed_case,
        'failed' 		=> $failed_case,
      ),
    );
  } catch (Exception $e) {
    $pushed = array(
      'status' => false,
      'params' => array(),
      'error_messages' => $e->getMessage(),
    );

  } finally {
    curl_close($ch);	 // Close the connection to the server
  }

  return $pushed;
}

public function set_credential($sandbox = true) {
  if ($sandbox === true) {
    $this->server_key 				= Environment::read('push.server_key');
    $this->sender_id	 			= Environment::read('push.sender_id');
    $this->server_feedback_url 		= Environment::read('push.server_feedback_url');
  }
}

0
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
web push notifications subscription web browser push notifications use push notifications web browser notifications example Push Notifications push notification options how to send push notification in web ways to push notifications how to implement push notifications what can i do with push notifications create web push notifications push notification for web application in browser push notifications push notification in browser web push notification automatic how to implement automatic web push notifications web push notification services how to send push notifications from website can website send push notifications push notification library web push notifications how it works web notifications example push notifications to browser push notification code web push notification is free with pusher? The push notification how to create push notification for a website how to create push notification what is website push notification web browser push notification best web push notifications how to create a web push notification push notification send push notification to web browser websockets web push notifications web push notifications architecture adding push notifications to a web app push notification in web app best way to send push notifications from a web app best way to send push notifications in a web application push notification number Web push notifications own server web push notifications web application projects web push notifications web application software web send push notification web push notification integration website push notification web push notifications image push notification website how to add push notifications to website How to implement web push notifications web browser push notification tutorial pusher notification\ websites push notifications push notification provider push notification standard what is push notification how it works web push notifications for owa push notification code example what is push notification mean how to implement push notification web push notification options push notification from web app push notification ideias add notification web push notification gratis web push notification system pusher push-notifications-web example push-notifications-web example web-push notification action push notification for a web how to add push notifications to app adding push notifications to a web app example web push notification specific user web push notification show all notifications notification push message push notification browser tutorial push notification tutorial push notifications design push notification with Pushe how does push notifications work push notification in website push notification samples free web push notifications Push Notifications Request sites with web push notifications pushy push notification push notification tutorial web push notifications for web apps sending push notifications from website push notification tool for web push notifications browser understanding web push notification for websites web notifications push push notifications without app web push notification apps add push notifications on web app how to make push notifications push notification services can web app send push notifications push app notifications push notification was push notification on web push notification definition push notification for websites how to create a push notification can i push notifications push notification support push notification script web push notification setup in website notification push site web create a push notification web push notifications provider push notification latest web push notification support can i use push notifications plugin Web push notifications how to do push notifications on website push notification app push notification a[[ web push notifications not working push notifications on app push notification on the web web push notifications tutorial push notification with pusher is it possible to use push notification on a website browser push notifications push notification browser what is the meaning of push notifications web push notification api pushy for push notification web push vs web notification what is push notification? web push notifications supported browsers push notifications browser example push notifications browser webapp push notification web app push notification push notification web app push notification push notifications tutorial display a push notifications web app with push notifications how to push notification browser push notification how to send push notification from website how to implement push notification in web application push notification service web what is push notifications mean send push notifications from website PushOwl Web Push Notifications push notifications example explain push notification how to create web push notification notification push définition Web Push Notifications – Webpushr push notification design web push notifications browser support web push notifications support push notification web app Push Notification added web push notifications google web push notification google how to send web push notifications What is a push notification in an app web push notifications localhost web push notifications free web push notifications free call web push notifications design push notification service pushy push notifications send push notifications to web browser\ how to send push notification on web web push notification help push notification demo push notification on webpage instead browser push notification on website what does push notification mean web push notifications api add push notifications to website web push notifications full working what is push notifications how it works push notifications meaning what is a push notification push notifications into webpage push notification in web application notifications push web notifications push how web push notification works in web application how push notification works in web application push notification in applications web application push notifications how push notification works can a web app send push notifications web push notifications script web push notifications library web app push notifications how do push notifications work push notification example web push notifications appboy implement web push notifications appboy implemt pusher notifications web push notifications top notification simple web push notification push notification google push notifications for website how to develop push notifications create push notification push notification message custom web push notification push notification client send push notifications to web application add push notifications to web app pushy notification send web push notification push notification in web push notification meaning website push notifications local notification to push notification web push notifications call pushing notification in web app notification push push notifications web app pushr notifications push notification webapp notification push web what is web push notification how push notifications work push notification tool web push notifications chrome chrome push messaging what is the best way to implement push notifications in web browser based push notifications package push notification in other lamguages how notifications work in web application gainsight push notification app push notification for website how to send push notification in apns push notifications website send notification to chrome send me push notifications site avec notification push web notification example how to send push notification push alert notifications google chrome notifications development if we convert a website into an app can we still push notifications browser push notifications example push notifications from browser to browser push notification server can you send push notifications from a mobile site how to implement notification in web application web push notifications for beginners google push notifications chrome web notifications push noticication how to send push notification to web browser send notification to web page chrome push notifications server send chrome notifications reload a screen when fcm push hits if visible android store notifications temporarily in browser js store notification temparory in browser chrome notifications offline web push notification advatages onesignal web push notification example how to open url notification in chrome pushbullet push notification send notification from server to web browser web push notifications code push messaging browser support web push notification expiration pusher notification can we directly accept push notification request in web push notifications web what is a push message how browser show web push notification web push notification example website show a web push notification on browser html code web push notification simulate notification from a browser realtime notification navigator.onLine notification web push google chrome mobile push notifications can i send website push notification and android how to change web message to notification web broser push notification web push notifications what are push notifications browser notifications web app google chrome get notification settings javascript manully pen nativ device notification permisss pop up in web app Web Push certificates push notifications in browser push notification on browser javascript web push notification ads what is push notifications what is push notification Browser push notification html5 notifications example html5 push notifications example push nottifications push notification web sample html 5 web pushj google notifications api handle notifcations for websites web push notification example notification html5 example https://api.pushe.co/v2/messaging/notifications/ make a call to https://fcm.googleapis.com/fcm/send from inside wordpress web push notifications example push notifications push message to mobile push notification
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source