1

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

4

1 回答 1

0

无法将 toast 和 tile 有效负载组合到单个请求中。
您需要发送两个请求,因为每个请求都需要无法组合或复制的自定义标头值。

于 2013-10-03T09:58:41.557 回答