locked
[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);
            }
        }

    Saturday, May 2, 2015 3:42 PM

Answers