C# Pushsharp apple通知调用SSPI失败错误

C# Pushsharp apple通知调用SSPI失败错误,c#,ios,push-notification,apple-push-notifications,pushsharp,C#,Ios,Push Notification,Apple Push Notifications,Pushsharp,我正在使用PushSharp以C#格式发送苹果推送通知,我有我的production.pem文件及其密码。下面是我的代码片段。我总是遇到这个错误 "A call to SSPI failed, see inner exception. ---> System.ComponentModel.Win32Exception: The message received was unexpected or badly formatted-" 或 我尝试了网络中几乎所有可用的代码。甚至尝试了Moo

我正在使用PushSharp以C#格式发送苹果推送通知,我有我的production.pem文件及其密码。下面是我的代码片段。我总是遇到这个错误

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

我尝试了网络中几乎所有可用的代码。甚至尝试了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();
请帮忙 提前感谢

我认为您的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);`
Boolean bsandbox=true;
字符串p12fileName=AppDomain.CurrentDomain.BaseDirectory+“yourCert.p12”;
字符串p12password=“1234”;
字符串设备1=“2909b25e0c699b2dc4864b4b9f719e67aac7e0fab791a72a086ffb788ba28f6a”//
string msg=“这是在以下地址发送的消息:”;
string alert=“Hello world at”+DateTime.Now.ToLongTimeString();
int badge=1;
string soundstring=“默认”;
var payload1=新的通知有效载荷(设备1、警报、徽章、声音字符串);
payload1.AddCustom(“custom1”,msg);
var notificationList=新列表{payload1};
var push=新的PushNotification(bsandbox,p12文件名,p12密码);
var rejected=push.SendToApple(通知列表)`

是的,约翰。。。你说得对。它的p12文件用于push sharp。我用的是pem文件。用p12文件解决了这个问题。ThanksI我使用相同的代码推送,但我得到一个异常:您选择了开发/沙盒(非生产)服务器,但您的证书似乎不是开发/沙盒证书!请检查以确保您拥有正确的证书@Legnus您使用的是产品证书。是的,.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);`