gpt4 book ai didi

windows - 推送通知、Uri channel 和 Php 服务器端

转载 作者:可可西里 更新时间:2023-11-01 10:37:40 24 4
gpt4 key购买 nike

我正在尝试使用 WP7.1 中的推送通知。我创建了类和一些 php 类。该示例适用于所有通知类型,但我的问题是 UriChannel。对于我的简单示例,我必须在 php 代码中手动编写 URI channel 。

  • 安装我的应用程序的所有设备的 uri channel 是否都是唯一的?

  • 如何将 Uri channel 发送到我的服务器?

谢谢。

这是我的代码:

/// Holds the push channel that is created or found.
HttpNotificationChannel pushChannel;
// The name of our push channel.
string channelName = "LiveTileChannel";

// Costruttore
public MainPage()
{
InitializeComponent();
CreatePushChannel();
}

private void CreatePushChannel()
{
// Try to find the push channel.
pushChannel = HttpNotificationChannel.Find(channelName);

// If the channel was not found, then create a new connection to the push service.
if (pushChannel == null)
{
pushChannel = new HttpNotificationChannel(channelName);

// Register for all the events before attempting to open the channel.
pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);
pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(PushChannel_ShellToastNotificationReceived);
pushChannel.HttpNotificationReceived += new EventHandler<HttpNotificationEventArgs>(pushChannel_HttpNotificationReceived);
pushChannel.Open();
// Bind this new channel for Tile events.
pushChannel.BindToShellTile();
pushChannel.BindToShellToast();
connessioneTxt.Text = "Connessione avvenuta";
}
else
{
// The channel was already open, so just register for all the events.
pushChannel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);
pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(PushChannel_ShellToastNotificationReceived);
pushChannel.HttpNotificationReceived += new EventHandler<HttpNotificationEventArgs>(pushChannel_HttpNotificationReceived);
// Display the URI for testing purposes. Normally, the URI would be passed back to your web service at this point.
System.Diagnostics.Debug.WriteLine(pushChannel.ChannelUri.ToString());
uriTxt.Text=pushChannel.ChannelUri.ToString();
connessioneTxt.Text = "Connessione già avvenuta";
}
}

void pushChannel_HttpNotificationReceived(object sender, HttpNotificationEventArgs e)
{
string message;

using (System.IO.StreamReader reader = new System.IO.StreamReader(e.Notification.Body))
{
message = reader.ReadToEnd();
}

Dispatcher.BeginInvoke(() => rawTxt.Text = String.Format("Received Notification {0}:\n{1}",
DateTime.Now.ToShortTimeString(), message)
);

}

/// Event handler for when the Push Channel Uri changes.
void PushChannel_ChannelUriUpdated(object sender, NotificationChannelUriEventArgs e)
{

Dispatcher.BeginInvoke(() =>
{
// Display the new URI for testing purposes. Normally, the URI would be passed back to your web service at this point.
System.Diagnostics.Debug.WriteLine(e.ChannelUri.ToString());
uriTxt.Text = pushChannel.ChannelUri.ToString();
});
}

// Event handler for when a Push Notification error occurs.
void PushChannel_ErrorOccurred(object sender, NotificationChannelErrorEventArgs e)
{
// Error handling logic for your particular application would be here.
Dispatcher.BeginInvoke(() =>
MessageBox.Show(String.Format("A push notification {0} error occurred. {1} ({2}) {3}", e.ErrorType, e.Message, e.ErrorCode, e.ErrorAdditionalData)));
}

void PushChannel_ShellToastNotificationReceived(object sender, NotificationEventArgs e)
{
System.Diagnostics.Debug.WriteLine("notifica aperta");
}


}

还有树 php 示例之一:

Pastebin of PHP

最佳答案

URI channel 对于安装了您的应用程序的每个设备都是唯一的。它对于每台设备都必须是唯一的,因为这是告诉 MPN 服务要将通知发送到哪个设备。它与 Apple 推送通知的设备 token 和 Google 云消息传递的注册 ID 的用途相同。

您可以通过向您的服务器发送一些 HTTP GET 或 POST 请求,将 URI channel 作为输入参数,将 URI channel 发送到您的服务器。

以下是从 MSDN 中获取的有关通信服务器的一些指南:

Each time your app starts, you should pass the URI from your push channel to the cloud service that sends out the push notifications. It is also recommended that you pass the device ID to your cloud service so that the cloud service can track to which devices the URIs are assigned. If a URI changes, then the cloud service can replace the old URI for that device ID. Windows Phone does not provide a framework to do this, since in most scenarios apps and cloud services already have their own protocols that they use to communicate with each other.

Best practices for communicating with your cloud service include:

The app should authenticate with its corresponding cloud service.

The app should encrypt its notification channel URI before sending the URI to its corresponding cloud service.

If your cloud service will be using notifications properties that do not exist in Windows Phone OS 7.0 then you should pass the OS version information to your cloud service so that the cloud service can correctly downgrade the notifications for Windows Phone OS 7.0 clients.

The cloud service should validate the notification channel URI received from its corresponding app and store it in a secure manner.

When a session is initiated from the app, the notification channel URI should always be sent to its corresponding cloud service.

The cloud service should have a status code that it can send to its corresponding app that will trigger the app to create a new notification channel URI.

关于windows - 推送通知、Uri channel 和 Php 服务器端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16126139/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com