Pushsharp 苹果通知 A call to SSPI failed 错误

3

我正在使用PushSharp在C#中发送苹果推送通知,我有生产环境的.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();

Please help Thanks in advance

1个回答

1

我认为你的c#代码可能有误,为了验证,请使用以下代码测试你的p12证书,而不是.pem证书...

    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);`

是的,约翰...你说得对。它是使用p12文件进行推送锐利。我一直在使用pem文件。使用p12文件解决了问题。谢谢。 - ramesh
我正在使用相同的代码进行推送,但仍然出现异常:您选择了开发/沙盒(非生产)服务器,但您的证书似乎不是开发/沙盒证书!请检查以确保您拥有正确的证书! - Legnus
@Legnus,你正在使用生产证书。 - Woodstock
是的,.p12 文件有效。在我的情况下,我发现必须使用密码才能使其工作。 - user1019042

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接