我可以毫无错误地发送通知,但我的设备上没有任何内容。我尝试了很多解决方案,但我不知道还能做些什么。
证书和令牌在PHP中有效... 配置:Java 1.8,Tomcat 7,Javapns 2.2
由于
代码
BasicConfigurator.configure();
URL res = getClass().getClassLoader().getResource("KeyNotification/certificat.p12");
File f = new File(res.getFile());
List<PushedNotification> notifications = Push.combined("message", 10, "", f.getAbsolutePath(), "password", false, token);
for (PushedNotification notification : notifications) {
if (notification.isSuccessful()) {
System.out.println("Push notification sent successfully to: " + notification.getDevice().getToken());
} else {
String invalidToken = notification.getDevice().getToken();
Exception theProblem = notification.getException();
theProblem.printStackTrace();
/* If the problem was an error-response packet returned by Apple, get it */
ResponsePacket theErrorResponse = notification.getResponse();
if (theErrorResponse != null) {
System.out.println(theErrorResponse.getMessage());
}
}
}
日志
0 [http-bio-8080-exec-21] DEBUG javapns.communication.ConnectionToAppleServer - Creating SSLSocketFactory
3 [http-bio-8080-exec-21] DEBUG javapns.communication.ConnectionToAppleServer - Creating SSLSocket to feedback.sandbox.push.apple.com:2196
1189 [http-bio-8080-exec-21] DEBUG javapns.feedback.FeedbackServiceManager - Found: [0]
1194 [http-bio-8080-exec-21] DEBUG javapns.notification.Payload - Adding alert [message]
1194 [http-bio-8080-exec-21] DEBUG javapns.notification.Payload - Adding badge [10]
1194 [http-bio-8080-exec-21] DEBUG javapns.notification.Payload - Adding sound []
1199 [http-bio-8080-exec-21] DEBUG javapns.communication.ConnectionToAppleServer - Creating SSLSocketFactory
1201 [http-bio-8080-exec-21] DEBUG javapns.communication.ConnectionToAppleServer - Creating SSLSocket to gateway.sandbox.push.apple.com:2195
1444 [http-bio-8080-exec-21] DEBUG javapns.notification.PushNotificationManager - Initialized Connection to Host: [gateway.sandbox.push.apple.com] Port: [2195]: 1e816c94[SSL_NULL_WITH_NULL_NULL: Socket[addr=gateway.sandbox.push.apple.com/17.110.227.35,port=2195,localport=63887]]
1447 [http-bio-8080-exec-21] DEBUG javapns.notification.PushNotificationManager - Building Raw message from deviceToken and payload
1447 [http-bio-8080-exec-21] DEBUG javapns.notification.PushNotificationManager - Built raw message ID 1 of total length 98
1447 [http-bio-8080-exec-21] DEBUG javapns.notification.PushNotificationManager - Attempting to send notification: {"aps":{"badge":10,"alert":"message","sound":""}}
1447 [http-bio-8080-exec-21] DEBUG javapns.notification.PushNotificationManager - to device: 1d8e0488958b92297923884508bf3714835f3581101ede9d3155ded0d8241c3e
2315 [http-bio-8080-exec-21] DEBUG javapns.notification.PushNotificationManager - Flushing
2315 [http-bio-8080-exec-21] DEBUG javapns.notification.PushNotificationManager - At this point, the entire 98-bytes message has been streamed out successfully through the SSL connection
2315 [http-bio-8080-exec-21] DEBUG javapns.notification.PushNotificationManager - Notification sent on first attempt
2315 [http-bio-8080-exec-21] DEBUG javapns.notification.PushNotificationManager - Reading responses
7321 [http-bio-8080-exec-21] DEBUG javapns.notification.PushNotificationManager - Closing connection
Push notification sent successfully to: 1d8e0488958b92297923884508bf3714835f3581101ede9d3155ded0d8241c3e
答案 0 :(得分:0)
我解决了我的问题,证书不兼容!
创建证书的命令行(aps_development.pem是从Apple下载的,myprivatekey.p12是从我的应用程序私钥中导出的“Keychain Access”):
openssl x509 -in aps_development.cer -inform DER -out aps_development.pem -outform PEM
openssl pkcs12 -nocerts -in myprivatekey.p12 -out myprivatekey.pem
openssl pkcs12 -export -inkey myprivatekey.pem -in aps_development.pem -out cert_dev.p12