簡體   English   中英

推送Sharp ios通知,獲取分發證書“ System.Security.Cryptography.CryptographicException”的錯誤

[英]Push Sharp ios notification getting error with distribution certificate “System.Security.Cryptography.CryptographicException”

我正在使用Push Sharp處理蘋果推送通知。 帶有開發和發行證書的本地計算機上運行良好。 我在本地嘗試時確實收到了推送通知。 但是,當我將代碼移到生產服務器(GODaddy服務器)時,我收到一個錯誤

System.Security.Cryptography.CryptographicException).

PushBroker _pushBroker = new PushBroker();
                var appleCert = File.ReadAllBytes(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Certificates/App_AdHoc.p12"));
                _pushBroker.RegisterAppleService(new ApplePushChannelSettings(true, appleCert, "pamten")); //Extension method
                _pushBroker.QueueNotification(new AppleNotification()
                        .ForDeviceToken("Device Token")
                        .WithAlert("Message")
                        .WithBadge(0)
                        .WithSound("default")
                        );

以下是我在GoDaddy服務器中遇到的錯誤。

ExceptionType": "System.Security.Cryptography.CryptographicException",
5   "StackTrace": " at System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr)\r\n at System.Security.Cryptography.X509Certificates.X509Utils._LoadCertFromBlob(Byte[] rawData, IntPtr password, UInt32 dwFlags, Boolean persistKeySet, SafeCertContextHandle& pCertCtx)\r\n at System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromBlob(Byte[] rawData, Object password, X509KeyStorageFlags keyStorageFlags)\r\n at System.Security.Cryptography.X509Certificates.X509Certificate..ctor(Byte[] rawData, String password, X509KeyStorageFlags keyStorageFlags)\r\n at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(Byte[] rawData, String password, X509KeyStorageFlags keyStorageFlags)\r\n at PushSharp.Apple.ApplePushChannelSettings..ctor(Boolean production, Byte[] certificateData, String certificateFilePwd, Boolean disableCertificateCheck)\r\n at InStorePal.Controllers.InStorePalController.GetItemsList(GetItems obj)\r\n at lambda_method(Closure , Object , Object[] )\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass13.<GetExecutor>b__c(Object instance, Object[] methodParameters)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.<>c__DisplayClass5.<ExecuteAsync>b__4()\r\n at System.Threading.Tasks.TaskHelpers.RunSynchronously[TResult](Func`1 func, CancellationToken cancellationToken)"
6   }

我嘗試了很多方法,例如對GODaddy服務器中文件夾的訪問權限,創建分布式證書這么多次。

請幫我。

我在GoDaddy服務器中也遇到了同樣的問題。 嘗試一次Azure或Amazon服務器。 它在Azure中為我工作。

這是一個奇怪的問題和奇怪的解決方案。 但這對我有用。

 public ActionResult ios()
    {
        var certi = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Certificatesgit.p12");
        var appleCert = System.IO.File.ReadAllBytes(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Certificatesgit.p12"));

        ApnsConfiguration apnsConfig = new ApnsConfiguration(ApnsConfiguration.ApnsServerEnvironment.Production, appleCert, "password");

        string message = string.Empty;
        var apnsBroker = new ApnsServiceBroker(apnsConfig);

        apnsBroker.OnNotificationFailed += (notification, aggregateEx) =>
        {
            aggregateEx.Handle(ex =>
            {
                if (ex is ApnsNotificationException)
                {
                    var notificationException = (ApnsNotificationException)ex;
                    var apnsNotification = notificationException.Notification;
                    var statusCode = notificationException.ErrorStatusCode;
                    var inner = notificationException.InnerException;
                    message = "IOS Push Notifications: Apple Notification Failed: ID=" + apnsNotification.Identifier + ", Code=" + statusCode + ", Inner Exception" + inner;
                }
                else
                {
                    message = "IOS Push Notifications: Apple Notification Failed for some unknown reason : " + ex.InnerException;
                }
                return true;
            });
        };

        apnsBroker.OnNotificationSucceeded += (notification) =>
        {
            message = "IOS Push Notifications: Apple Notification Sent!";
        };

        apnsBroker.Start();
        try
        {
            string deviceToken = "4e16e1439d7f1a342ed5a8c92bf029503107c7a2bc3b92b794b22665affcf99c";

            apnsBroker.QueueNotification(new ApnsNotification
            {
                DeviceToken = deviceToken,
                Payload = JObject.Parse("{\"aps\":{\"badge\":7}}")
            });
        }
        catch (Exception ex)
        {
            Console.Write(ex);
        }
        apnsBroker.Stop();

        return View(message);
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM