java接入极光推送
直接提供工具类, 调用时直接调用其 sendToRegistrationId() 方法 1 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; public class JpushClientUtil { private final static String appKey = "xxxxxxxxxxxxxxxxxxxxx自己填";
private final static String masterSecret = "xxxxxxxxxxxxxxxxxxxxxxx自己填";
private static JPushClient jPushClient = new JPushClient(masterSecret, appKey); /**
* 推送给设备标识参数的用户
*
* @param registrationId
* 设备标识
* @param notification_title
* 通知内容标题
* @param msg_title
* 消息内容标题
* @param msg_content
* 消息内容
* @param extrasparam
* 扩展字段
* @return 0推送失败,1推送成功
*/
public static int sendToRegistrationId(String registrationId, String notification_title, String msg_title,String msg_content, String extrasparam) {
int result = 0;
try {
PushPayload pushPayload = JpushClientUtil.buildPushObject_all_registrationId_alertWithTitle(registrationId,
notification_title, msg_title, msg_content, extrasparam);
System.out.println(pushPayload);
PushResult pushResult = jPushClient.sendPush(pushPayload);
System.out.println(pushResult);
if (pushResult.getResponseCode() == 200) {
result = 1;
}
} catch (APIConnectionException e) {
e.printStackTrace(); } catch (APIRequestException e) {
e.printStackTrace();
} return result;
} private static PushPayload buildPushObject_all_registrationId_alertWithTitle(String registrationId,
String notification_title, String msg_title, String msg_content, String extrasparam) { 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(1)
// 此字段的值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(1)
// 此字段的值是用来指定本推送的离线保存时长,如果不传此字段则默认保存一天,最多指定保留十天;
.setTimeToLive(86400) .build()) .build(); } }
java接入极光推送的更多相关文章
- Java整合极光推送 ( 简单 )
Java 整合极光推送官方文档:https://github.com/jpush/jpush-api-java-client 这里记录一下简单的使用步骤:创建一个普通的 Maven 工程然后添加依赖 ...
- Flutter接入极光推送
(1)搜索 https://pub.dartlang.org/packages/jpush_flutter ,安装插件,并且按照官方配置 /android/app/build.gradle andro ...
- 极光推送-Java后台实现方式一:Http API
Java后台实现极光推送有两种方式,一种是使用极光推送官方提供的推送请求API:https://api.jpush.cn/v3/push,另一种则是使用官方提供的第三方Java APIjar包,这里先 ...
- 极光推送经验之谈-Java后台服务器实现极光推送的两种实现方式
原创作品,可以转载,但是请标注出处地址http://www.cnblogs.com/V1haoge/p/6439313.html Java后台实现极光推送有两种方式,一种是使用极光推送官方提供的推送请 ...
- 1、Android Studio集成极光推送(Jpush) 报错 java.lang.UnsatisfiedLinkError: cn.jpush.android.service.PushProtoco
Android studio 集成极光推送(Jpush) (华为手机)报错, E/JPush: [JPushGlobal] Get sdk version fail![获取sdk版本失败!] W/Sy ...
- java 极光推送
Web.xml配置文件 <context-param> <param-name>contextConfigLocation</param-name> <par ...
- JPush极光推送 Java调用服务器端API开发
极光推送是:使得开发者可以即时地向其应用程序的用户推送通知或者消息,与用户保持互动,从而有效地提高留存率,提升用户体验.简单的说就是通过JPush后台管理网站进行app消息的推送.可以让用户及时 ...
- 极光推送JAVA代码示例
一. 准备工作 1. 登录极光推送官网https://www.jpush.cn/,注册账号并登录 2. 创建应用 创建应用过程,详见百度经验:http://jingyan.baidu.com/arti ...
- 极光推送>>java SDK服务端集成后台项目(使用详解)
PS:如果你是第一次用推送,那就直接按照我的步骤来,再去看官方文档,这样,更容易能理解操作流程.还有——-请耐心看 极光文档(java SDK)请参考 [ 极光文档 ] 步骤一: 首先,你必须在 [极 ...
随机推荐
- MNIST数据集转化为二维图片
#coding: utf-8 from tensorflow.examples.tutorials.mnist import input_data import scipy.misc import o ...
- redis之(十九)redis的管理
[一]redis的安全 --->redis的简洁美,使得redis的安全设计是在“redis运行在可信环境”这个前提下做出来,. --->在生产环境运行时不能允许外界直接链接到redis, ...
- hdu 1547(BFS)
Bubble Shooter Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- 【转载】Web开发技术发展历史-版本1
原文在这里. Web开发技术发展历史 Web的诞生 提到Web,不得不提一个词就是“互联网”.Web是World Wide Web的简称,中文译为万维网.“万维网”和我们经常说的“互联网”是两个联系极 ...
- Windows7 + OSG3.6 + VS2017 + Qt5.11
一.准备工作 下载需要的材料: 1. OSG稳定版源代码, 3.6.3版本 2. 第三方库,选择VS2017对应的版本 https://download.osgvisual.org/3rdParty ...
- gitlab和github的区别
先说一下相同点,二者都是基于web的Git仓库,在很大程度上GitLab是仿照GitHub来做的,它们都提供了分享开源项目的平台,为开发团队提供了存储.分享.发布和合作开发项目的中心化云存 ...
- Spring学习(一)——Spring中的依赖注入简介
[前面的话] Spring对我太重要了,做个关于web相关的项目都要使用Spring,每次去看Spring相关的知识,总是感觉一知半解,没有很好的系统去学习一下,现在抽点时间学习一下Spring.不知 ...
- Notepad++7.4.2的配置使用详情
之前有写过一篇notepad的使用说明,没想到稀里糊涂更新了几次之后,我以前的配置什么的全干掉了,而且我打开新版后,发现和以前还有点不一样了.那就继续这个高级版本再来一边吧. 1.Zen Coding ...
- 利用jquery.touchSwipe.js实现的移动滑屏效果。
利用jquery.touchSwipe.js实现的移动滑屏效果. 亲测:兼容ie8及各种浏览器 <script type="text/javascript" src=&quo ...
- Spring注解@Scope("prototype")
spring 默认scope 是单例模式 这样只会创建一个Action对象 每次访问都是同一个Action对象,数据不安全 struts2 是要求 每次次访问 都对应不同的Action scope=& ...