c# - Pushsharp 发送苹果通知失败 : SSL Stream Failed to Authenticate as Client
<p><p>我尝试在 IIS 上托管的 ASP.NET MVC 项目上使用 Pushsharp 库向苹果设备发送推送通知。</p>
<p>我的代码:</p>
<pre><code> public static void SendAppleNotification()
{
// Configuration (NOTE: .pfx can also be used here)
byte[] arr = File.ReadAllBytes("D:\\MySoftware\\pa_Dev.pem");
var config = new ApnsConfiguration(ApnsConfiguration.ApnsServerEnvironment.Sandbox,
arr, "1234");
// Create a new broker
var apnsBroker = new ApnsServiceBroker(config);
// Wire up events
apnsBroker.OnNotificationFailed += (notification, aggregateEx) => {
aggregateEx.Handle(ex => {
// See what kind of exception it was to further diagnose
if (ex is ApnsNotificationException)
{
var notificationException = (ApnsNotificationException)ex;
// Deal with the failed notification
var apnsNotification = notificationException.Notification;
var statusCode = notificationException.ErrorStatusCode;
Console.WriteLine($"Apple Notification Failed: ID={apnsNotification.Identifier}, Code={statusCode}");
}
else
{
// Inner exception might hold more useful information like an ApnsConnectionException
Console.WriteLine($"Apple Notification Failed for some unknown reason : {ex.InnerException}");
}
// Mark it as handled
return true;
});
};
apnsBroker.OnNotificationSucceeded += (notification) => {
Console.WriteLine("Apple Notification Sent!");
};
// Start the broker
apnsBroker.Start();
// Queue a notification to send
apnsBroker.QueueNotification(new ApnsNotification
{
DeviceToken = "660E4433785EFF2B2AA29D5076B039C969F1AADD839D79261328F40B08D26497",
Payload = JObject.Parse("{\"aps\":{\"badge\":7}}")
});
// Stop the broker, wait for it to finish
// This isn't done after every message, but after you're
// done with the broker
apnsBroker.Stop();
}
</code></pre>
<p>注意事项:
1- 尝试将 pem 扩展名更改为 p12,但仍然出现同样的问题。
2- 我尝试使用 <a href="https://pushtry.com/" rel="noreferrer noopener nofollow">https://pushtry.com/</a> 发送推送通知并且它工作正常,所以不是从认证文件或密码发出的。</p>
<p>pushsharp 内部的问题或缺少配置必须在我的机器上完成,有人知道吗?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>截至 2019 年 7 月 23 日,这刚刚发生在我身上。看起来 Apple 现在正在为位于 </p> 的沙盒 voip 推送通知服务器强制执行 TLS 1.2
<pre><code>gateway.sandbox.push.apple.com - port 2195
feedback.sandbox.push.apple.com - port 2196
</code></pre>
<p>我发现我必须从 <a href="https://github.com/Redth/PushSharp" rel="noreferrer noopener nofollow">https://github.com/Redth/PushSharp</a> 查看最新的代码(主分支),构建它,然后在我的项目中手动添加对构建的 DLL 的引用。</p>
<p>之前我使用的是 NuGet PushSharp 包,它已经有 3 年历史了,还没有更新。如果您查看 master 分支上最近的提交,就会发现那里有一些与 Apple 和 TLS 相关的更改,所以我确信这已经修复了它。</p></p>
<p style="font-size: 20px;">关于c# - Pushsharp 发送苹果通知失败 : SSL Stream Failed to Authenticate as Client,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/48355550/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/48355550/
</a>
</p>
页:
[1]