1
votes

I am developing for Windows Phone 8. I need to send toast and tile push notification at a time using PHP. I can receive toast or tile notification successfully but I need to combine these notifications. Can anyone tell me how to solve this issue?

My code is given below

<?php
     class WindowsPhonePushPriority
    {
      const TileImmediately = 1;

    }

    class WindowsPhonePushClient
  {
private $device_url = '';
private $debug_mode = false;

function __construct($device_url)
{
    $image_url = 'Images/purple.jpg';
    $this->device_url = $device_url;

}

 public function send_tile_update($message1, $title, $priority =    WindowsPhonePushPriority::TileImmediately)
{
   $title = 'push from Bestin Uk';
    $msg = "<?xml version=\"1.0\" encoding=\"utf-8\"?>".
           "<wp:Notification xmlns:wp=\"WPNotification\">".
              "<wp:Tile>".
              "<wp:BackgroundImage>".$imageURL."</wp:BackgroundImage>".
              "<wp:Count>".$message1."</wp:Count>".
              "<wp:Title>".$title."</wp:Title>".
              "<wp:Param>/Receive.xaml?NavigatedFrom=push</wp:Param>".
              "</wp:Tile>".
           "</wp:Notification>";

    return $this->_send_push(array('X-WindowsPhone-Target: token','X-NotificationClass: ' . $priority,), $msg);
}

private function _send_push($headers, $msg)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $this->device_url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HEADER, true); 
    curl_setopt($ch, CURLOPT_HTTPHEADER,    // Add these headers to all requests
        $headers + array(
                        'Content-Type: text/xml',
                        'Accept: application/*'
                        )
        ); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $msg);

    if ($this->debug_mode)
    {
        curl_setopt($ch, CURLOPT_VERBOSE, $this->debug_mode);
        curl_setopt($ch, CURLOPT_STDERR, fopen('debug.log','w'));
    }
    $output = curl_exec($ch);
    echo $output;
    curl_close($ch);

    return array(
        'X-SubscriptionStatus'     => $this->_get_header_value($output, 'X-SubscriptionStatus'),
        'X-NotificationStatus'     => $this->_get_header_value($output, 'X-NotificationStatus'),
        'X-DeviceConnectionStatus' => $this->_get_header_value($output, 'X-DeviceConnectionStatus')
        );
  }

 private function _get_header_value($content, $header)
 {
    return preg_match_all("/$header: (.*)/i", $content, $match) ? $match[1][0] : "";
 }
}


 ?>

I have tried combined code but I am getting some time xml payload error

1

1 Answers

0
votes

It is not possible to combine the toast and tile payloads into a single request.
You need to send two requests as each request requires custom header values which can't be combined or duplicated.