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 Live24u.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

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.

Also Read :   Vue js Simple CKEditor Instance Get textarea value

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.





<?php

class Wns {
        // live24u.com Windows Push Notification
    public function simpleXMLCreate($post_title, $subpost_title){
        $toastMessage = "<?xml version=\"1.0\" encoding=\"utf-8\"?>".
                "<wp:Notification xmlns:wp=\"WPNotification\">".
                   "<wp:Toast>".
                        "<wp:Text1>".$post_title."</wp:Text1>".
                        "<wp:Text2>".$subpost_title."</wp:Text2>".
                        "<wp:Param>/MainPage.xaml</wp:Param>".
                   "</wp:Toast> ".
                "</wp:Notification>";
        
        return $toastMessage;
    }
      // live24u.com Windows Push Notification
    public function sendWindowsNotification($uri, $xml_data, $type = 'wns/toast', $more_tags = ''){
        if($this->access_token == ''){
            $this->get_access_token();
        }
      // live24u.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: http://live24u.com/en-us/live24u/windows/apps/xaml/live24u.aspx
        # http://live24u.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'];
          // live24u.com Windows Push Notification
        if($code == 200){
            return new LiveWPNRes('  // live24u.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('  // live24u.com Windows Push NotificationExpired or invalid URI', $code, true);
        }
        else{
            return new LiveWPNRes('  // live24u.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;
    }
}

  // live24u.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
}    

  // live24u.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
    }
}
?>

Also Read :   Deleting mySQL Table Row with jQuery Ajax

get clientss cd_device some notify url list data from database.

  // live24u.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(live24u.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(live24u.com) Are Most Always Welcome.