jsp推送iOS消息
来源:互联网 发布:重庆知秋凤凰婚礼 编辑:程序博客网 时间:2024/03/29 04:32
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.List" %>
<%@ page import="org.apache.commons.lang.StringUtils" %>
<%@ page import="javapns.Push" %>
<%@ page import="javapns.devices.Device" %>
<%@ page import="javapns.devices.implementations.basic.BasicDevice" %>
<%@ page import="javapns.notification.AppleNotificationServerBasicImpl" %>
<%@ page import="javapns.notification.PushNotificationPayload" %>
<%@ page import="javapns.notification.PushNotificationManager" %>
<%@ page import="org.apache.commons.lang.StringUtils" %>
<%@ page import="javapns.notification.PushedNotification" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
String deviceToken = "AAAA5064209B6165C8542A9A17118BFFFFFE99851A9BD124B26CE6A6F84DDDDD";
String alert = "this is test push message";//push的内容
int badge = 3;//图标小红圈的数值
String sound = "default";//铃音
List<String> tokens = new ArrayList<String>();
tokens.add(deviceToken);
String certificatePath = "D:\\etah\\P12\\iOS-development-cert.p12";
String certificatePassword = "123456";//此处注意导出的证书密码不能为空因为空密码会报错
boolean sendCount = true;
try
{
PushNotificationPayload payLoad = new PushNotificationPayload();
payLoad.addAlert(alert); // 消息内容
payLoad.addBadge(badge); // iphone应用图标上小红圈上的数值
if (!StringUtils.isBlank(sound))
{
payLoad.addSound(sound);//铃音
}
PushNotificationManager pushManager = new PushNotificationManager();
//true:表示的是产品发布推送服务 false:表示的是产品测试推送服务
pushManager.initializeConnection(new AppleNotificationServerBasicImpl(certificatePath, certificatePassword, false));
List<PushedNotification> notifications = new ArrayList<PushedNotification>();
// 发送push消息
if (sendCount)
{
Device device = new BasicDevice();
device.setToken(tokens.get(0));
PushedNotification notification = pushManager.sendNotification(device, payLoad, true);
notifications.add(notification);
}
else
{
List<Device> device = new ArrayList<Device>();
for (String token : tokens)
{
device.add(new BasicDevice(token));
}
notifications = pushManager.sendNotifications(payLoad, device);
}
pushManager.stopConnection();
}
catch (Exception ex)
{
ex.printStackTrace();
}
%>
</body>
</html>
pageEncoding="UTF-8"%>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.List" %>
<%@ page import="org.apache.commons.lang.StringUtils" %>
<%@ page import="javapns.Push" %>
<%@ page import="javapns.devices.Device" %>
<%@ page import="javapns.devices.implementations.basic.BasicDevice" %>
<%@ page import="javapns.notification.AppleNotificationServerBasicImpl" %>
<%@ page import="javapns.notification.PushNotificationPayload" %>
<%@ page import="javapns.notification.PushNotificationManager" %>
<%@ page import="org.apache.commons.lang.StringUtils" %>
<%@ page import="javapns.notification.PushedNotification" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
String deviceToken = "AAAA5064209B6165C8542A9A17118BFFFFFE99851A9BD124B26CE6A6F84DDDDD";
String alert = "this is test push message";//push的内容
int badge = 3;//图标小红圈的数值
String sound = "default";//铃音
List<String> tokens = new ArrayList<String>();
tokens.add(deviceToken);
String certificatePath = "D:\\etah\\P12\\iOS-development-cert.p12";
String certificatePassword = "123456";//此处注意导出的证书密码不能为空因为空密码会报错
boolean sendCount = true;
try
{
PushNotificationPayload payLoad = new PushNotificationPayload();
payLoad.addAlert(alert); // 消息内容
payLoad.addBadge(badge); // iphone应用图标上小红圈上的数值
if (!StringUtils.isBlank(sound))
{
payLoad.addSound(sound);//铃音
}
PushNotificationManager pushManager = new PushNotificationManager();
//true:表示的是产品发布推送服务 false:表示的是产品测试推送服务
pushManager.initializeConnection(new AppleNotificationServerBasicImpl(certificatePath, certificatePassword, false));
List<PushedNotification> notifications = new ArrayList<PushedNotification>();
// 发送push消息
if (sendCount)
{
Device device = new BasicDevice();
device.setToken(tokens.get(0));
PushedNotification notification = pushManager.sendNotification(device, payLoad, true);
notifications.add(notification);
}
else
{
List<Device> device = new ArrayList<Device>();
for (String token : tokens)
{
device.add(new BasicDevice(token));
}
notifications = pushManager.sendNotifications(payLoad, device);
}
pushManager.stopConnection();
}
catch (Exception ex)
{
ex.printStackTrace();
}
%>
</body>
</html>
阅读全文
0 0
- jsp推送iOS消息
- IOS推送消息 php推送
- ios 推送消息 php推送
- ios 推送消息 极光推送/百度推送
- ios推送消息
- iOS消息推送
- iOS消息推送
- iOS推送消息实现
- iOS php消息推送
- IOS推送消息
- IOS消息推送
- iOS 消息推送
- ios消息推送
- IOS消息推送
- iOS 消息推送原理
- iOS 消息推送原理
- iOS 消息推送通知
- iOS消息推送
- android 获取手机中的所有图片或某一目录下的图片
- bzoj4031: [HEOI2015]小Z的房间
- 三子棋游戏(简单)————C语言实现
- Codeforces 897C Nephren gives a riddle(dfs)
- [SCOI2010]连续攻击游戏
- jsp推送iOS消息
- python
- ORB-SLAM2详解1 框架说明
- 打包依赖.aar文件以及坑总结
- codeforces 897 B. Chtholly's request【构造回文数+递推】
- RAC中集合的操作
- Hibernate的学习之路三十二(HQL的聚合函数查询)
- 为可执行程序(sys/exe)生成公有调试符号
- ip