如何使用 php 代码在 Windows Phone 中一次发送磁贴和 Toast 推送通知


How to send tile and toast push notification at a time in windows phone using php code?

我正在为Windows Phone 8开发。我需要使用 PHP 一次发送 Toast 和磁贴推送通知。我可以成功接收 Toast 或磁贴通知,但我需要合并这些通知。谁能告诉我如何解决这个问题?

我的代码如下

<?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] : "";
 }
}

 ?>

我尝试了组合代码,但我遇到了一些时间xml有效负载错误

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