我正在为Windows Phone 8开发。我需要使用PHP一次发送toast和tile push通知。我可以成功收到toast或tile通知,但我需要将这些通知组合在一起。有谁能告诉我如何解决这个问题?
我的代码如下:
<?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有效负载错误
答案 0 :(得分:0)
无法将toast和tile有效负载组合到单个请求中 您需要发送两个请求,因为每个请求都需要自定义标头值,这些标头值无法组合或重复。