- 浏览: 2539839 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
APNS(4)Recall the Process and Learn Java APNS
1. Process about the Certificate File
Generate the Certificate Signing Request(CSR) --- xxxx.certSigningRequest
Export the p12 private key --- xxxx.p12
Upload my xxxx.certSigningRequest file to Apple and generate the certificate
--- xxxx.cer
Based on the certSigningRequest file and xxxx.p12 and xxxx.cer I will generate the PEM file
>xxxx.cer -----> xxxx1.pem
>xxxx,p12 -----> xxxx2.pem
Make the PEM file together
xxxx1.pem + xxxx2.pem ----> xxxx.pem
That is the whole process.
2. Process to Deal directly with the p12
Open the keychain Access ---> Request a Certificate Information from Authority Certificate ---> Output: CertificateSigningRequest.certSigningRequest
Open the keychain Access ---> login ----> Keys ---> [Command Name] private key ----> Export to p12 file Output:
[Command Name].p12
Logon to Apple ----> identifiers -----> App IDs ----> Settings ----> Create Certificate ---- Upload my xxxxx.certSigningRequest file
aps_development.cer
That is right. Then based on p12 and CER, I will generate 2 PEM files. And make 2 PEM together into 1. That is done.
3. JavaPNS
Basic Push Notification
Configure the pom.xml to be
<dependency> <groupId>com.google.code</groupId> <artifactId>javapns</artifactId> <version>2.2</version>
</dependency>
And the basic simple implementation is as follow:
package com.sillycat.easyrestserver.main;
import javapns.Push;
import javapns.communication.exceptions.CommunicationException;
import javapns.communication.exceptions.KeystoreException;
publicclass PushTestMain {
publicstaticvoid main(String[] args) {
try { Push.alert( "Hello World!", "[file directory and name].p12", "password", false, "APNS token from the device"); } catch (CommunicationException e) { e.printStackTrace(); } catch (KeystoreException e) { e.printStackTrace(); } } }
Error Message:
04-17 11:20:08 [ERROR] javapns.notification.PushNotificationManager.sendNotification(PushNotificationManager.java:426) - Attempt to send Notification failed and beyond the maximum number of attempts permitted
04-17 11:20:08 [ERROR] javapns.notification.PushNotificationManager.sendNotification(PushNotificationManager.java:429) - Delivery error
javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:174)
at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:136)
Solution:
>openssl x509 -in aps_development.cer -inform DER -out developer_identity.pem -outform PEM
>openssl pkcs12 -nocerts -in EasyiOSSampleKey.p12 -out mykey.pem
>openssl pkcs12 -export -inkey mykey.pem -in developer_identity.pem -out EasyiOSSampleKey_final.p12
The means do not directly use the p12 from the private key, In my PHP example, I used PEM file based on the CER from apple and p12 from my private key.
Almost the same process to generate the P12, also based on the CER from apple and p12 from my private key.
In the class Push, there are methods alert, badge, sound, combined and etc.
Advanced Push Notification
PushNotificationPayload payload = PushNotificationPayload.complex();
playload.addBadge(int badge)
playload.addSound(String sound)
playload.addAlert(String message)
List<PushedNotification]]> notifications = Push.payload(payload, keystore, password, production, devices);
Send Multiple Message
private static void sendMultiple(){
PushNotificationPayload payload = PushNotificationPayload.complex(); try { payload.addAlert(DEFAULT_MESSAGE); payload.addSound("default"); payload.addBadge(1); } catch (JSONException e1) { e1.printStackTrace(); } int threads = 2; List<Device> devices = new ArrayList<Device>(); try { devices.add(new BasicDevice(DEFAULT_TOKEN)); } catch (InvalidDeviceTokenFormatException e1) { e1.printStackTrace(); } try { List<PushedNotification> notifications = Push.payload(payload, P12_FILE, DEFAULT_PASSWORD, false, threads, devices); System.out.println(notifications); } catch (Exception e) { e.printStackTrace(); }
}
Creating a push queue
PushNotificationPayload payload = PushNotificationPayload.alert("Hello World!");
int threads = 30;
PushQueue queue = Push.queue(keystore, password, production, threads);
queue.start();
queue.add(payload, token);
private static void sendQueue() {
PushNotificationPayload payload = PushNotificationPayload.complex(); try { payload.addAlert(DEFAULT_MESSAGE); payload.addSound("default"); payload.addBadge(1); } catch (JSONException e1) { e1.printStackTrace(); } int threads = 2; PushQueue queue = null; try { queue = Push.queue(P12_FILE, DEFAULT_PASSWORD, false, threads); queue.start(); queue.add(payload, DEFAULT_TOKEN); } catch (KeystoreException e) { e.printStackTrace(); } catch (InvalidDeviceTokenFormatException e) { e.printStackTrace(); } try { Thread.sleep(10* 1000); } catch (InterruptedException e) { e.printStackTrace(); }
}
References:
http://sillycat.iteye.com/blog/1769158
http://sillycat.iteye.com/blog/1769163
http://sillycat.iteye.com/blog/1769781
javaPNS
https://code.google.com/p/javapns/
https://code.google.com/p/javapns/wiki/PushNotificationBasic
https://code.google.com/p/javapns/wiki/PushNotificationAdvanced
http://www.raywenderlich.com/3525/apple-push-notification-services-tutorial-part-2
http://stackoverflow.com/questions/12585858/cannot-send-push-notifications-using-javapns-javaapns-ssl-handshake-failure
1. Process about the Certificate File
Generate the Certificate Signing Request(CSR) --- xxxx.certSigningRequest
Export the p12 private key --- xxxx.p12
Upload my xxxx.certSigningRequest file to Apple and generate the certificate
--- xxxx.cer
Based on the certSigningRequest file and xxxx.p12 and xxxx.cer I will generate the PEM file
>xxxx.cer -----> xxxx1.pem
>xxxx,p12 -----> xxxx2.pem
Make the PEM file together
xxxx1.pem + xxxx2.pem ----> xxxx.pem
That is the whole process.
2. Process to Deal directly with the p12
Open the keychain Access ---> Request a Certificate Information from Authority Certificate ---> Output: CertificateSigningRequest.certSigningRequest
Open the keychain Access ---> login ----> Keys ---> [Command Name] private key ----> Export to p12 file Output:
[Command Name].p12
Logon to Apple ----> identifiers -----> App IDs ----> Settings ----> Create Certificate ---- Upload my xxxxx.certSigningRequest file
aps_development.cer
That is right. Then based on p12 and CER, I will generate 2 PEM files. And make 2 PEM together into 1. That is done.
3. JavaPNS
Basic Push Notification
Configure the pom.xml to be
<dependency> <groupId>com.google.code</groupId> <artifactId>javapns</artifactId> <version>2.2</version>
</dependency>
And the basic simple implementation is as follow:
package com.sillycat.easyrestserver.main;
import javapns.Push;
import javapns.communication.exceptions.CommunicationException;
import javapns.communication.exceptions.KeystoreException;
publicclass PushTestMain {
publicstaticvoid main(String[] args) {
try { Push.alert( "Hello World!", "[file directory and name].p12", "password", false, "APNS token from the device"); } catch (CommunicationException e) { e.printStackTrace(); } catch (KeystoreException e) { e.printStackTrace(); } } }
Error Message:
04-17 11:20:08 [ERROR] javapns.notification.PushNotificationManager.sendNotification(PushNotificationManager.java:426) - Attempt to send Notification failed and beyond the maximum number of attempts permitted
04-17 11:20:08 [ERROR] javapns.notification.PushNotificationManager.sendNotification(PushNotificationManager.java:429) - Delivery error
javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:174)
at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:136)
Solution:
>openssl x509 -in aps_development.cer -inform DER -out developer_identity.pem -outform PEM
>openssl pkcs12 -nocerts -in EasyiOSSampleKey.p12 -out mykey.pem
>openssl pkcs12 -export -inkey mykey.pem -in developer_identity.pem -out EasyiOSSampleKey_final.p12
The means do not directly use the p12 from the private key, In my PHP example, I used PEM file based on the CER from apple and p12 from my private key.
Almost the same process to generate the P12, also based on the CER from apple and p12 from my private key.
In the class Push, there are methods alert, badge, sound, combined and etc.
Advanced Push Notification
PushNotificationPayload payload = PushNotificationPayload.complex();
playload.addBadge(int badge)
playload.addSound(String sound)
playload.addAlert(String message)
List<PushedNotification]]> notifications = Push.payload(payload, keystore, password, production, devices);
Send Multiple Message
private static void sendMultiple(){
PushNotificationPayload payload = PushNotificationPayload.complex(); try { payload.addAlert(DEFAULT_MESSAGE); payload.addSound("default"); payload.addBadge(1); } catch (JSONException e1) { e1.printStackTrace(); } int threads = 2; List<Device> devices = new ArrayList<Device>(); try { devices.add(new BasicDevice(DEFAULT_TOKEN)); } catch (InvalidDeviceTokenFormatException e1) { e1.printStackTrace(); } try { List<PushedNotification> notifications = Push.payload(payload, P12_FILE, DEFAULT_PASSWORD, false, threads, devices); System.out.println(notifications); } catch (Exception e) { e.printStackTrace(); }
}
Creating a push queue
PushNotificationPayload payload = PushNotificationPayload.alert("Hello World!");
int threads = 30;
PushQueue queue = Push.queue(keystore, password, production, threads);
queue.start();
queue.add(payload, token);
private static void sendQueue() {
PushNotificationPayload payload = PushNotificationPayload.complex(); try { payload.addAlert(DEFAULT_MESSAGE); payload.addSound("default"); payload.addBadge(1); } catch (JSONException e1) { e1.printStackTrace(); } int threads = 2; PushQueue queue = null; try { queue = Push.queue(P12_FILE, DEFAULT_PASSWORD, false, threads); queue.start(); queue.add(payload, DEFAULT_TOKEN); } catch (KeystoreException e) { e.printStackTrace(); } catch (InvalidDeviceTokenFormatException e) { e.printStackTrace(); } try { Thread.sleep(10* 1000); } catch (InterruptedException e) { e.printStackTrace(); }
}
References:
http://sillycat.iteye.com/blog/1769158
http://sillycat.iteye.com/blog/1769163
http://sillycat.iteye.com/blog/1769781
javaPNS
https://code.google.com/p/javapns/
https://code.google.com/p/javapns/wiki/PushNotificationBasic
https://code.google.com/p/javapns/wiki/PushNotificationAdvanced
http://www.raywenderlich.com/3525/apple-push-notification-services-tutorial-part-2
http://stackoverflow.com/questions/12585858/cannot-send-push-notifications-using-javapns-javaapns-ssl-handshake-failure
发表评论
-
ionic UI(5)UI and Backend
2016-12-02 03:22 590ionic UI(5)UI and Backend 1 Pr ... -
Stanford Cource(2)Demo App Caculator
2014-06-24 01:29 897Stanford Cource(2)Demo App Ca ... -
Mono on MAC
2014-06-04 03:27 974Mono on MACJust fine the tool f ... -
IOS7 App Development Essentials(4)IPhone5, IPhone5s, IPhone5c
2014-04-11 03:59 982IOS7 App Development Essentia ... -
IOS7 App Development Essentials(3)NSUserDefaults
2014-04-11 02:58 1005IOS7 App Development Essentia ... -
IPhone and Location(2)Documents Region Monitoring and Region Sample
2013-10-18 05:10 1727IPhone and Location(2)Documents ... -
IPhone and Location(1)Documents User Location
2013-10-18 03:50 1304IPhone and Location(1)Documents ... -
Learn Objective C(6)Programming with Objective-C - Working with Blocks and Deali
2013-10-18 00:02 924Learn Objective C(6)Programming ... -
Learn Objective C(5)Programming with Objective-C - Working with Protocols and Va
2013-10-17 23:47 996Learn Objective C(5)Programming ... -
Learn Objective C(4)Programming with Objective-C - Encapsulating Data and Custom
2013-10-17 23:23 934Learn Objective C(4)Programming ... -
Learn Objective C(3)Programming with Objective-C - Defining Classes, Working wit
2013-10-17 23:09 1014Learn Objective C(3)Programmi ... -
Learn Objective C(2)Learn Objective-C in Day 6 - 4 ~ 6
2013-10-17 00:30 960Learn Objective C(2)Learn Obj ... -
Learn Object C(1) Learn Objective-C in Day 6 - 1 ~ 3
2013-10-17 00:22 1110Learn Object C(1) Learn Objec ... -
Build the iOS Things with J2Objc
2013-04-12 03:25 2463Build the iOS Things with J2Obj ... -
APNS(3)Write the Easy Client App
2013-01-15 07:23 1693APNS(3)Write the Easy Client Ap ... -
APNS(2)Try to Finish the first Example
2013-01-14 07:56 1537APNS(2)Try to Finish the first ... -
Stanford Cource(1)MVC and Object-C
2012-12-14 14:04 1318Stanford Cource(1)MVC and Objec ... -
Some VI Tips
2012-11-15 04:48 1093Some VI Tips Today, I need to c ... -
MAC Mini Setup
2012-09-25 18:45 1326MAC Mini Setup I am dealing wit ... -
Android Talker(1)MAC Environment
2012-09-01 00:16 1921Android Talker(1)MAC Environmen ...
相关推荐
apns4j 是 Apple Push Notification Service 的 Java 实现!Maven: <groupId>com.github.teaey</groupId> <artifactId>apns4j <version>1.0.1 示例代码:KeyStoreWraper keyStore = ...
Java整合APNS推送服务是将Java应用程序与Apple Push Notification Service(APNS)相结合,以便能够向iOS和tvOS设备发送即时消息。APNS是苹果公司提供的一个服务,它允许开发者在用户不打开应用的情况下,向他们的...
在Java中实现APNs推送,我们可以使用第三方库如`Java-APNS`或`Apns4j`,它们封装了与APNs交互的复杂过程,使代码更加简洁。不过,如果你选择自己实现,需要注意以下几点: - **错误处理**:APNs服务器对推送消息有...
在Java开发环境中,当需要构建一个能够向Apple Push Notification Service (APNS)发送推送通知的服务时,`notnoop-java-apns`是一个常用的第三方库。这个压缩包`notnoop-java-apns.zip`包含了开发者用于实现这一功能...
4. **构建推送请求**:根据APNs规范创建一个JSON对象,包含必要的通知字段。例如: ```json { "aps": { "alert": { "title": "通知标题", "body": "通知正文" }, "sound": "default" }, "topic": ...
2. **Java APNs库**:描述中的"iphone_apns_send"可能是用于Java的APNs库,如`Apns4j`或`JavaAPNS`。这些库封装了与APNs服务器交互的复杂过程,包括证书处理、错误处理和消息构建。例如,`Apns4j`提供了简单易用的...
该项目是一款基于Java语言实现的苹果推送服务APNS客户端库——APNS4J的设计源码,共包含37个文件,主要包括31个Java源文件、1个Git忽略文件、1个YAML配置文件、1个LICENSE文件、1个README文本文件、1个Markdown文件...
Java进行苹果APNS(Apple Push Notification Service)消息推送是一项在iOS和macOS应用程序中实现远程通知功能的关键技术。本文将详细介绍如何使用Java实现这一过程,同时关注`javapns`库和`bcprov-jdk`加密组件的...
一个Java库,用于使用Apple的新HTTP / 2 API通过APNS发送通知。 该库使用OkHttp。 以前的版本包括对Jetty客户端的支持,但是,由于Jetty客户端的不稳定,我们已将其删除。 注意:确保引导类路径中包含Jetty的ALPN ...
利用socket 推送消息到 苹果的服务器。APNS 协议。支持失败重新发送。批量发送等。
java(后台) ios 推送(APNS) 源码+支持jar包,代码经测试没问题,包含4个jar包:javaAPNS2.2、log4j、org.bouncycastle.jce1.39.0、apache.common.lang所属包
Java APNS Eclipse项目是一个使用Java语言在Eclipse集成开发环境中构建的Apple Push Notification Service(APNs)服务器应用程序。APNs是苹果公司提供的服务,用于向iOS、iPadOS、watchOS和macOS设备发送即时推送...
Java APNS,全称为Apple Push Notification service,是苹果公司提供的一项服务,允许应用程序开发者向iOS、iPadOS、watchOS和macOS设备发送实时通知。在Java中实现APNS服务器,可以让我们利用Java强大的编程能力来...
"notnoop-java-apns-0.1.4"是一个针对苹果推送通知服务(Apple Push Notification Service,简称APNS)的Java实现库。这个库由notnoop开发者创建,版本号为0.1.4,旨在帮助Java开发者更方便地集成和管理APNS服务,...
**苹果推送通知服务(Apple Push Notification service,简称APNS)** APNS是苹果公司提供的一项服务,用于向iOS、iPadOS、watchOS、tvOS以及macOS设备推送通知。通过APNS,应用开发者可以在他们的应用不在前台运行...
APNSPHP是一个专门为苹果推送通知服务(Apple Push Notification service,简称APNs)设计的PHP库。这个库的主要目的是帮助PHP开发者方便地与苹果服务器进行通信,以便向iOS、macOS和watchOS设备发送推送通知。从...
在Java中实现APNS推送,你可以使用开源库,例如`com.notnoop.apns`(Apns4j)或`io.github.relayrides:pushy`。以下是一个基本的使用流程: 1. **导入依赖**:在项目中添加对应的库依赖,比如Pushy。 2. **加载...
Apple APNs java client, based on netty4. 基于netty4实现的苹果通知推送服务Java客户端。 特点: 支持第三版通知推送,即command = 2。目前的绝大部分Java客户端都只支持command = 1,即第二版。 ...
.NET APNS推送是一个基于.NET框架实现的用于向Apple Push Notification Service (APNS)发送推送通知的项目。APNS是苹果公司提供的服务,允许开发者通过云端将实时消息推送到iOS、iPadOS、watchOS以及macOS设备上的...
然后dbay-apns4j来了。 我认为这是最好的。特征高性能且易于使用快速入门演示支持连接池中英双语注释,英语小白阅读起来也没问题支持错误后重新发送通知空闲时自动创建新的套接字支持反馈服务支持沙盒和生产服务...