极光推送消息——RegistrationID方式
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方式的更多相关文章
- 极光推送消息——Alias别称方式(Andirod)
1.pom文件引入相关jar包 <!--极光推送消息start--> <dependency> <groupId>net.sf.json-lib</group ...
- Yii1.1框架实现PHP极光推送消息通知
一.下载极光推送PHP SDK,解压后放在/protected/components/目录下,如下图所示: 二.完善修改下官方的demo例子,我这里复制一份demo,改为NotifyPush.php, ...
- ios之极光推送消息收到以后对消息的处理总结
当我们的APP收到推送消息后,通常需要根据推送内容点击消息进入到指定的页面 这里讲一下收到推送消息后的处理,分为三种情况 :1.APP处于前台运行情况下 2.APP处于后台挂起情况下 3. ...
- ios -- 极光推送《2》--极光推送消息推送成功,但是手机收不到的解决方法
1.确认证书是否与app的Bundle ID是否一致 2. 确认你的推送证书是否已经过期 3.确认你的APP_KEY是否和极光APP_KEY是否一致 4.正确调用bindChannel,并成功返回ap ...
- JPush 极光推送 消息推送 实例
简介 官网:https://www.jpush.cn/ 极光推送(JPush)是一个端到端的推送服务,使得服务器端消息能够及时地推送到终端用户手机上,让开发者积极地保持与用户的连接,从而提高用户活跃度 ...
- 极光推送_总结_01_Java实现极光推送
一.代码实现 1.配置类—Env.java package com.ray.jpush.config; /**@desc : 极光推送接入配置 * * @author: shirayner * @da ...
- iOS:极光推送控制器跳转
在前面已经做完了极光消息的推送,那么有消息了,如何跳转到需要的控制器呢?其实,主要还是在userInfo这个消息里面做判断来处理,具体如下: 下面这两个是远程推送时接收消息的方法,这是应用程序提供的方 ...
- Ionic5整合极光推送JPush ( 简单 )
项目初始化 1. 安装项目依赖: # 安装cordova插件 ionic cordova plugin add jpush-phonegap-plugin --variable APP_KEY=&qu ...
- 使用极光推送(www.jpush.cn)向安卓手机推送消息【服务端向客户端主送推送】C#语言
在VisualStudio2010中新建网站JPushAndroid.添加引用json帮助类库Newtonsoft.Json.dll. 在web.config增加appkey和mastersecret ...
随机推荐
- Anaconda简单使用手册
安装部分 准备工作 下载各平台对应的安装包,各平台安装包下载链接如下: Windows macOs Linux 安装过程 安装过程在此不给出具体过程,可参照官方给出教程,各平台对应教程如下: Wind ...
- session一致性的解决方案
更多内容,欢迎关注微信公众号:全菜工程师小辉.公众号回复关键词,领取免费学习资料. 什么是session? 服务器为每个用户创建一个会话,存储用户的相关信息,以便多次请求能够定位到同一个上下文,这个相 ...
- 基于ASP.Net Core开发的一套通用后台框架
基于ASP.Net Core开发一套通用后台框架 写在前面 这是本人在学习的过程中搭建学习的框架,如果对你有所帮助那再好不过.如果您有发现错误,请告知我,我会第一时间修改. 知其然,知其所以然,并非重 ...
- java基础-多线程一
什么是线程 说到线程就不得不说下进程了, 大家都知道,许许多多的线程组合在一起就成了一个进程,进程是由操作系统进行资源操作的一个最小的单位,线程则是比进程更小的实际执行操作的单位:每个线程都有自己的堆 ...
- ValueError: Error when checking input: expected conv2d_1_input to have 4 dimensions, but got array with shape (60000, 28, 28)
报错 Traceback (most recent call last): File "D:/PyCharm 5.0.3/WorkSpace/3.Keras/3.构建各种神经网络/3.CNN ...
- SDU暑期集训排位(4)
SDU暑期集训排位(4) C. Pick Your Team 题意 有 \(n\) 个人,每个人有能力值,A 和 B 轮流选人,A 先选,B 选人按照一种给出的优先级, A 可以随便选.A 想最大化己 ...
- UVA - 10462-Is There A Second Way Left? Kruskal求次小生成树
UVA - 10462 题意: 求次小生成树的模板题,这道题因为有重边的存在,所以用kruskal求比较好. #include <iostream> #include <cstdio ...
- Codeforces#398 &767C. Garland 树形求子节点的和
传送门 题意:在一个树上,问能否切两刀,使得三块的节点值的和相同. 思路: 由于这个总的节点和是不变的,每块的节点值和sum固定,dfs搜索,和等于sum/3,切.若不能分成三块(不能被3整除,-1) ...
- codeforces 14E. Camels(多维dp)
题目链接:http://codeforces.com/problemset/problem/14/E 题意:就是给出n个点要求画出t个波峰和t-1个波谷 很显然要t个波峰和t-1个波谷开始是波动一定是 ...
- hdu5491 The Next 模拟
Let LL denote the number of 1s in integer DD’s binary representation. Given two integers S1S1 and S2 ...