官网文档更详细,这里是只做个测试

http://docs.getui.com/server/java/start/

全部推送(针对app应用)

public static final String appid = "xxxx";
public static final String appkey = "xxxx";
public static final String masterSecret = "xxxx";
public static final String url = "http://sdk.open.api.igexin.com/apiex.htm"; public static void main(String[] args) {
IGtPush push = new IGtPush(url, appkey, masterSecret);
     // 定义"点击链接打开通知模板",并设置标题、内容、链接
LinkTemplate template = new LinkTemplate();
template.setAppId(appid);
template.setAppkey(appkey); // 设置样式
Style0 style = new Style0();
style.setTitle("test01");
style.setText("测试内容2017-6-8");
style.setLogoUrl("");
style.setRing(true);
style.setVibrate(true);
style.setClearable(true);
template.setStyle(style);
template.setUrl("http://www.getui.com"); List<String> appIds = new ArrayList<String>();
appIds.add(appid); // 设置AppMessage消息对象
AppMessage message = new AppMessage();
message.setData(template);
message.setAppIdList(appIds);
message.setOffline(true);
message.setOfflineExpireTime(1000 * 600); //广播
IPushResult ret = push.pushMessageToApp(message);
System.out.println(ret.getResponse().toString());
}

单个推送(针对个人)

public static void main(String[] args) {
IGtPush push = new IGtPush(url, appkey, masterSecret);
LinkTemplate template = new LinkTemplate();
template.setAppId(appid);
template.setAppkey(appkey); Style6 style = new Style6();
style.setRing(true);//响铃
style.setTitle("test02");//标题
style.setClearable(true);//可清除
style.setVibrate(true);//震动
style.setBigStyle2("单个测试内容2017-6-8");//通知展示文本+长文本样式
style.setText("单个测试内容2017-6-8");//通知内容 template.setStyle(style);
template.setUrl("http://www.getui.com"); SingleMessage message = new SingleMessage();
message.setOffline(true);
// 离线有效时间,单位为毫秒,可选
message.setOfflineExpireTime(24 * 3600 * 1000);
message.setData(template);
// 可选,1为wifi,0为不限制网络环境。根据手机处于的网络情况,决定是否下发
message.setPushNetWorkType(0);
Target target = new Target();
target.setAppId(appid);
//单个用户唯一标志
target.setClientId("fe54e481d7201803c7683eacec25a21e");
IPushResult ret = null;
try {
ret = push.pushMessageToSingle(message, target);
} catch (RequestException e) {
e.printStackTrace();
ret = push.pushMessageToSingle(message, target, e.getRequestId());
}
if (ret != null) {
System.out.println(ret.getResponse().toString());
} else {
System.out.println("服务器响应异常");
}
}
04-24 19:38