Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.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
Ios 如何在调用APN的API时向APN发送推送证书?_Ios_Spring Boot_Ssl_Apple Push Notifications - Fatal编程技术网

Ios 如何在调用APN的API时向APN发送推送证书?

Ios 如何在调用APN的API时向APN发送推送证书?,ios,spring-boot,ssl,apple-push-notifications,Ios,Spring Boot,Ssl,Apple Push Notifications,由于使用我的服务器应用程序(Spring Boot应用程序)中的apns推送证书发送推送通知而被卡住。苹果公司概述了我们如何使用证书发送推送,但没有关于TLS通信的技术细节(特别是我如何将推送证书发送到APN并继续API调用) 有人有任何参考资料或文章吗?自从您提到您正在使用Spring Boot应用程序以来,我假设您正在使用Java和Maven 我们的后端也是用Java编写的,我最近通过实现更新了推送通知代码。使用经过战斗测试并定期更新的库要比编写自己的库容易得多。我使用pushy在一个相当弱

由于使用我的服务器应用程序(Spring Boot应用程序)中的apns推送证书发送推送通知而被卡住。苹果公司概述了我们如何使用证书发送推送,但没有关于TLS通信的技术细节(特别是我如何将推送证书发送到APN并继续API调用)


有人有任何参考资料或文章吗?

自从您提到您正在使用Spring Boot应用程序以来,我假设您正在使用Java和Maven

我们的后端也是用Java编写的,我最近通过实现更新了推送通知代码。使用经过战斗测试并定期更新的库要比编写自己的库容易得多。我使用pushy在一个相当弱的服务器上每天发送大约10万个推送通知,而且从未遇到过任何问题

实现起来相当简单。它们非常有用,但摘要是在
pom.xml
文件中添加pushy作为依赖项:

<dependency>
    <groupId>com.eatthepath</groupId>
    <artifactId>pushy</artifactId>
    <version>0.13.11</version>
</dependency>  

com.eatthepath
,但我确实添加了评论:

// Add these lines as class properties  

// This creates the object that handles the sending of the push notifications.
// Use ApnsClientBuilder.PRODUCTION_APNS_HOST to send pushes to App Store apps
final ApnsClient apnsClient = new ApnsClientBuilder()
        .setApnsServer(ApnsClientBuilder.DEVELOPMENT_APNS_HOST)
        .setClientCredentials(new File("/path/to/certificate.p12"), "p12-file-password")
        .build();  

// The push notification
final SimpleApnsPushNotification pushNotification;  

// In some method:  

// Creating the object that builds the APNs payload
final ApnsPayloadBuilder payloadBuilder = new ApnsPayloadBuilder();  

// setting the text of the push
payloadBuilder.setAlertBody("Example!");  

// Builds the anps payload for the push notification
final String payload = payloadBuilder.build();  

// The push token of the device you're sending the push to
final String token = TokenUtil.sanitizeTokenString("<efc7492 bdbd8209>");  

// Creating the push notification object using the push token, your app's bundle ID, and the APNs payload
pushNotification = new SimpleApnsPushNotification(token, "com.example.myApp", payload);  

try {
    // Asking the APNs client to send the notification 
    // and creating the future that will return the status 
    // of the push after it's sent.  
    // (It's a long line, sorry)
    final PushNotificationFuture<SimpleApnsPushNotification, PushNotificationResponse<SimpleApnsPushNotification>> sendNotificationFuture = apnsClient.sendNotification(pushNotification);  

    // getting the response from APNs 
    final PushNotificationResponse<SimpleApnsPushNotification> pushNotificationResponse = sendNotificationFuture.get();
    if (pushNotificationResponse.isAccepted()) {
        System.out.println("Push notification accepted by APNs gateway.");
    } else {
        System.out.println("Notification rejected by the APNs gateway: " +
                pushNotificationResponse.getRejectionReason());

        if (pushNotificationResponse.getTokenInvalidationTimestamp() != null) {
            System.out.println("\t…and the token is invalid as of " +
                pushNotificationResponse.getTokenInvalidationTimestamp());
        }
    }
} catch (final ExecutionException e) {
    System.err.println("Failed to send push notification.");
    e.printStackTrace();
}
//将这些行添加为类属性
//这将创建处理推送通知发送的对象。
//使用ApnsClientBuilder.PRODUCTION\u APNS\u主机向应用商店应用发送推送
最终ApnsClient ApnsClient=新的ApnsClientBuilder()
.setApnsServer(ApnsClientBuilder.DEVELOPMENT\u APNS\u主机)
.setClientCredentials(新文件(“/path/to/certificate.p12”),“p12文件密码”)
.build();
//推送通知
最终SimpleAppushNotification推送通知;
//在某些方法中:
//创建构建APNs有效负载的对象
最终ApnsPayloadBuilder payloadBuilder=新ApnsPayloadBuilder();
//设置推送的文本
setAlertBody(“示例!”);
//为推送通知生成anps有效负载
最终字符串有效载荷=payloadBuilder.build();
//要向其发送推送的设备的推送令牌
final String token=TokenUtil.sanitizeTokenString(“”);
//使用推送令牌、应用程序包ID和APNs负载创建推送通知对象
pushNotification=new SimpleAppsPushNotification(标记“com.example.myApp”,有效负载);
试一试{
//请求APNs客户端发送通知
//创造一个未来,让我们回到过去
//发送后的推送。
//(对不起,队伍很长)
最终PushNotificationFuture sendNotificationFuture=apnsClient.sendNotification(pushNotification);
//从APNs获取响应
final PushNotificationResponse PushNotificationResponse=sendNotificationFuture.get();
if(pushNotificationResponse.isAccepted()){
System.out.println(“APNs网关接受推送通知”);
}否则{
System.out.println(“APNs网关拒绝的通知:”+
pushNotificationResponse.getRejectionReason());
if(pushNotificationResponse.getTokenInvalidationTimestamp()!=null){
System.out.println(“\t…”和令牌截至无效”+
pushNotificationResponse.getTokenInvalidationTimestamp());
}
}
}捕获(最终执行例外){
System.err.println(“未能发送推送通知”);
e、 printStackTrace();
}

我需要在不使用任何外部库的情况下使用证书向APNS发送推送消息您是否尝试过此方法?\@arturdev在
--cert
中,cert的文件格式是什么
.p12
.cert
.pem
?它可以是组合的.pam或组合的.p12。您可以使用轻松地为您的应用程序生成它们app@arturdev我可以使用curl发送推送,但我需要从SpringBoot应用程序发送推送。我怎么能这么做?我不想使用任何图书馆。你知道后面的把手有多用力吗?他们是否打开插座,进行TLS握手等等?或者他们使用不同的方法?我不太清楚他们是如何做到的,但是如果您查看他们的
ApnsClientBuilder
类,您可以阅读一些他们为TLS设置凭据的代码。图书馆也有很好的文档记录,里面应该有一些线索。如果我有更多的空闲时间,我会搜索并找出答案,但不幸的是我没有。