I am trying to send TOAST (PUSH) notification to Windows Phone Application (8.1) from PHP application. Configuration for the notification is done right . Configuration is validated with (http://31daysofwindows8.com/push) and it works fine. However when I use following code, I get notification as a string "New Notification". This notification does not have header, default image as it should be .Also what we observed is when XML payload is commented and a simple string is send, the same notification is receieved. I doubt the XML payload what is send is not right. Please guide me
$tokenRequest = curl_init();
curl_setopt($tokenRequest, CURLOPT_URL, 'https://login.live.com/accesstoken.srf');
curl_setopt($tokenRequest, CURLOPT_HTTPHEADER, array(
'Content-Type: application/x-www-form-urlencoded'
));
//FIELDS
$fields = array(
'grant_type' => 'client_credentials',
'client_id' => 'our client id',
'client_secret' => 'our client secret',
'scope' => 'notify.windows.com'
);
$fields_string = "";
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
curl_setopt($tokenRequest, CURLOPT_RETURNTRANSFER, true);
curl_setopt($tokenRequest,CURLOPT_POST, count($fields));
curl_setopt($tokenRequest,CURLOPT_POSTFIELDS, $fields_string);
$output = json_decode(curl_exec($tokenRequest));
curl_close($tokenRequest);
echo "<br>";
echo "<br>";
$accessToken = $output->{'access_token'};
$sendPush = curl_init();
curl_setopt($sendPush, CURLOPT_URL, 'our URI here');
//TOAST MESSAGE
$toastMessage = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" .
"<wp:Notification xmlns:wp=\"WPNotification\">" .
"<wp:Toast>" .
"<wp:Text1>Text...</wp:Text1>" .
"<wp:Text2>text..</wp:Text2>" .
"</wp:Toast>" .
"</wp:Notification>";
curl_setopt($sendPush, CURLOPT_HEADER, true);
echo $toastMessage;
$headers = array('Content-Type: text/xml',,"Content-Type: text/xml", "X-WNS-Type: wns/toast","Content-Length: " . strlen($toastMessage),"X-NotificationClass:2" ,"X-WindowsPhone-Target: toast","Authorization: Bearer $accessToken");
curl_setopt($sendPush, CURLOPT_HTTPHEADER, $headers);
curl_setopt($sendPush, CURLOPT_RETURNTRANSFER, true);
curl_setopt($sendPush,CURLOPT_POST, true);
curl_setopt($sendPush, CURLOPT_POSTFIELDS, $toastMessage));
$output = curl_exec($sendPush);
$info = curl_getinfo($sendPush);
echo($info['request_header']);
echo "<br>";
//var_dump(curl_getinfo($sendPush, CURLINFO_HTTP_CODE));
echo "<br>";
//var_dump(curl_getinfo($sendPush, CURLINFO_HEADER_OUT));
echo "<br>";
curl_close($sendPush);
The resultant XML payload is as following
<?xml version=\"1.0\" encoding=\"utf-8\"?>
<wp:Notification
xmlns:wp=\"WPNotification\">
<wp:Toast>
<wp:Text1>Sharvin</wp:Text1>
<wp:Text2>Notif</wp:Text2>
</wp:Toast>
</wp:Notification>"