gpt4 book ai didi

c# - PushSharp Apple - 收到的消息是意外的或格式错误

转载 作者:可可西里 更新时间:2023-11-01 08:15:57 25 4
gpt4 key购买 nike

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

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

我使用提供的 PHP 脚本成功发送消息 here on Ray Wenderlich's walkthrough使用与我的 PushSharp 应用程序相同的证书并发送到相同的设备 ID。

我已经通过从 key 链中将完整的证书导出为 p12 进行了测试。导出完成的证书和 key 。导出私钥。同样通过使用的方法here .当我在 PHP 脚本中组合使用证书和 key 时,我没有遇到任何问题。

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

在将苹果推送服务注册到推送代理时,我尝试更改 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 启动事件,然后是服务异常。

一些相关问题提到此错误可能与防火墙问题有关 - 我已经在 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 协议(protocol)。与报告此问题的其他人一样,我针对生产 APNS 的通知仍然有效。

您可以在此处找到拉取请求:

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

更新

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

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

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

虽然还没有官方文档,但 APNS 似乎正在转向 TLS 而不是 SSL(仅基于看到这一变化 - 我还没有听到任何官方消息)。

关于c# - PushSharp Apple - 收到的消息是意外的或格式错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23115394/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com