如何在Windows Phone的Microsoft推送通知服务中进行身份验证?

时间:2013-03-29 13:04:35

标签: windows-phone-7 windows-phone-8 push-notification windows-phone mpns

实现这一目标真的很麻烦。我正在开发一个PhoneGap应用程序,我将把它部署到Android,iOS和Windows Phone。

我能够毫无问题地使用Apple Notification Service(APN)和Google Cloud Messaging,但我真的很难用我的Windows Phone应用程序做同样的事情。

与APN GCM不同,我找不到生成某些代码或下载某些证书的地方,以便将我的应用程序与推送通知服务集成。

我正在尝试使用此服务通过PHP向Windows Phone发送推送通知 http://phpwindowsphonepush.codeplex.com/

该示例向我展示了这个$uri="http://db3.notify.live.net/throttledthirdparty/01.00/123456789123456798"; //uri sended by Microsoft plateform但是如何注册到他们的plataform以获得这样的URI?

此外,这个PHP Windows Phone推送是在Windows Phone上发送Toast和tile通知的正确选择吗?文档非常混乱,并且不清楚如何配置服务器和本机代码应用程序,我迷路了。

1 个答案:

答案 0 :(得分:3)

被叫通知信道中的URI,它是APNS设备令牌和GCM注册ID的MPNS等价物。 您可以在Windows Phone应用程序代码中获取它:

public MainPage()
{
    /// Holds the push channel that is created or found.
    HttpNotificationChannel pushChannel;

    // The name of our push channel.
    string channelName = "ToastSampleChannel";

    InitializeComponent();

    // 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);

        // Register for this notification only if you need to receive the notifications while your application is running.
        pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(PushChannel_ShellToastNotificationReceived);

        pushChannel.Open();

        // Bind this new channel for toast events.
        pushChannel.BindToShellToast();

    }
    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);

        // Register for this notification only if you need to receive the notifications while your application is running.
        pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(PushChannel_ShellToastNotificationReceived);

        // 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());
        MessageBox.Show(String.Format("Channel Uri is {0}",
            pushChannel.ChannelUri.ToString()));

    }
}

您无需验证您的Web服务(未经身份验证的Web服务每天可以为每台设备发送500条消息),但建议您这样做:

  

我们建议您设置经过身份验证的网络服务以发送您的   通知推送通知服务,因为通信   通过HTTPS接口发生,以提高安全性。经过验证的网站   服务没有推送通知数量的每日限制   他们可以发送。另一方面,未经身份验证的Web服务是   以每次订阅500次推送通知的速率进行限制   天。有关详细信息,请参阅设置经过身份验证的Web服务   发送Windows Phone的推送通知。

相关链接:

Sending push notifications for Windows Phone

Setting up an authenticated web service to send push notifications for Windows Phone