使用 php 平铺通知

发布于 2024-11-14 09:42:57 字数 3870 浏览 4 评论 0 原文

我正在尝试使用此库向我的手机发送磁贴通知 http://phpwindowsphonepush.codeplex.com/ 但只有当我输入远程图像的URL时,手机才收到通知。这是我的简单 php 代码

$uri="http://db3.notify.live.net/throttledthirdparty/01.00/AAEyQ7xxxxxxxxxxx";

$notif=new WindowsPhonePushNotification($uri);

$imm="http://www.mysite.net/imm/1.jpg";

$notif->push_tile($imm, "Title","2");

这是 c# 代码

private HttpNotificationChannel channel;

    public MainPage()
    {
        InitializeComponent();

        try
        {
            StartChannel();
        }
        catch (InvalidOperationException ioe)
        {
            HandleChannelException(ioe);
        }
    }



    private void HandleChannelException(InvalidOperationException ioe)
    {
        MessageBox.Show(ioe.Message);
    }

    private void StartChannel()
    {
        channel = HttpNotificationChannel.Find("test1");
        if (channel == null)
        {
            channel = new HttpNotificationChannel("test1", "name");
            AddDelegates();
            channel.Open();
        }
        else
        {
            AddDelegates();
        }

        if (channel.ChannelUri != null)
        {
            OnChannelReady();
        }
    }

    private void AddDelegates()
    {
        channel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(channel_ChannelUriUpdated);
        channel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(channel_ErrorOccurred);
        channel.HttpNotificationReceived += new EventHandler<HttpNotificationEventArgs>(channel_HttpNotificationReceived);
    }

    private void channel_HttpNotificationReceived(object sender, HttpNotificationEventArgs e)
    {

        StreamReader sr = new StreamReader(e.Notification.Body, Encoding.UTF8);
        string text = sr.ReadToEnd();
        this.Dispatcher.BeginInvoke(() => MessageBox.Show(text));
    }



    private void channel_ErrorOccurred(object sender, NotificationChannelErrorEventArgs e)
    {

        MessageBox.Show("ERROR");

    }

    private void channel_ChannelUriUpdated(object sender, NotificationChannelUriEventArgs e)
    {
        try
        {
            this.Dispatcher.BeginInvoke(OnChannelReady);
        }
        catch (InvalidOperationException ioe)
        {
            this.Dispatcher.BeginInvoke(() => HandleChannelException(ioe));
        }
    }

    private void OnChannelReady()
    {

        if (!this.channel.IsShellTileBound)
            this.channel.BindToShellTile();

    }

这是一个日志文件:

