json 封装和解析dataList数据

java 后台编写IOS信息推送所需要的包:

bcprov-jdk16-145.jar  commons-io-2.0.1.jar  commons-lang-2.1.jar  javapns-jdk16-163.jar log4j-1.2.12.jar

下载见附件

 

单个信息推送和批量信息推送代码如下:

//单个发送
	public boolean postTsxxOne(XxtsDomain domain) throws Exception{
		boolean flag = true;
		//连接APNS
		PushNotificationManager pushManager = PushNotificationManager.getInstance();
		try{
	        //String host = "gateway.sandbox.push.apple.com"; //测试
	        String host = "gateway.push.apple.com";		//真正运行
	        int port = 2195;
	        
	        String path=this.getClass().getResource("/").getPath();//得到d:/tomcat/webapps/工程名WEB-INF/classes/路径
	        path=path.substring(1, path.indexOf("WEB-INF/classes"));//从路径字符串中取出工程路劲
	        String certificatePath = path +"zsxx/newTax.p12";//前面生成的用于JAVA后台连接APNS服务的*.p12文件位置
	        String certificatePassword = "123456";//p12文件密码。
	        pushManager.initializeConnection(host, port, certificatePath,certificatePassword, SSLConnectionHelper.KEYSTORE_TYPE_PKCS12);
			
			//消息封装 发送
			PayLoad payLoad = new PayLoad();
			payLoad.addAlert("智税提醒,您有新消息");
			payLoad.addBadge(domain.getMessCount());//消息推送标记数,小红圈中显示的数字。
			payLoad.addSound("default");
			//注册deviceToken
			pushManager.addDevice("iPhone" + domain.getUserId(), domain.getSbsbm()); //deviceToken sbsbm
			Device client = pushManager.getDevice("iPhone" + domain.getUserId());
			pushManager.sendNotification(client, payLoad);
			log.warn("userId:" + domain.getUserId() + " Push Success");
		}catch (Exception ex){
			log.error("userId:" + domain.getUserId() + " Push Fail");
	        ex.printStackTrace();
	        flag = false;
	    }finally{
	    	pushManager.stopConnection(); 
			pushManager.removeDevice("iPhone" + domain.getUserId());
	    }
	    
	    return flag;
	}
	
	//批量发送
	public void postTsxxMore(List<XxtsDomain> dataList) throws Exception{
		System.out.println("Push Start");
		//连接APNS
		PushNotificationManager pushManager = PushNotificationManager.getInstance();
        //String host = "gateway.sandbox.push.apple.com"; //测试
        String host = "gateway.push.apple.com";		//真正运行
        int port = 2195;
        
        String path=this.getClass().getResource("/").getPath();//得到d:/tomcat/webapps/工程名WEB-INF/classes/路径
        path=path.substring(1, path.indexOf("WEB-INF/classes"));//从路径字符串中取出工程路劲
        String certificatePath = path +"zsxx/newTax.p12";//前面生成的用于JAVA后台连接APNS服务的*.p12文件位置
        
        String certificatePassword = "123456";//p12文件密码。
        pushManager.initializeConnection(host, port, certificatePath,certificatePassword, SSLConnectionHelper.KEYSTORE_TYPE_PKCS12);
		
		//消息封装 发送
		for(XxtsDomain domain : dataList) {
			 PayLoad payLoad = new PayLoad();
	         payLoad.addAlert("智税提醒,您有新消息");
	         payLoad.addBadge(domain.getMessCount());//消息推送标记数,小红圈中显示的数字。
	         payLoad.addSound("default");
	         //注册deviceToken
	         pushManager.addDevice("iPhone" + domain.getUserId(), domain.getSbsbm()); //deviceToken sbsbm
	         Device client = pushManager.getDevice("iPhone" + domain.getUserId());
	         pushManager.sendNotification(client, payLoad);
		}
		
		pushManager.stopConnection(); 
		for (int i = 0; i < dataList.size(); i++) { 
			pushManager.removeDevice("iPhone" + dataList.get(i).getUserId());
		}
		System.out.println("Push End");
	}

 

 

你可能感兴趣的:(datalist)