Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 苹果APNS和;委托安全CA根证书“;?_Java_Apple Push Notifications_Certificate - Fatal编程技术网

Java 苹果APNS和;委托安全CA根证书“;?

Java 苹果APNS和;委托安全CA根证书“;?,java,apple-push-notifications,certificate,Java,Apple Push Notifications,Certificate,我正在尝试向iOS设备发送推送通知。 我已经为APN创建了一个开发人员证书,并将其与应用程序标识符绑定在一起 然后,我继续使用Pushy()与APNS服务器建立连接: final PushManagerFactory<SimpleApnsPushNotification> pushManagerFactory = new PushManagerFactory<SimpleApnsPushNotification>( Apns

我正在尝试向iOS设备发送推送通知。
我已经为APN创建了一个开发人员证书,并将其与应用程序标识符绑定在一起

然后,我继续使用Pushy()与APNS服务器建立连接:

final PushManagerFactory<SimpleApnsPushNotification> pushManagerFactory =
        new PushManagerFactory<SimpleApnsPushNotification>(
                ApnsEnvironment.getSandboxEnvironment(),
                PushManagerFactory.createDefaultSSLContext( DEV_CERT_P12__PATH, DEV_CERT_P12__PASSWORD )
                );

final PushManager<SimpleApnsPushNotification> pushManager = pushManagerFactory.buildPushManager();

pushManager.registerFailedConnectionListener(new MyFailedConnectionListener());

pushManager.start();
最终PushManagerFactory PushManagerFactory=
新PushManagerFactory(
ApnsenEnvironment.GetSandboxenEnvironment(),
PushManagerFactory.createDefaultSSLContext(开发证书路径、开发证书密码)
);
final PushManager PushManager=pushManagerFactory.buildPushManager();
registerFailedConnectionListener(新的MyFailedConnectionListener());
pushManager.start();

公共静态类MyFailedConnectionListener实现FailedConnectionListener{
公共无效句柄失败连接(

我已经找到了解决办法。作为向我提出这个建议的人,我不知道为什么它解决了这个问题。

使用OpenSSL,我将P12文件(我从密钥链访问中获得)转换为PEM,然后从PEM转换回P12…

  • 将从应用程序的APN(位于developer.apple.com)下载的CER文件转换为PEM
    opensslx509-in-aps_development.cer-通知DER-out-aps_development.pem-outform-pem


  • 将使用Keychain Access创建的P12文件转换为PEM
    openssl pkcs12-nocerts-in Certificates.p12-out Certificates.pem

  • 创建一个新的、好的P12文件
    openssl pkcs12-export-inkey Certificates.pem-in-aps\u development.pem-out GOOD\u Certificates.P12

  • 有关更多信息:

    您是如何创建p12文件的?您是否从keytool应用程序导出了证书+私钥?我在OS X上,所以我只是使用Keychain Access导出私钥。我指的是Keychain Access应用程序(我忘了名称)。您应该同时选择推送证书和私钥,并将它们导出到p12文件。@Eran仍然存在相同的错误。我已用屏幕截图更新了问题。您是否在Mac上本地运行服务器?
    public static class MyFailedConnectionListener implements FailedConnectionListener<SimpleApnsPushNotification> {
    
        public void handleFailedConnection(
                final PushManager<? extends SimpleApnsPushNotification> pushManager,
                final Throwable cause) {
    
            System.out.println("ERROR  -  "+ cause.toString());
    
            if (cause instanceof SSLHandshakeException) {
    
                // This is probably a permanent failure, and we should shut down
                // the PushManager.
            }
        }
    }