PushSharp Apple – 收到的消息是意外的或格式错误

我使用的是PushSharp 2.1.2版。 该应用程序是.NET 4.5.1(虽然我也尝试过针对.NET 4.5和.NET 4)

我正在尝试但没有成功通过沙盒Apple APNS发送推送消息。

我使用相同的证书并使用与我的PushSharp应用程序相同的设备ID,使用Ray Wenderlich演练中提供的PHP脚本成功发送消息。

我已通过从钥匙链中导出已完成的证书p12进行测试。 导出已完成的证书和密钥。 导出私钥。 也可以通过这里使用的方法。 当我将证书和密钥结合起来用于PHP脚本时,我没有任何问题。

我已将p12证书导入到我测试过的机器上 – 似乎没有任何区别。

我已经尝试在向推送代理注册apple推送服务时更改IsProduction标志。 将它设置为生产时没有错误(即使这是一个沙箱证书),但在这种情况下它显然也无法通过设备。

我的所有消息都不会通过,所有消息都会得到如下所示的服务exception:

System.Security.Authentication.AuthenticationException: A call to SSPI failed, see inner exception. ---> System.ComponentModel.Win32Exception: The message received was unexpected or badly formatted --- End of inner exception stack trace --- at System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, Exception exception) at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult) at PushSharp.Apple.FeedbackService.Run(ApplePushChannelSettings settings, CancellationToken cancelToken) at PushSharp.Apple.ApplePushService.c__DisplayClass4.b__1(Object state) 

这基本上就是我的代码:

 var push = new PushBroker(); // register event handlers for channel create/destroy/exception, notificationrequeue, serviceexception, notification sent var appleCert = File.ReadAllBytes(ConfigurationManager.AppSettings["CertAddress"]); push.RegisterAppleService(new ApplePushChannelSettings(false, appleCert, ConfigurationManager.AppSettings["CertPassword"])); var pn = new AppleNotification().ForDeviceToken(item.SendToDeviceIdentifier).WithAlert(item.AlertMessage).WithBadge(item.Badges); push.QueueNotification(pn); 

我调用了通道up事件,然后是服务exception。

一些相关的问题提到这个错误可能与防火墙问题有关 – 我已经在2个不同的网络中测试了我的应用程序,这些网络能够发送推送通知(其中1个当前正在使用PushSharp应用程序)。

任何见解都会非常感激。

使用现已弃用的APNS-Sharp库(PushSharp的祖先),我们遇到了同样的问题。 我提交了一个APNS-Sharp的拉取请求,根据我的测试解决了这个问题。

修改是要改变的(在ApplePushChannel.cs中)

 stream.AuthenticateAsClient(this.appleSettings.Host, this.certificates, System.Security.Authentication.SslProtocols.Ssl3, false); 

 stream.AuthenticateAsClient(this.appleSettings.Host, this.certificates, System.Security.Authentication.SslProtocols.Tls, false); 

我没有找到关于此的确认,但看起来Sandbox APNS不再支持SSL3协议。 与报告此问题的其他人一样,我对生产APNS的通知仍然有效。

你可以在这里找到拉取请求:

https://github.com/Redth/PushSharp/pull/369/files

更新

Apple Developer网站上有一个关于此主题的主题:

https://devforums.apple.com/thread/224320?tstart=0

但是,那里的一些人也在这个线程或github线程上。 所以这些信息肯定是有偏见的。 我在Apple的联系人说:

虽然还没有官方文档,但似乎APNS正朝着TLS而不是SSL发展(完全基于看到这种变化 – 我没有听到任何官方文件)。

如果你们中的任何人在Windows Server 2003上运行它(我知道,我知道),你将不得不运行这个补丁,否则即使你实现了修复程序,你仍然会遇到奇怪的错误。 我花了几个小时想知道为什么我的2008服务器工作,而我的2003服务器没有。

http://support.microsoft.com/kb/948963