苹果APNs消息推送
代码实现
maven引入第三方库
<dependency>
<groupId>com.eatthepath</groupId>
<artifactId>pushy</artifactId>
<version>0.15.4</version>
</dependency>
代码示例
InputStream certificateStream;
// 设备token
String deviceToken = "";
try {
// .p12文件路径
URL url = new URL("");
HttpURLConnection uc = (HttpURLConnection) url.openConnection();
//设置是否要从 URL 连接读取数据,默认为true
uc.setDoInput(true);
uc.connect();
certificateStream = uc.getInputStream();
final ApnsClient apnsClient = new ApnsClientBuilder()
.setApnsServer(ApnsClientBuilder.DEVELOPMENT_APNS_HOST)
.setClientCredentials(certificateStream, "1234")
.build();
final SimpleApnsPushNotification pushNotification = new SimpleApnsPushNotification(
deviceToken, // 设备token
"", // 主题(包名)
"{\"aps\":{\"alert\":\"Hello World!!!\"}}" // 载荷
);
final PushNotificationFuture<SimpleApnsPushNotification, PushNotificationResponse<SimpleApnsPushNotification>>
sendNotificationFuture = apnsClient.sendNotification(pushNotification);
sendNotificationFuture.thenAccept(response -> {
// 处理响应
System.out.println(response);
});
} catch (Exception e) {
e.printStackTrace();
}
原文地址:https://blog.csdn.net/weixin_43833540/article/details/143757979
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!