Answered by:
[W8.1]WNS notification - 404 Error
Question
-
I use php. push Notification
I am trying to push notifications to my windows app via WNS,
I get a 404 response everytime.
I have verified that the Channel URI is valid, because every time I launch the app, I get the channel URI and use that immediately for testing.
I tried Project->Store->Associate App With the Store everytime.
but I still receive 404 response everytime.
Windows Store App needs to send authentication is completed in windows Dev Center ?
But I just wanted to test success.
My Server PHP Code :
function Send() { $_WPN = new WPN("ms-app://s-1-15-2-xxxxxxxxxxxxxxxxxxxxxx", "Dx56rxxxxxxxxxxxxxxxxx"); $_build_tile_xml = $_WPN->build_tile_xml("test","ms-appx:///images/Img.png"); $_WPN->post_tile( "My_PC_channelUrl", null, 'wns/toast'); } public function build_tile_xml($title, $img){ return '<?xml version="1.0" encoding="utf-8"?>'. '<toast launch="additionalContextParameters">'. '<visual lang="en-US">'. '<binding template="ToastImageAndText01">'. '<text id="1">'.$title.'</text>'. '</binding>'. '</visual>'. '</toast>'; } public function post_tile($uri, $xml_data, $type = WPNTypesEnum::Toast, $tileTag = ''){ if($this->access_token == ''){ $this->get_access_token(); } $headers = array('Content-Type: text/xml', "Content-Length: " . strlen($xml_data), "X-WNS-Type: $type", "Authorization: Bearer $this->access_token"); if($tileTag != ''){ array_push($headers, "X-WNS-Tag: $tileTag"); } $ch = curl_init($uri); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml_data"); curl_setopt($ch, CURLOPT_VERBOSE, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($ch); $response = curl_getinfo( $ch ); curl_close($ch); $code = $response['http_code']; if($code == 200){ echo 'Successfully sent message'. "<br>"; return new WPNResponse('Successfully sent message', $code); } else if($code == 401){ echo '$code == 401' . "<br>"; $this->access_token = ''; return $this->post_tile($uri, $xml_data); } else if($code == 410 || $code == 404){ echo 'Expired or invalid URI ' . $code . "<br>"; return new WPNResponse('Expired or invalid URI ', $code, true); } else{ echo 'Unknown error while sending message ' . $code . "<br>"; return new WPNResponse('Unknown error while sending message', $code, true); } }- Edited by Kouun Saturday, May 2, 2015 3:44 PM
- Edited by Franklin ChenMicrosoft employee, Moderator Monday, May 4, 2015 7:44 AM Tagged Subject
Saturday, May 2, 2015 3:42 PM
Answers
-
Hi Kouun,
To authenticate your cloud service, WNS sends the server a response to the authentication request. The response includes an access token that your cloud server must save and use in any notifications it sends until that access token expires.
I saw that you have attached the required request parameters in header variable, I would suggest you checking the post request header, like Authorization information(access_token), I'm not familiar with PHP, but there must be a way to log the detailed post request content.
And I've found a similar thread about 404 error using PHP backend: https://social.msdn.microsoft.com/Forums/windowsapps/en-US/7d18568b-e787-4444-a09c-0b5aa370b9f0/push-notifications-returning-a-404-channel-not-found-error-c-app-php-back-end?forum=winappswithcsharp
The customer found that the Channel URI had some symbols to "break" the actual URI, you can also follow his answer to check if this is the same issue.
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- Proposed as answer by Franklin ChenMicrosoft employee, Moderator Tuesday, May 19, 2015 12:14 PM
- Marked as answer by Franklin ChenMicrosoft employee, Moderator Wednesday, May 20, 2015 12:44 PM
Monday, May 4, 2015 7:37 AMModerator