Pushsharp苹果通知对SSPI的调用失败错误

本文关键字:调用 失败 错误 SSPI 苹果 通知 Pushsharp | 更新日期: 2023-09-27 18:29:53

我使用PushSharp在C#中发送Apple推送通知,我有我的production.pem文件及其密码。下面是我的代码片段。我总是犯这个错误。。

"A call to SSPI failed, see inner exception. ---> System.ComponentModel.Win32Exception: The message received was unexpected or badly formatted-" 

"System.IO.IOException: Authentication failed because the remote party has closed the transport stream."

我尝试了网络上几乎所有可用的代码。甚至尝试了MoonAPNS,但同样的错误,对于自定义脚本也得到了这个SSPI失败错误。我使用相同的.pem文件并运行php脚本从同一服务器向APN发送推送通知,它可以工作。

var push = new PushBroker();
var appleCert = File.ReadAllBytes(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ck.pem"));
 push.RegisterAppleService(new ApplePushChannelSettings(false, appleCert, "pwd")); 
 push.QueueNotification(new AppleNotification()
                                           .ForDeviceToken("XXXXXXXXXXXXXXX")
                                           .WithAlert("Hello World!")
                                           .WithBadge(7)
                                           .WithSound("sound.caf"));

                LogManager.Info("Waiting for Queue to Finish..");
                push.StopAllServices();

请帮忙提前感谢

Pushsharp苹果通知对SSPI的调用失败错误

我认为您的c#可能不正确。为了验证,而不是使用.pem,您可以使用下面的代码来测试您的p12证书吗。。。

    Boolean bsandbox = true;
    string p12fileName =AppDomain.CurrentDomain.BaseDirectory + "yourCert.p12";
    string p12password = "1234";
    string deviceID1 = "2909b25e0c699b2dc4864b4b9f719e67aac7e0fab791a72a086ffb788ba28f6a"; //
    string msg = "This is the message sent at : ";
    string alert = "Hello world at " + DateTime.Now.ToLongTimeString();
    int badge = 1;
    string soundstring = "default";
    var payload1 = new NotificationPayload(deviceID1, alert, badge, soundstring);
    payload1.AddCustom("custom1", msg); 
    var notificationList = new List<NotificationPayload> { payload1 };

    var push = new PushNotification(bsandbox, p12fileName, p12password);
    var rejected = push.SendToApple(notificationList);`