/**
*apple单独的推送方法
*@param token iphone手机获取的token
*@param content 推送消息的内容
*@param count 应用图标上小红圈上的数值
*param goal 目标服务器 true:正式 false:测试
*/
public boolean ApnsSend(String token,String content,int count ,boolean goal){
boolean b = false;
try{
String certificatePath="";
String certificatePassword="";
if(!goal){
//测试证书地址(.p12文件) +密码 你可以写成死的值在上边 F://文件名//证书名
certificatePath=PropertiesUtil.getProperty("testCertificatePath");
certificatePassword=PropertiesUtil.getProperty("testCertificatePwd");
}else{
//正式证书地址+密码
certificatePath=PropertiesUtil.getProperty("certificatePath");
certificatePassword=PropertiesUtil.getProperty("certificatePwd");
}
PushNotificationPayload payload = new PushNotificationPayload();
payload.addAlert(content);
payload.addSound("default");
payload.addBadge(count);
PushNotificationManager pushManager = new PushNotificationManager();
//true:表示的是产品发布推送服务 false:表示的是产品测试推送服务
pushManager.initializeConnection(new AppleNotificationServerBasicImpl(certificatePath, certificatePassword, goal));
List<PushedNotification> notifications = new ArrayList<PushedNotification>();
Device device = new BasicDevice();
device.setToken(token);
PushedNotification notification = pushManager.sendNotification(device, payload, true);
notifications.add(notification);
List<PushedNotification> successfulNotifications = PushedNotification.findSuccessfulNotifications(notifications);
int successful = successfulNotifications.size();
if(successful>0){
b=true;
}else{
b=false;
}
}catch(Exception e){
return b;
}
return b;
}
/**
* @param args
* 测试主函数
*/
public static void main(String[] args) {
PhonePush pp = new PhonePush();
String token="76edc85fd2e6704b27974d774cc046d7e33a3440fd6f39ba18c729387e6c788a";
//String token="自己手机的tokens";
String content="测试iphone推送"; //推送内容
int count=10;//应用图标上小红圈上的数值
boolean goal=false; //测试服务器false 正式服务器 ture
boolean b = pp.ApnsSend(token, content, count, goal);
System.out.println(b);
}
java做的iphone推送,水平有限,单个推送还可以,上万的推送写的线程不知道怎么样,高人可一指点下。
最新推荐文章于 2020-04-17 12:37:48 发布