import org.json.JSONObject;
import com.ytdinfo.core.umeng.FileInfo;
import com.ytdinfo.core.umeng.Message;
import push.android.AndroidCustomizedcast;
import push.android.AndroidFilecast;
import push.ios.IOSCustomizedcast;
import push.ios.IOSFilecast;
import push.ios.IOSUnicast;public classPushMessageUtil {//安卓notification
public staticboolean sendAndroidCustomizedcastNotification(Message message) throws Exception {
AndroidCustomizedcast customizedcast= newAndroidCustomizedcast();
customizedcast.setAppMasterSecret(message.getAndroidMasterSecret());
customizedcast.setPredefinedKeyValue("appkey", message.getAndroidAppKey());
customizedcast.setPredefinedKeyValue("timestamp", Integer.toString((int) (System.currentTimeMillis() / 1000L)));
customizedcast.setPredefinedKeyValue("type", message.getType());
customizedcast.setPredefinedKeyValue("device_tokens", message.getDeviceTokens());
customizedcast.setPredefinedKeyValue("display_type", "notification");//customizedcast.setPredefinedKeyValue("display_type", "message");
customizedcast.setPredefinedKeyValue("ticker", message.getContent());
customizedcast.setPredefinedKeyValue("title", message.getTitle());
customizedcast.setPredefinedKeyValue("text", message.getContent());
customizedcast.setPredefinedKeyValue("after_open", "go_custom");
customizedcast.setPredefinedKeyValue("custom", message.getCustom());
customizedcast.setPredefinedKeyValue("production_mode", "false");
customizedcast.setPredefinedKeyValue("description", message.getContent());//set custom field
JSONObject customJson = newJSONObject();
customJson.put("msgtype", (String) message.getMsgtype());
customJson.put("objectid", message.getObjectid());
customJson.put("content", (String) message.getContent());
customJson.put("studentId", (String) message.getStudentId());
customJson.put("studentName", (String) message.getStudentName());
customizedcast.setPredefinedKeyValue("custom", customJson);returncustomizedcast.send();
}//ios推送消息
public staticboolean sendIOSCustomizedcast(Message message) throws Exception {
IOSUnicast unicast= newIOSUnicast();
unicast.setAppMasterSecret((String) message.getIosMasterSecret());
unicast.setPredefinedKeyValue("appkey", message.getIosAppKey());
unicast.setPredefinedKeyValue("timestamp", Integer.toString((int) (System.currentTimeMillis() / 1000L)));
unicast.setPredefinedKeyValue("device_tokens", message.getDeviceTokens());//customizedcast.setPredefinedKeyValue("display_type", "notification");//customizedcast.setPredefinedKeyValue("display_type", "message");
unicast.setPredefinedKeyValue("alert", message.getContent());
unicast.setPredefinedKeyValue("badge", Integer.valueOf(1));
unicast.setPredefinedKeyValue("sound", "default");
unicast.setPredefinedKeyValue("content-available", message.getContent());
unicast.setPredefinedKeyValue("description", message.getContent());
unicast.setPredefinedKeyValue("production_mode", "false");//custom field
unicast.setCustomizedField("msgtype", (String) message.getMsgtype());
unicast.setCustomizedField("objectid", message.getObjectid());
unicast.setCustomizedField("content", (String) message.getContent());
unicast.setCustomizedField("studentId", (String) message.getStudentId());
unicast.setCustomizedField("studentName", (String) message.getStudentName());returnunicast.send();
}//安卓发送文件播
public static voidsendAndroidFilecast(FileInfo fileInfo) throws Exception {
AndroidFilecast filecast= newAndroidFilecast();
filecast.setAppMasterSecret(fileInfo.getAndroidMasterSecret());
filecast.setPredefinedKeyValue("appkey", fileInfo.getAppkey());
filecast.setPredefinedKeyValue("timestamp", Integer.toString((int) (System.currentTimeMillis() / 1000L)));
filecast.uploadContents(fileInfo.getContent());
filecast.setPredefinedKeyValue("ticker", "Android filecast ticker");
filecast.setPredefinedKeyValue("title", fileInfo.getTitle());
filecast.setPredefinedKeyValue("text", fileInfo.getText());
filecast.setPredefinedKeyValue("after_open", "go_app");
filecast.setPredefinedKeyValue("display_type", "notification");
filecast.send();
}//Ios发送文件播
public voidsendIOSFilecast(FileInfo fileInfo) throws Exception {
IOSFilecast filecast= newIOSFilecast();
filecast.setAppMasterSecret(fileInfo.getIosMasterSecret());
filecast.setPredefinedKeyValue("appkey", fileInfo.getAppkey());
filecast.setPredefinedKeyValue("timestamp", Integer.toString((int) (System.currentTimeMillis() / 1000L)));
filecast.uploadContents(fileInfo.getContent());
filecast.setPredefinedKeyValue("alert", "IOS 文件播测试");
filecast.setPredefinedKeyValue("badge", Integer.valueOf(0));
filecast.setPredefinedKeyValue("sound", "chime");
filecast.setPredefinedKeyValue("production_mode", "true");
filecast.send();
}public static voidmain(String[] args) {}
}