使用 php 平铺通知
我正在尝试使用此库向我的手机发送磁贴通知 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,这将教会我仔细查看代码 - 如果您不带参数调用 BindToShellTile(),则只能使用图块的本地资源。但是,如果您创建一个新集合并将该集合作为参数传递,您将能够访问图块中的本地或远程图像。
例如。
应该做到这一点。 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.
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.