Aurora推送摘要
极光推送就是将消息推送至app。我们首先需要在服务器上集成maven依赖性。
& lt!-极光推送-& gt;
& ltgroupId & gtcn.jpush.api
& ltartifactId & gtjpush-客户端
& lt版本& gt3.2.3
& lt/dependency & gt;
那么我们需要知道极光推送有哪些推送方式,安卓和ios都适用。我在项目中使用了alias push alias(和tag push tag),推送方式分为通知推送和自定义推送。手机提示框可以显示通知推送,自定义推送不能。我觉得安卓做的可以像微信视频一样弹出对话框,看起来很不错。这和微信不同,你可以邀请多个人。好像只能一对一用阿里云,所以改成腾讯视频会议了。好了,废话不多说,去上一个我写的工具类。
包com . jpxx . home page . home page . service . utils;
导入cn . jpush . API . jpush client;
导入cn . jpush . API . push . push result;
导入cn . jpush . API . push . model . options;
导入cn . jpush . API . push . model . platform;
导入cn . jpush . API . push . model . push payload;
导入cn . jpush . API . push . model . audience . audience;
导入cn . jpush . API . push . model . notification . notification;
导入cn . jpush . API . push . model . message;
导入cn . jpush . API . push . model . push payload . builder;
公共类SendMessageUtils {
private static string apkey = " 8a 7880 c6fb 81ad 494 b 224078 ";
/**
* j推主密极光推平台生成的密钥。
*/
private static StringMasterSecret = " c0fc 675 c 4c 48 f 9 BF 35269 cf 4 ";
//为两个参数分别填写你申请的masterSecret和appKey。
private static JPushClientjPushClient = new JPushClient(master secret,AppKey);
/**
*通知推送
*注意:当push方法不为空时,pushed值不能为空;当推送方法为空时,不需要推送值。
* @param类型推送模式:1,“标签”推送,2,“别名”推送。
* @param value推送的标记或别名值
* @param警报推送内容
*/
public static StringpushNotice(字符串类型,字符串标题,字符串值,字符串alert,int roomId,字符串MessageType,字符串名称,字符串promoterAdavter,字符串meetingTitle,字符串sig){
builder builder = push payload . new builder();
builder . set platform(platform . all());//设置接受的平台。all适用于所有平台,包括Android、ios和微软。
//设置用户不在线时保存离线消息的时间。
options options = options . send no();
options . settimetolive(86400 l);//设置为86400保存一天,不设置默认保存一天。
builder.setOptions(选项);
builder . set message(message . new builder()
。setMsgContent(值)
。标题
。addExtra("roomId ",roomId)
。addExtra("消息类型",消息类型)
。addExtra("名称",名称)
。addExtra("promoterAdavter ",promoterAdavter)
。addExtra("meetingTitle ",meetingTitle)
。addExtra("userSig ",Sig)
。build());
//设置推送模式
if(type . equals(" alias "){
builder . set audience(audience . alias(value));//按别名推送
} else if(type . equals(" tag "){
builder . set audience(audience . tag(value));//按标签推送
}否则{
builder . set audience(audience . all());//Audience设置为all,表示是广播推送的,所有用户都可以接收。
}
//设置为通过通知发送消息。
builder . set notification(notification . alert(alert));
push payload push payload = builder . build();
system . out . println(" ggggggg "+push payload);
尝试{
//推送,实际推送就在这一步。
//system . out . println(" zzzzzzzzz "+jpushclient . send push(push payload));
push result push result = jpushclient . send push(push payload);
返回“成功”;
}catch(异常e){
system . out . println(" exception "+e);
e . printstacktrace();
返回“失败”;
}
}
/**
*自定义消息推送
*注意:当push方法不为空时,pushed值不能为空;当推送方法为空时,不需要推送值。
* @param类型推送模式:1,“标签”推送,2,“别名”推送。
* @param value推送的标记或别名值
* @param警报推送内容
*/
public static String pushmsg(String type,String title,String value,String alert,int roomId,String MessageType,String name,String promoterAdavter,String meetingTitle,String sig){
builder builder = push payload . new builder();
builder . set platform(platform . all());//设置接受的平台
if(type . equals(" alias "){
builder . set audience(audience . alias(value));//别名推送
} else if(type . equals(" tag "){
builder . set audience(audience . tag(value));//标签推送
}否则{
builder . set audience(audience . all());//Audience设置为all,表示是广播推送的,所有用户都可以接收。
}
消息。builder new builder = message . new builder();
new builder . setmsgcontent(alert);//消息内容
newBuilder.setTitle(标题);
newBuilder.addExtra("roomId ",roomId);
new builder . add extra(" message type ",消息类型);
newBuilder.addExtra("name ",名称);
new builder . add extra(" promoterAdavter ",promoterAdavter);
new builder . add extra(" meeting title ",meeting title);
newBuilder.addExtra("userSig ",SIG);
message message = new builder . build();
builder.setMessage(消息);
push payload push payload = builder . build();
尝试{
push result push result = jpushclient . send push(push payload);
system . out . println(push result . is resultok());
返回“成功”;
}catch(异常e){
e . printstacktrace();
返回“失败”;
}
}
公共静态void main(String[] args) {
//使用标签福柯向用户推送消息。
//SendMessage实用程序。Pushmsg("别名","标题"," 5b 9022746 e 284 ea 092 e 3 baa 983035 DC ","您有新任务,请及时处理",111,"会议类型","。
//sendNotificationWirhAlias _ Ios(" zzzzzzzzzzzz "," uuid ");
//string result = sendmessageutils . push notice(" alias "," title "," 5b9022746e 284a092e3a983035dc ","您有新任务,请及时处理",11,"会议类型。
//System.out.println("返回结果"+结果);
/* string result = sendmessage utils . push notice(" alias ","警告标题"," 5b9022746e 284a092e3a983035dc "," dddd ",0,"警告类型",""," ");?//userDto.getUuId()
system . out . println(" result "+result);*/
//根据uuid查询别名信息是否存在。
字符串结果= HttpRequestUtil。JGUtil("/v3/aliases/5b 9022746 e 284 ea 0992 E3 baa 983035 DC "," 8a7880c6fb81ad494b224078 "," c 0 fc 675 c 48 f 9 BF 35269 cf 4 ");//获取请求
//String result = http request util . interface util("/jpush/server/push/server _ overview/