PushSharp Apple-收到的消息出乎意料或格式错误

本文关键字:出乎意料 格式 错误 消息 Apple- PushSharp | 更新日期: 2023-09-27 17:58:42

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

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

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

我已经通过将已完成的证书从密钥链导出为p12进行了测试。正在导出已完成的证书和密钥。正在导出私钥。也是通过这里使用的方法。当我将cert和key组合在PHP脚本中使用时,我没有问题。

我已经将p12证书导入到我测试的机器上——似乎没有什么区别。

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

我的任何消息都不会通过,所有消息都会得到一个服务异常,如下所示:

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.<.ctor>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);

我调用了channel up事件,然后调用了服务异常。

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

任何见解都将不胜感激。

PushSharp Apple-收到的消息出乎意料或格式错误

我们在使用现已弃用的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);

我没有找到这方面的确认,但看起来沙盒APNS不再支持SSL3协议。与其他报告该问题的人一样,我针对生产APNS的通知仍然有效。

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

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

更新

苹果开发者网站上有一个关于这个主题的帖子:

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

然而,那里的一些人也在这个线程或github线程上。因此,这些信息肯定是有偏见的。我在苹果公司的一位联系人说:

虽然目前还没有官方文档,但APNS似乎正在朝着TLS而非SSL的方向发展(仅基于看到这一变化-我还没有听到任何官方消息)

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

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