java实现apns消息推送


import javapns.back.PushNotificationManager;
import javapns.back.SSLConnectionHelper;
import javapns.data.Device;
import javapns.data.PayLoad;

public class a {

public static void main(String[] args) throws Exception {
try {
// 从客户端获取的deviceToken,在此为了测试简单,写固定的一个测试设备标识。
String deviceToken = "b606c95c4b3956de89d67ecfa02811ebc5d1a09c6f832c3be67b1d9554a66683";
System.out.println("Push Start deviceToken:" + deviceToken);
// 定义消息模式
PayLoad payLoad = new PayLoad();
payLoad.addAlert("this is test!");
payLoad.addBadge(1);// 消息推送标记数,小红圈中显示的数字。
payLoad.addSound("default");
// 注册deviceToken
PushNotificationManager pushManager = PushNotificationManager.getInstance();
pushManager.addDevice("iPhone", deviceToken);
// 连接APNS
String host = "gateway.sandbox.push.apple.com";
// String host = "gateway.push.apple.com";
int port = 2195;
String certificatePath = "E:/123.p12";// 前面生成的用于JAVA后台连接APNS服务的*.p12文件位置
String certificatePassword = "8dbmds";// p12文件密码。
pushManager.initializeConnection(host, port, certificatePath, certificatePassword, SSLConnectionHelper.KEYSTORE_TYPE_PKCS12);
// 发送推送 991847304
Device client = pushManager.getDevice("iPhone");
System.out.println("推送消息: " + client.getToken() + "\n" + payLoad.toString() + " ");
pushManager.sendNotification(client, payLoad);
// 停止连接APNS
pushManager.stopConnection();
// 删除deviceToken
pushManager.removeDevice("iPhone");
System.out.println("Push End");
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值