1

我需要在 windows phone 中设置推送通知接收消息目标页面。我可以发送和接收 toast 推送通知,但是当我单击收到的 toast 消息时,它会转到主页。当我单击 toast 消息时,我需要在目标页面中打开该应用程序。请让我知道为什么我会遇到这个问题以及我的代码有什么问题。

我的代码如下:

C#接收目标页面:

 void PushChannel_ShellToastNotificationReceived(object sender, NotificationEventArgs e)
    {
        StringBuilder message = new StringBuilder();
        string relativeUri = string.Empty;

        message.AppendFormat("Received Toast {0}:\n", DateTime.Now.ToShortTimeString());

        // Parse out the information that was part of the message.
        foreach (string key in e.Collection.Keys)
        {
            message.AppendFormat("{0}: {1}\n", key, e.Collection[key]);

            if (string.Compare(
                key,
                "wp:Param",
                System.Globalization.CultureInfo.InvariantCulture,
                System.Globalization.CompareOptions.IgnoreCase) == 0)
            {
                relativeUri = e.Collection[key];

            }
        }

        // Display a dialog of all the fields in the toast.
        Dispatcher.BeginInvoke(() => MessageBox.Show(message.ToString()));

    }
    protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
    {
        base.OnNavigatedTo(e);

        //  If we navigated to this page
        // from the MainPage, the DefaultTitle parameter will be "FromMain".  If we navigated here
        // when the secondary Tile was tapped, the parameter will be "FromTile".
        textBlockFrom.Text = "Navigated here from " + this.NavigationContext.QueryString["NavigatedFrom"];

    }

我正在使用 PHP 代码发送推送通知:

  <?php 
  final class WindowsPhonePushDelay
  {

   const Immediate=0;

   private function __construct(){}
 }

 class WindowsPhonePushNotification
 {
  private $notif_url = '';

  function WindowsPhonePushNotification($notif_url)
  {
     $this->notif_url = $notif_url;
  }
  public function push($target,$message,$notif_url)
  {

   // Create the toast message
   $toastMessage = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" .
            "<wp:Notification xmlns:wp=\"WPNotification\">" .
               "<wp:Toast>" .
                    "<wp:Text1>" . "SendToast" . "</wp:Text1>" .
                    "<wp:Text2>" . $message . "</wp:Text2>" .
                    "<wp:Param>/Receive.xaml?NavigatedFrom=Toast Notification</wp:Param>" .
                    "</wp:Toast> " .
            "</wp:Notification>";

  // Create request to send
     $r = curl_init();
     curl_setopt($r, CURLOPT_URL,$notif_url);
     curl_setopt($r, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($r, CURLOPT_POST, true);
     curl_setopt($r, CURLOPT_HEADER, true); 

  // add headers
     $httpHeaders=array('Content-type: text/xml; charset=utf-8', 'X-WindowsPhone-Target: toast',
                'Accept: application/*', 'X-NotificationClass: 2','Content-Length:'.strlen($toastMessage));
  curl_setopt($r, CURLOPT_HTTPHEADER, $httpHeaders);

  // add message
  curl_setopt($r, CURLOPT_POSTFIELDS, $toastMessage);

  // execute request
  $output = curl_exec($r);
  curl_close($r);

   }
}

?>

我需要如下图所示的输出

在此处输入图像描述

4

1 回答 1

0

作为 toast 通知有效负载一部分的 wp:param 应该是 uri。因此它也应该被编码为一个。在您提供的示例中,有效负载中有一个空间,这可能会导致问题。你可以试试这样格式化吗?

  "<wp:Param>/Receive.xaml?NavigatedFrom=Toast%20Notification</wp:Param>" .

还要确保 Receive.xaml 确实在包的根目录中。

于 2013-09-04T09:03:36.753 回答