java做的iphone推送,水平有限,单个推送还可以,上万的推送写的线程不知道怎么样,高人可一指点下。

/**
     *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);
	}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值