1、工具类

package com.test.util;
import cn.jiguang.common.resp.APIConnectionException;
import cn.jiguang.common.resp.APIRequestException;
import cn.jpush.api.JPushClient;
import cn.jpush.api.push.PushResult;
import cn.jpush.api.push.model.Message;
import cn.jpush.api.push.model.Options;
import cn.jpush.api.push.model.Platform;
import cn.jpush.api.push.model.PushPayload;
import cn.jpush.api.push.model.audience.Audience;
import cn.jpush.api.push.model.notification.AndroidNotification;
import cn.jpush.api.push.model.notification.IosNotification;
import cn.jpush.api.push.model.notification.Notification;
import com.yjl.entity.pushMessage.JpushClient; public class JpushClientUtil { private final static String appKey = "极光平台创建应用的appKey";
private final static String masterSecret = "极光平台创建应用的masterSecret";
private static JPushClient jPushClient = new JPushClient(masterSecret, appKey); public static void main(String[] args) {
JpushClient jpushClient = new JpushClient();
jpushClient.setRegistrationId("1a0018970afae35532f");
jpushClient.setMsgContent("这个是消息内容");
jpushClient.setMsgTitle("这个是标题");
jpushClient.setNotificationTitle("这个是通知标题");
jpushClient.setExtrasParam("这个是其他参数内容");
int result = JpushClientUtil.sendToRegistrationId(jpushClient);
System.out.println("推送结果:"+result);
} /**
* 0推送失败,1推送成功
* @param jpushClient
* @return
*/
public static int sendToRegistrationId(JpushClient jpushClient) {
int result = ;
try {
PushPayload pushPayload = JpushClientUtil.buildPushObject_all_registrationId_alertWithTitle(jpushClient);
System.out.println(pushPayload);
PushResult pushResult = jPushClient.sendPush(pushPayload);
System.out.println(pushResult);
if (pushResult.getResponseCode() == ) {
result = ;
}
} catch (APIConnectionException e) {
e.printStackTrace(); } catch (APIRequestException e) {
e.printStackTrace();
} return result;
} private static PushPayload buildPushObject_all_registrationId_alertWithTitle(JpushClient jpushClient) {
String registrationId = jpushClient.getRegistrationId();
String notification_title = jpushClient.getNotificationTitle();
String msg_title = jpushClient.getMsgTitle();
String msg_content = jpushClient.getMsgContent();
String extrasparam = jpushClient.getExtrasParam();
System.out.println("----------buildPushObject_all_all_alert");
// 创建一个IosAlert对象,可指定APNs的alert、title等字段
// IosAlert iosAlert = IosAlert.newBuilder().setTitleAndBody("title",
// "alert body").build();
return PushPayload.newBuilder()
// 指定要推送的平台,all代表当前应用配置了的所有平台,也可以传android等具体平台
.setPlatform(Platform.all())
// 指定推送的接收对象,all代表所有人,也可以指定已经设置成功的tag或alias或该应应用客户端调用接口获取到的registration
// id
.setAudience(Audience.registrationId(registrationId))
// jpush的通知,android的由jpush直接下发,iOS的由apns服务器下发,Winphone的由mpns下发
.setNotification(Notification.newBuilder()
// 指定当前推送的android通知
.addPlatformNotification(AndroidNotification.newBuilder().setAlert(notification_title)
.setTitle(notification_title)
// 此字段为透传字段,不会显示在通知栏。用户可以通过此字段来做一些定制需求,如特定的key传要指定跳转的页面(value)
.addExtra("sss", extrasparam).build())
// 指定当前推送的iOS通知
.addPlatformNotification(IosNotification.newBuilder()
// 传一个IosAlert对象,指定apns title、title、subtitle等
.setAlert(notification_title)
// 直接传alert
// 此项是指定此推送的badge自动加1
.incrBadge()
// 此字段的值default表示系统默认声音;传sound.caf表示此推送以项目里面打包的sound.caf声音来提醒,
// 如果系统没有此音频则以系统默认声音提醒;此字段如果传空字符串,iOS9及以上的系统是无声音提醒,以下的系统是默认声音
.setSound("sound.caf")
// 此字段为透传字段,不会显示在通知栏。用户可以通过此字段来做一些定制需求,如特定的key传要指定跳转的页面(value)
.addExtra("content", extrasparam).build())
// 此项说明此推送是一个background推送,想了解background看:http://docs.jpush.io/client/ios_tutorials/#ios-7-background-remote-notification
// 取消此注释,消息推送时ios将无法在锁屏情况接收
// .setContentAvailable(true)
.build())
// Platform指定了哪些平台就会像指定平台中符合推送条件的设备进行推送。 jpush的自定义消息,
// sdk默认不做任何处理,不会有通知提示。建议看文档http://docs.jpush.io/guideline/faq/的
// [通知与自定义消息有什么区别?]了解通知和自定义消息的区别
.setMessage(Message.newBuilder() .setMsgContent(msg_content) .setTitle(msg_title) .addExtra("message extras key", extrasparam) .build()) .setOptions(Options.newBuilder()
// 此字段的值是用来指定本推送要推送的apns环境,false表示开发,true表示生产;对android和自定义消息无意义
.setApnsProduction(false)
// 此字段是给开发者自己给推送编号,方便推送者分辨推送记录
.setSendno()
// 此字段的值是用来指定本推送的离线保存时长,如果不传此字段则默认保存一天,最多指定保留十天;
.setTimeToLive() .build()) .build(); } }

