Java APNS(Apple 推送通知服务)错误 [英] Java APNS (Apple Push Notification Service) error

查看:41
本文介绍了Java APNS(Apple 推送通知服务)错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Java APNS(一个开源项目)向 iPhone 发送推送通知.但是,我收到错误消息.

I am trying to use Java APNS - an open source project - to send push notifications to iPhones. I am getting an error, though.

我使用了 .pem 文件作为证书.这应该是一个 .p12 文件吗?我不确定有什么区别,但我在网上某处读到这些文件格式之间存在差异.

I have used a .pem file as certificate. Should this have been a .p12 file? I am not sure what the difference is, but I read somewhere online that there is a difference between these file formats.

代码如下:

   ApnsService service =
        APNS.newService()
            .withCert("gpk.pem", "XXXX")
            .withSandboxDestination()
            .build();


    String payload = APNS.newPayload().alertBody("Can't be simpler than this!").build();
    String token = "theTokenIsRemoveHere";
    service.push(token, payload);

这里是错误:

Exception in thread "main" com.notnoop.exceptions.InvalidSSLConfig: java.io.IOException: toDerInputStream rejects tag type 45
    at com.notnoop.apns.internal.Utilities.newSSLContext(Utilities.java:102)
    at com.notnoop.apns.ApnsServiceBuilder.withCert(ApnsServiceBuilder.java:161)
    at com.notnoop.apns.ApnsServiceBuilder.withCert(ApnsServiceBuilder.java:124)
    at com.geomobsters.cli.ApnsClient.main(ApnsClient.java:12)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.io.IOException: toDerInputStream rejects tag type 45
    at sun.security.util.DerValue.toDerInputStream(DerValue.java:806)
    at com.sun.net.ssl.internal.pkcs12.PKCS12KeyStore.engineLoad(PKCS12KeyStore.java:1201)
    at java.security.KeyStore.load(KeyStore.java:1185)
    at com.notnoop.apns.internal.Utilities.newSSLContext(Utilities.java:87)
    ... 8 more

推荐答案

Java APNS 需要证书为 .p12 文件.

Java APNS is expecting the cert as .p12 file.

您必须检查钥匙串中的私钥和证书.然后右键单击->导出2个文件"并导出它们你必须给它一个密码,这个密码你必须在这里输入

You have to check both privatekey and certificate in your keychain. then right click-> "export 2 files" and export them you have to give it a password, this password you have to type here

.withCert("gpk.pem", "XXXX")

作为你的XXXX

祝你好运

.P12 – PKCS#12,包含证书和用密码保存的私钥.PEM – 是 Base64 编码的证书,由 „-----BEGIN CERTIFICATE-----"和 „-----END CERTIFICATE-----"

.P12 – PKCS#12, contains certificates an private keys saved with a password .PEM – is Base64-encoded certificate, lockedby „-----BEGIN CERTIFICATE-----" and „-----END CERTIFICATE-----"

这篇关于Java APNS(Apple 推送通知服务)错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