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

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

问题描述

我试图用Java APNS - 一个开源项目 - 发送推送通知到iPhone。
我得到一个错误,虽然。

我使用了一个.pem文件为证。如果这是一个.p12文件?我不知道有什么区别,但我在网上读的地方,有这些文件格式之间的差异。

下面是code:

  ApnsService服务=
        APNS.newService()
            .withCert(gpk.pem,XXXX)
            .withSandboxDestination()
            。建立();
    字符串的有效载荷= APNS.newPayload()alertBody(不能比这更简单!),建立()。
    字符串标记=theTokenIsRemoveHere;
    service.push(令牌,负载);

这里是错误:

 异常线程maincom.notnoop.exceptions.InvalidSSLConfig:java.io.IOException异常:toDerInputStream拒绝标签类型45
    在com.notnoop.apns.internal.Utilities.newSSLContext(Utilities.java:102)
    在com.notnoop.apns.ApnsServiceBuilder.withCert(ApnsServiceBuilder.java:161)
    在com.notnoop.apns.ApnsServiceBuilder.withCert(ApnsServiceBuilder.java:124)
    在com.geomobsters.cli.ApnsClient.main(ApnsClient.java:12)
    在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)
    在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    在java.lang.reflect.Method.invoke(Method.java:597)
    在com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
java.io.IOException异常:引起toDerInputStream拒绝标签类型45
    在sun.security.util.DerValue.toDerInputStream(DerValue.java:806)
    在com.sun.net.ssl​​.internal.pkcs12.PKCS12KeyStore.engineLoad(PKCS12KeyStore.java:1201)
    在java.security.KeyStore.load(KeyStore.java:1185)
    在com.notnoop.apns.internal.Utilities.newSSLContext(Utilities.java:87)
    ... 8个


解决方案

Java的APNS期待的证书为.p12文件。

您必须检查您的钥匙串都privatekey和证书。
然后右键单击 - >出口2个文件
并导出
你必须给它一个密码,这个密码,您必须在此处键入

  .withCert(gpk.pem,XXXX)

作为您XXXX

好运气

编辑:

.P12 - PKCS#12,包含证书的私钥保存密码
.PEM - 是的Base64恩codeD证书,lockedby ----- BEGIN CERTIFICATE -----和----- END CERTIFICATE -----

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

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.

Here is the code:

   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);

And here is the error:

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 is expecting the cert as .p12 file.

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")

as your XXXX

good luck

EDIT:

.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(苹果推送通知服务)错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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