2、对象

package com.test.entity.pushMessage;

public class JpushClient {

  private String registrationId;
private String notificationTitle;
private String msgTitle;
private String msgContent;
private String extrasParam; public String getRegistrationId() {
return registrationId;
} public void setRegistrationId(String registrationId) {
this.registrationId = registrationId;
} public String getNotificationTitle() {
return notificationTitle;
} public void setNotificationTitle(String notificationTitle) {
this.notificationTitle = notificationTitle;
} public String getMsgTitle() {
return msgTitle;
} public void setMsgTitle(String msgTitle) {
this.msgTitle = msgTitle;
} public String getMsgContent() {
return msgContent;
} public void setMsgContent(String msgContent) {
this.msgContent = msgContent;
} public String getExtrasParam() {
return extrasParam;
} public void setExtrasParam(String extrasParam) {
this.extrasParam = extrasParam;
}
}

参考链接: https://blog.csdn.net/LWJdear/article/details/77374415

极光推送消息——RegistrationID方式的更多相关文章

  1. 极光推送消息——Alias别称方式(Andirod)

    1.pom文件引入相关jar包 <!--极光推送消息start--> <dependency> <groupId>net.sf.json-lib</group ...

  2. Yii1.1框架实现PHP极光推送消息通知

    一.下载极光推送PHP SDK,解压后放在/protected/components/目录下,如下图所示: 二.完善修改下官方的demo例子,我这里复制一份demo,改为NotifyPush.php, ...

  3. ios之极光推送消息收到以后对消息的处理总结

    当我们的APP收到推送消息后,通常需要根据推送内容点击消息进入到指定的页面 这里讲一下收到推送消息后的处理,分为三种情况 :1.APP处于前台运行情况下     2.APP处于后台挂起情况下   3. ...

  4. ios -- 极光推送《2》--极光推送消息推送成功,但是手机收不到的解决方法

    1.确认证书是否与app的Bundle ID是否一致 2. 确认你的推送证书是否已经过期 3.确认你的APP_KEY是否和极光APP_KEY是否一致 4.正确调用bindChannel,并成功返回ap ...

  5. JPush 极光推送 消息推送 实例

    简介 官网:https://www.jpush.cn/ 极光推送(JPush)是一个端到端的推送服务,使得服务器端消息能够及时地推送到终端用户手机上,让开发者积极地保持与用户的连接,从而提高用户活跃度 ...

  6. 极光推送_总结_01_Java实现极光推送

    一.代码实现 1.配置类—Env.java package com.ray.jpush.config; /**@desc : 极光推送接入配置 * * @author: shirayner * @da ...

  7. iOS:极光推送控制器跳转

    在前面已经做完了极光消息的推送,那么有消息了,如何跳转到需要的控制器呢?其实,主要还是在userInfo这个消息里面做判断来处理,具体如下: 下面这两个是远程推送时接收消息的方法,这是应用程序提供的方 ...

  8. Ionic5整合极光推送JPush ( 简单 )

    项目初始化 1. 安装项目依赖: # 安装cordova插件 ionic cordova plugin add jpush-phonegap-plugin --variable APP_KEY=&qu ...

  9. 使用极光推送(www.jpush.cn)向安卓手机推送消息【服务端向客户端主送推送】C#语言

    在VisualStudio2010中新建网站JPushAndroid.添加引用json帮助类库Newtonsoft.Json.dll. 在web.config增加appkey和mastersecret ...

随机推荐

  1. Leetcode之深度优先搜索&回溯专题-679. 24 点游戏(24 Game)

    Leetcode之深度优先搜索&回溯专题-679. 24 点游戏(24 Game) 深度优先搜索的解题详细介绍,点击 你有 4 张写有 1 到 9 数字的牌.你需要判断是否能通过 *,/,+, ...

  2. [The Preliminary Contest for ICPC Asia Nanjing 2019] A-The beautiful values of the palace(二维偏序+思维)

    >传送门< 前言 这题比赛的时候觉得能做,硬是怼了一个半小时,最后还是放弃了.开始想到用二维前缀和,结果$n\leq 10^{6}$时间和空间上都爆了,没有办法.赛后看题解用树状数组,一看 ...

  3. Beego orm 模型字段与数据库类型的对应

    深度学习,ORM 推荐的对应数据库类型,在此列出,自动建表功能也会以此为标准.默认所有的字段都是 NOT NULL MySQL go mysql int, int32-设置auto或者名称为Id in ...

  4. Win10安装Linux系统

    windows系统安装虚拟机,常见的是利用VMware Workstation这款软件来进行安装.在未接触Docker之前,我一直通过这款软件来进行管理的.docker是运行在linux环境下的,那怎 ...

  5. list 分批

    public class TestList { public static void main(String[] args){ List<Integer> list = new Array ...

  6. 2019牛客暑期多校训练营(第二场)J-Subarray(思维)

    >传送门< 前言 这题我前前后后看了三遍,每次都是把网上相关的博客和通过代码认真看了再思考,然并卵,最后终于第三遍也就是现在终于看懂了,其实懂了之后发现其实没有那么难,但是的的确确需要思维 ...

  7. HDU-4857-逃生-反向拓扑排序+优先队列

    HDU-4857 题意就是做一个符合条件的排序,用到拓扑序列. 我一开始wa了多发,才发现有几个样例过不了,发现1->2->3...的顺序无法保证. 后来就想用并查集强连,还是wa: 后来 ...

  8. codeforces 454 E. Little Pony and Summer Sun Celebration(构造+思维)

    题目链接:http://codeforces.com/contest/454/problem/E 题意:给出n个点和m条边,要求每一个点要走指定的奇数次或者是偶数次. 构造出一种走法. 题解:可能一开 ...

  9. win10 无法安装/启用 .net framework 3.5

    有些程序依赖.net framework 3.5 win10可以在控制面板->程序和功能->启用或关闭windows功能 启用 但有时会报错 比如 0x800f0950 官方论坛的解决办法 ...

  10. CLR中你想知道的事

    CLR是什么? CLR 公共语言运行时,是一个可由多个语言共同使用的运行环境,核心(内存管理,程序集加载,安全性,异常处理和多线程) Visual Studio是一种编译器,编译器也可称为语法检查器和 ...