* About to connect() to db3.notify.live.net port 80
*   Trying xx.xx.xx.xxx... * connected
* Connected to db3.notify.live.net (xxx.xx.xx.xxx) port 80
> POST /throttledthirdparty/01.00/AAE0ykxoIaknSoMXxxxxxxxxxxxx HTTP/1.1
Host: db3.notify.live.net
Accept: */*
X-WindowsPhone-Target: token
X-NotificationClass: 1
Content-Length: 240
Content-Type: application/x-www-form-urlencoded
<?xml version="1.0" encoding="utf-8"?>
<wp:Notification xmlns:wp="WPNotification">
<wp:Tile>
<wp:BackgroundImage>http://www.mysite.net/imm/1.jpg</wp:BackgroundImage>
<wp:Count>2</wp:Count>
<wp:Title>6</wp:Title>
</wp:Tile> 
</wp:Notification>< HTTP/1.1 200 OK
< Cache-Control: private
< Server: Microsoft-IIS/7.5
< X-DeviceConnectionStatus: Connected
< X-NotificationStatus: Received
< X-SubscriptionStatus: Active
< X-MessageID: 00000000-0000-0000-0000-000000000000
< ActivityId: xxxxxx-83fa-423d-8240-ec610eca749b
< X-Server: DB3MPNSM005
< X-AspNet-Version: 4.0.30319
< X-Powered-By: ASP.NET
< Date: Tue, 07 Jun 2011 11:57:18 GMT
< Content-Length: 0
* Connection #0 to host db3.notify.live.net left intact
* Closing connection #0

I'm trying to send to my phone a tile notification using this library
http://phpwindowsphonepush.codeplex.com/
but the phone does not receive the notification only when I enter the URL of remote image. This is my simple php code

$uri="http://db3.notify.live.net/throttledthirdparty/01.00/AAEyQ7xxxxxxxxxxx";

$notif=new WindowsPhonePushNotification($uri);

$imm="http://www.mysite.net/imm/1.jpg";

$notif->push_tile($imm, "Title","2");

this is c# code

private HttpNotificationChannel channel;

    public MainPage()
    {
        InitializeComponent();

        try
        {
            StartChannel();
        }
        catch (InvalidOperationException ioe)
        {
            HandleChannelException(ioe);
        }
    }



    private void HandleChannelException(InvalidOperationException ioe)
    {
        MessageBox.Show(ioe.Message);
    }

    private void StartChannel()
    {
        channel = HttpNotificationChannel.Find("test1");
        if (channel == null)
        {
            channel = new HttpNotificationChannel("test1", "name");
            AddDelegates();
            channel.Open();
        }
        else
        {
            AddDelegates();
        }

        if (channel.ChannelUri != null)
        {
            OnChannelReady();
        }
    }

    private void AddDelegates()
    {
        channel.ChannelUriUpdated += new EventHandler<NotificationChannelUriEventArgs>(channel_ChannelUriUpdated);
        channel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(channel_ErrorOccurred);
        channel.HttpNotificationReceived += new EventHandler<HttpNotificationEventArgs>(channel_HttpNotificationReceived);
    }

    private void channel_HttpNotificationReceived(object sender, HttpNotificationEventArgs e)
    {

        StreamReader sr = new StreamReader(e.Notification.Body, Encoding.UTF8);
        string text = sr.ReadToEnd();
        this.Dispatcher.BeginInvoke(() => MessageBox.Show(text));
    }



    private void channel_ErrorOccurred(object sender, NotificationChannelErrorEventArgs e)
    {

        MessageBox.Show("ERROR");

    }

    private void channel_ChannelUriUpdated(object sender, NotificationChannelUriEventArgs e)
    {
        try
        {
            this.Dispatcher.BeginInvoke(OnChannelReady);
        }
        catch (InvalidOperationException ioe)
        {
            this.Dispatcher.BeginInvoke(() => HandleChannelException(ioe));
        }
    }

    private void OnChannelReady()
    {

        if (!this.channel.IsShellTileBound)
            this.channel.BindToShellTile();

    }

this is a log file:

* About to connect() to db3.notify.live.net port 80
*   Trying xx.xx.xx.xxx... * connected
* Connected to db3.notify.live.net (xxx.xx.xx.xxx) port 80
> POST /throttledthirdparty/01.00/AAE0ykxoIaknSoMXxxxxxxxxxxxx HTTP/1.1
Host: db3.notify.live.net
Accept: */*
X-WindowsPhone-Target: token
X-NotificationClass: 1
Content-Length: 240
Content-Type: application/x-www-form-urlencoded
<?xml version="1.0" encoding="utf-8"?>
<wp:Notification xmlns:wp="WPNotification">
<wp:Tile>
<wp:BackgroundImage>http://www.mysite.net/imm/1.jpg</wp:BackgroundImage>
<wp:Count>2</wp:Count>
<wp:Title>6</wp:Title>
</wp:Tile> 
</wp:Notification>< HTTP/1.1 200 OK
< Cache-Control: private
< Server: Microsoft-IIS/7.5
< X-DeviceConnectionStatus: Connected
< X-NotificationStatus: Received
< X-SubscriptionStatus: Active
< X-MessageID: 00000000-0000-0000-0000-000000000000
< ActivityId: xxxxxx-83fa-423d-8240-ec610eca749b
< X-Server: DB3MPNSM005
< X-AspNet-Version: 4.0.30319
< X-Powered-By: ASP.NET
< Date: Tue, 07 Jun 2011 11:57:18 GMT
< Content-Length: 0
* Connection #0 to host db3.notify.live.net left intact
* Closing connection #0

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ぺ禁宫浮华殁 2024-11-21 09:42:57

好的,这将教会我仔细查看代码 - 如果您不带参数调用 BindToShellTile(),则只能使用图块的本地资源。但是,如果您创建一个新集合并将该集合作为参数传递,您将能够访问图块中的本地或远程图像。

例如。

Collection<Uri> TileLocations = new Collection<Uri> { new Uri(@"/Background.jpg") };
TileLocations.Add(new Uri("http://jquery.andreaseberhard.de"));
if (!channel.IsShellTileBound) { channel.BindToShellTile(TileLocations); }

应该做到这一点。 URI 集合应包含可从中检索图像的所有可能的域。在这种情况下, http://jquery.andreasebernhard.de 中的任何内容都将是有效图像。 参阅此页面

有关详细信息,请 $notif->push_>tile("http://jquery.andreaseberhard.de/pngFix/pngtest.png","title","2");应该使用远程图像。

OK, that will teach me to look carefully at the code - if you call BindToShellTile() without arguments, you can only use local resources for the tile. However, if you create a new Collection and pass that collection in as an argument, you will be able to access local or remote images in the tile.

eg.

Collection<Uri> TileLocations = new Collection<Uri> { new Uri(@"/Background.jpg") };
TileLocations.Add(new Uri("http://jquery.andreaseberhard.de"));
if (!channel.IsShellTileBound) { channel.BindToShellTile(TileLocations); }

Should do the trick. The collection of URIs should contain all the possible domains from which images may be retrieved. In this case, anything at http://jquery.andreasebernhard.de would be valid images. For details see this page

Now calling $notif->push_>tile("http://jquery.andreaseberhard.de/pngFix/pngtest.png","title","2"); should work with a remote image.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文