Push 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);
}
我正在使用 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);
}