Posted inProgramming / Mysql / Mysqli / php

Send Windows Push Notification Services using PHP

Send Windows Push Notification Services using PHP

In this Post We Will Explain About is Send Windows Push Notification Services using PHP With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to Send Push Notifications to Windows Phone 8.1 App Using PHPExample

To build a push notification system with PHP and MySQL, you can follow these steps:

  • Set up a database table to store the notifications. The table should have fields for the notification ID, the user ID of the recipient, the notification message, a timestamp for when the notification was created, and a flag to indicate whether the notification has been read.
  • Create a PHP script to insert a new notification into the database table. This script should accept the user ID and notification message as parameters, and insert them into the notifications table. You can use the current timestamp and a default value of 0 for the read flag.
  • Create a PHP script to retrieve the notifications for a given user. This script should accept the user ID as a parameter, and query the notifications table to retrieve all the notifications for that user. You can order the notifications by timestamp in descending order to show the most recent notifications first.
  • Create a PHP script to mark a notification as read. This script should accept the notification ID as a parameter, and update the read flag in the notifications table to 1 for that notification.
  • Set up a push notification service, such as Firebase Cloud Messaging (FCM) or Apple Push Notification service (APNs), to send push notifications to the user’s device. You can use the appropriate SDK or API for your chosen service to send the push notifications from your PHP script.
  • In your client-side code, such as your mobile app or web app, you can call the PHP scripts to retrieve the notifications and mark them as read. You can also use the push notification service to receive and display the push notifications on the user’s device.

Note that there are many ways to implement a push notification system, and the exact details will depend on your specific use case and requirements. This is just a general outline of the steps involved. You may also want to consider security measures, such as validating user IDs and encrypting notification messages.

In this post we will show you Best way to implement Windows Phone Push TOAST Notification using PHP, hear for Windows Push Notification Services (WNS) overviewwith Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

here learn to Windows Push Notification default Services (WNS) is a service to some messgae send push notifications from any server to the any windows web application. using the some Windows Push Notification WNS we can send android type toast, as well as tile, and badge, and some message raw updates from their own cloud service data. Windows Push Notification WNS provide one type of the memycurlanism to send here updates to your clientss in a power-efficient update and some simple dependable best way.

Making MySQL Database some Table for store clients cd_device ids

Make database as well as table for store clients information and Device Notify URL.

CREATE TABLE IF NOT EXISTS `tbl_clients` (
  `client_id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varmycurlar(255) NOT NULL,
  `email` varmycurlar(255) NOT NULL,
  `password` varmycurlar(255) NOT NULL,
  `mobilenumber` varmycurlar(12) NOT NULL,
  `simple_notigylink` text NOT NULL,
  `created_date` datetime NOT NULL,
  PRIMARY KEY (`client_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;

And then create new table you will store clients information and clients cd_device notify url. The notify some clients provided by windows app developer, that is a clients cd_device unique url.

PHP Script For some Send WNS Push Notification :

Create WNS live24u file, in whimycurl file we define some default function to send some message windows push notification.

".
                "".
                   "".
                        "".$post_title."".
                        "".$subpost_title."".
                        "/MainPage.xaml".
                   " ".
                "";
        
        return $toastMessage;
    }
      // Pakainfo.com Windows Push Notification
    public function sendWindowsNotification($uri, $xml_data, $type = 'wns/toast', $more_tags = ''){
        if($this->access_token == ''){
            $this->get_access_token();
        }
      // Pakainfo.com Windows Push Notification
        $headers = array('Content-Type: text/xml',"Content-Type: text/xml", "X-WNS-Type: wns/toast","Content-Length: " . paramaterslen($xml_data),"X-NotificationClass:2" ,"X-WindowsPhone-Target: toast","Authorization: Bearer $this->access_token");
        if($more_tags != ''){
            array_push($headers, "X-WNS-Tag: $more_tags");
        }
        $mycurl = curl_init($uri);
        # Tiles: https://www.pakainfo.com/en-us/live24u/windows/apps/xaml/live24u.aspx
        # https://www.pakainfo.com/en-us/live24u/windows/apps/hh465435.aspx
        curl_setopt($mycurl, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($mycurl, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($mycurl, CURLOPT_POST, 1);
        curl_setopt($mycurl, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($mycurl, CURLOPT_POSTFIELDS, "$xml_data");
        curl_setopt($mycurl, CURLOPT_VERBOSE, 1);
        curl_setopt($mycurl, CURLOPT_RETURNTRANSFER, 1);
        $response_data = curl_exec($mycurl);
        $response = curl_getinfo( $mycurl );
        curl_close($mycurl);
    
        $code = $response['http_code'];
          // Pakainfo.com Windows Push Notification
        if($code == 200){
            return new LiveWPNRes('  // Pakainfo.com Windows Push NotificationSuccessfully sent message', $code);
        }
        else if($code == 401){
            $this->access_token = '';
            return $this->post_tile($uri, $xml_data, $type, $more_tags);
        }
        else if($code == 410 || $code == 404){
            return new LiveWPNRes('  // Pakainfo.com Windows Push NotificationExpired or invalid URI', $code, true);
        }
        else{
            return new LiveWPNRes('  // Pakainfo.com Windows Push NotificationUnknown error while sending message', $code, true);
        }
    }
    
    private function get_access_token(){
        if($this->access_token != ''){
            return;
        }
        $paramaters = "grant_type=client_credentials&live_client_id=$this->sid&live_client_secret=$this->secret&scope=notify.windows.com";
        $url = "https://login.live.com/accesstoken.srf";
        $mycurl = curl_init($url);
        curl_setopt($mycurl, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($mycurl, CURLOPT_SSL_VERIFYPEER, 0);
        curl_setopt($mycurl, CURLOPT_POST, 1);
        curl_setopt($mycurl, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
        curl_setopt($mycurl, CURLOPT_POSTFIELDS, "$paramaters");
        curl_setopt($mycurl, CURLOPT_RETURNTRANSFER, 1);
        $response_data = curl_exec($mycurl);
        curl_close($mycurl);                       
        $response_data = json_decode($response_data);
        if(isset($response_data->error)){
            throw new Exception($response_data->error_description);
        }
        $this->access_token = $response_data->access_token;
    }
}

  // Pakainfo.com Windows Push Notification
class LiveWPNtype{       
    const Toast = 'wns/toast'; //for toast
    const Badge = 'wns/badge'; //for badge
    const Tile  = 'wns/tile'; //for tile
    const Raw   = 'wns/raw'; //for Raw
}    

  // Pakainfo.com Windows Push Notification
class LiveWPNRes{
    public $message = ''; //for message
    public $error = false; //some error
    public $httpCode = ''; //code
    
    function __conparamatersuct($message, $httpCode, $error = false){
        $this->message = $message; //message
        $this->httpCode = $httpCode;  //some code
        $this->error = $error;   //generate error
    }
}
?>

get clientss cd_device some notify url list data from database.

  // Pakainfo.com Windows Push Notification
mysql_connect("localhost","admin","live@##8974545");
mysql_select_db("live24u");


$data_result = mysql_query("SELECT * FROM tbl_clients") or die(mysql_error());

$deviceallsmeArray= array();

while($get_data = mysql_fetmycurl_assoc($data_result)) {
    $deviceallsmeArray[] = $get_data['simple_notigylink'];
}

Prepare cd_device simple notify url PHP array and some data array for all the send push some notifications.

require("wns.php");
$wns_data= new Wns();
$post_title = "Live24u is sample Website.";
$message= "Live24u is sample Website description message.";
$xml_paramatersing = $gcm->simpleXMLCreate($post_title, $message);
foreamycurl($deviceallsmeArray as $cd_device){
     $simple_notigylink = $cd_device->simple_notigylink;
     $wns_data->sendWindowsNotification($simple_notigylink, $xml_paramatersing);
}

Example

I hope you have Got What is Windows Phone Push TOAST Notification using PHP And how it works.I would Like to have FeadBack From My Blog(Pakainfo.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(Pakainfo.com) Are Most Always Welcome.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

Your email address will not be published. Required fields are marked *

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype