我尝试在SNS上创建一个平台应用程序,并且可以轻松地为GCM / Google推送服务执行此操作,但我遇到了Apple问题。
当我调用CreatePlatformApplication()并传递请求时,我需要拥有PlatformCredential和PlatformPrincipal,即证书和私钥。
来自AWS文档的应用程序代码示例
var snsClient = new AmazonSimpleNotificationServiceClient();
var request = new CreatePlatformApplicationRequest
{
Attributes = new Dictionary<string, string>() { { "PlatformCredential", "AIzaSyDM1GHqKEdVg1pVFTXPReFT7UdGEXAMPLE" } },
Name = "TimeCardProcessingApplication",
Platform = "GCM"
};
snsClient.CreatePlatformApplication(request);
我目前在系统上有一个.p12文件,它与我们的手动系统一起用来发送推送通知,并且尝试过多次从p12文件中获取证书和私钥但是我仍然在发送请求时收到错误说PlatformPrincipal无效。
任何人都有想法如何从.p12文件中获取正确的PlatformPrincipal和PlatformCredential?
文档
答案 0 :(得分:0)
在C#中没有简单的方法,因为它需要导出为ASN'1格式,但你可以使用OpenSSL:
私钥
openssl pkcs12 -in key.p12 -nodes -nocerts -passin pass: > private.txt
公钥
openssl pkcs12 -in key.p12" -nodes -nokeys -passin pass: > public.txt
然后发送到AWS SNS
string publicKey = File.ReadAllText("public.txt");
string privateKey = File.ReadAllText("private.txt");
using (var client = new AmazonSimpleNotificationServiceClient())
{
var request = new CreatePlatformApplicationRequest()
{
Name = Client,
Platform = TargetPlatform,
Attributes =
new Dictionary<string, string>()
{
{"PlatformCredential", privateKey },
{"PlatformPrincipal", publicKey }
}
};
var response = client.CreatePlatformApplication(request);
}