国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

利用javapns對IOS進行推送

2019-11-14 20:39:37
字體:
來源:轉載
供稿:網友

start

package com.jynine.javapns;import java.io.FileNotFoundException;import java.io.IOException;import java.io.InputStream;import java.util.ArrayList;import java.util.List;import java.util.Map;import java.util.PRoperties;import javapns.Push;import javapns.communication.exceptions.CommunicationException;import javapns.communication.exceptions.KeystoreException;import javapns.devices.Device;import javapns.devices.Devices;import javapns.notification.PayloadPerDevice;import javapns.notification.PushNotificationPayload;import javapns.notification.transmission.PushQueue;import org.apache.commons.lang.StringUtils;import org.json.JSONException;public class IosPushUtil {	public static String keystore = null; 	public static String passWord = null; 	public static String host = null;	public static Boolean production = true;//true:production false: sandbox 	public static final int numberOfThreads = 8;	static{		Properties propertie = new Properties();		InputStream inputStream;				try {			inputStream = IosPushUtil.class.getClassLoader()					.getResourceAsStream("push.properties");			propertie.load(inputStream);			keystore = propertie.getProperty("certificatePath");			password = propertie.getProperty("certificatePassword","123456");			host = propertie.getProperty("host","gateway.push.apple.com");			production = Boolean.valueOf(propertie.getProperty("production", "true"));			inputStream.close();		} catch (FileNotFoundException ex) {			ex.printStackTrace();		} catch (IOException ex) {			ex.printStackTrace();		}	}	public static void main(String[] args) throws Exception {		//pushMsgNotification("hello!!!2", true, "iostoken");	//	pushBadgeNotification(1,  "iostoken");		String[] devs= new String[10000];		for (int i = 0; i < devs.length; i++) {		devs[i] = "iostoken";		}		List<Device> devices=Devices.asDevices(devs);		System.out.println(devices.size());		//pushPayLoadByThread(devices, "Hello 2222222", 1, null, null);		//pushPayloadDevicePairs(devices, "Hello 111111111", 1, null, null);		//pushPayloadDevicePairs(devices, "Hello +++", 1, null, null);		queue(devices,"Hello 2222222", 1, null, null);	}	/**	 * 推送一個簡單消息	 * @param msg 消息	 * @param devices 設備	 * @throws CommunicationException	 * @throws KeystoreException	 */	public static void pushMsgNotification(String msg,Object devices) throws CommunicationException, KeystoreException{		Push.alert(msg, keystore, password, production, devices);	}	/**	 * 推送一個標記	 * @param badge 標記	 * @param devices 設備	 * @throws CommunicationException	 * @throws KeystoreException	 */	public static void pushBadgeNotification(int badge,Object devices) throws CommunicationException, KeystoreException{		Push.badge(badge, keystore, password, production, devices);	}	/**	 * 推送一個語音	 * @param sound 語音	 * @param devices 設備	 * @throws CommunicationException	 * @throws KeystoreException	 */	public static void pushSoundNotification(String sound,Object devices) throws CommunicationException, KeystoreException{		Push.sound(sound, keystore, password, production, devices);	}	/**	 * 推送一個alert+badge+sound通知	 * @param message 消息	 * @param badge 標記	 * @param sound 聲音	 * @param devices 設備	 * @throws CommunicationException	 * @throws KeystoreException	 */	public static void pushCombinedNotification(String message,int badge,String sound,Object devices) throws CommunicationException, KeystoreException{		Push.combined(message, badge, sound, keystore, password, production, devices);	}	/**	 * 通知Apple的雜志內容	 * @param devices 設備	 * @throws CommunicationException	 * @throws KeystoreException	 */	public static void contentAvailable(Object devices) throws CommunicationException, KeystoreException{		Push.contentAvailable(keystore, password, production, devices);	}	/**	 * 推送有用的調試信息	 * @param devices 設備	 * @throws CommunicationException	 * @throws KeystoreException	 */	public static void test(Object devices) throws CommunicationException, KeystoreException{		Push.test(keystore, password, production, devices);	}	/**	 * 推送自定義負載	 * @param devices	 * @param msg	 * @param badge	 * @param sound	 * @param map	 * @throws JSONException	 * @throws CommunicationException	 * @throws KeystoreException	 */	public static void pushPayload(List<Device> devices, String msg,Integer badge,String sound,Map<String,String> map) throws JSONException, CommunicationException, KeystoreException{		PushNotificationPayload payload = customPayload(msg, badge, sound, map);		Push.payload(payload, keystore, password, production, devices);	}	/**	 * 用內置線程推送負載信息	 * @param devices	 * @param msg	 * @param badge	 * @param sound	 * @param map	 * @throws Exception	 */	public static void pushPayLoadByThread(List<Device> devices, String msg,Integer badge,String sound,Map<String,String> map) throws Exception{		PushNotificationPayload payload = customPayload(msg, badge, sound, map);		Push.payload(payload, keystore, password, production, numberOfThreads, devices);	}	/**	 * 推送配對信息	 * @param devices	 * @param msg	 * @param badge	 * @param sound	 * @param map	 * @throws JSONException	 * @throws CommunicationException	 * @throws KeystoreException	 */	public static void pushPayloadDevicePairs(List<Device> devices,String msg,Integer badge,String sound,Map<String,String> map) throws JSONException, CommunicationException, KeystoreException{		List<PayloadPerDevice> payloadDevicePairs = new ArrayList<PayloadPerDevice>();		PayloadPerDevice perDevice = null;		for (int i = 0; i <devices.size(); i++) {			perDevice = new PayloadPerDevice(customPayload(msg+"--->"+i, badge, sound, map), devices.get(i));			payloadDevicePairs.add(perDevice);		}		Push.payloads(keystore, password, production, payloadDevicePairs);	}	/**	 * 用線程推配對信息	 * @param devices	 * @param msg	 * @param badge	 * @param sound	 * @param map	 * @throws Exception	 */	public static void pushPayloadDevicePairsByThread(List<Device> devices,String msg,Integer badge,String sound,Map<String,String> map) throws Exception{		List<PayloadPerDevice> payloadDevicePairs = new ArrayList<PayloadPerDevice>();		PayloadPerDevice perDevice = null;		for (int i = 0; i <devices.size(); i++) {			perDevice = new PayloadPerDevice(customPayload(msg+"--->"+i, badge, sound, map), devices.get(i));			payloadDevicePairs.add(perDevice);		}		Push.payloads(keystore, password, production,numberOfThreads, payloadDevicePairs);	}	/**	 * 隊列多線程推送	 * @param devices	 * @param msg	 * @param badge	 * @param sound	 * @param map	 * @throws KeystoreException	 * @throws JSONException	 */	public static void queue(List<Device> devices,String msg,Integer badge,String sound,Map<String,String> map) throws KeystoreException, JSONException{		PushQueue queue = Push.queue(keystore, password, production, numberOfThreads);		queue.start();		PayloadPerDevice perDevice = null;		for (int i = 0; i <devices.size(); i++) {			perDevice = new PayloadPerDevice(customPayload(msg+"--->"+i, badge, sound, map), devices.get(i));			queue.add(perDevice);		}	}	/**	 * 自定義負載	 * @param msg	 * @param badge	 * @param sound	 * @param map 自定義字典	 * @return	 * @throws JSONException	 */	private static PushNotificationPayload customPayload(String msg,Integer badge,String sound,Map<String,String> map) throws JSONException{		PushNotificationPayload payload = PushNotificationPayload.complex();		if(StringUtils.isNotEmpty(msg)){			payload.addAlert(msg);					}		if(badge != null){						payload.addBadge(badge);		}		payload.addSound(StringUtils.defaultIfEmpty(sound, "default"));		if(map!=null && !map.isEmpty()){			Object[] keys = map.keySet().toArray();					Object[] vals = map.values().toArray();			if(keys!= null && vals != null && keys.length == vals.length){				for (int i = 0; i < map.size(); i++) {										payload.addCustomDictionary(String.valueOf(keys[i]),String.valueOf(vals[i]));				}			}		}		return payload;	}}

  


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 海淀区| 习水县| 谢通门县| 贵港市| 方正县| 五华县| 鹤峰县| 乐亭县| 富锦市| 龙泉市| 邯郸市| 杭锦后旗| 新建县| 齐齐哈尔市| 申扎县| 女性| 科技| 都安| 望城县| 玉树县| 吴桥县| 东阳市| 永新县| 重庆市| 团风县| 定南县| 沾益县| 绥江县| 陇西县| 米易县| 通州区| 大埔区| 镇巴县| 阜平县| 和林格尔县| 额敏县| 洞头县| 泽普县| 安康市| 凤翔县| 襄樊市|