// 对android和ios设备发送
JPushClient jpush = new JPushClient(masterSecret, appKey);
 
// 对android和ios设备发送,同时指定离线消息保存时间
JPushClient jpush = new JPushClient(masterSecret, appKey, timeToLive);
 
// 指定某种设备发送
JPushClient jpush = new JPushClient(masterSecret, appKey, DeviceEnum.Android);
 
// 指定某种设备发送,并且指定离线消息保存时间
JPushClient jpush = new JPushClient(masterSecret, appKey, timeToLive, DeviceEnum.IOS);
参数名称 参数类型 选项 内容说明
masterSecret
String 必须 Portal上注册应用时生成的 masterSecret
appKey String 必须 Portal上注册应用时生成的 appKey
timeToLive long 可选

保存离线消息的时长。秒为单位。最多支持10天(864000秒)。
0 表示该消息不保存离线。即:用户在线马上发出,当前不在线用户将不会收到此消息。
此参数不设置则表示默认,默认为保存1天的离线消息(86400秒)。

DeviceEnum Enum 可选 指定的设备。
可选值:DeviceEnum.Android, DeviceEnum.IOS。
不填或者null值为同时支持 Android 与 iOS。

发送消息

JPushClient公共方法

方法名称 参数列表(必须) 方法说明
setEnableSSL boolean enableSSL (true为使用ssl, 默认为不使用ssl) 是否启动ssl安全连接

sendNotificationWithImei

int sendNo(发送编号),
String imei (IMEI字符串) ,
String msgTitle (消息标题/通知标题) ,
String msgContent (消息内容/通知内容) 
发送带IMEI的通知
sendNotificationWithImei int sendNo , 
String imei ,
String msgTitle ,
String msgContent ,
int builderId (自定义通知栏样式Id) ,
Map<String, Object>extra (附属信息)
自定义通知栏(没有则填写0)
以及传递附属信息 

sendCustomMessageWithImei

int sendNo , 
String imei ,
String msgTitle ,
String msgContent 
发送带IMEI的消息
sendCustomMessageWithImei int sendNo , 
String imei ,
String msgTitle ,
String msgContent, 
String msgContentType (消息内容类型,原样返回),
Map<String, Object> extra 
用户自定义消息类型,
以及传递附属信息 

sendNotificationWithTag

int sendNo , 
String tag (Tag字符串) ,
String msgTitle ,
String msgContent
发送带Tag的通知
sendNotificationWithTag int sendNo , 
String tag ,
String msgTitle ,
String msgContent , 
int builderId ,
Map<String, Object>extra
自定义通知栏(没有则填写0)
以及传递附属信息 

sendCustomMessageWithTag

int sendNo , 
String tag ,
String msgTitle ,
String msgContent
发送带Tag的消息
sendCustomMessageWithTag int sendNo , 
String tag ,
String msgTitle ,
String msgContent ,
String msgContentType ,
Map<String, Object> extra 
用户自定义消息类型,
以及传递附属信息 

sendNotificationWithAlias

int sendNo , 
String alias (Alias字符串) ,
String msgTitle , 
String msgContent
发送带Alias的通知
sendNotificationWithAlias int sendNo , 
String alias (Alias字符串) ,
String msgTitle , 
String msgContent ,
int builderId ,
Map<String, Object>extra
自定义通知栏(没有则填写0)
以及传递附属信息 

sendCustomMessageWithAlias

int sendNo , 
String alias ,
String msgTitle , 
String msgContent
发送带Alias的消息
sendCustomMessageWithAlias int sendNo , 
String alias ,
String msgTitle , 
String msgContent , 
String msgContentType ,
Map<String, Object> extra 
用户自定义消息类型,
以及传递附属信息 

sendNotificationWithAppKey

int sendNo , 
String msgTitle , 
String msgContent
发送通知给AppKey的所有用户
sendNotificationWithAppKey int sendNo , 
String msgTitle , 
String msgContent ,
int builderId ,
Map<String, Object>extra
自定义通知栏(没有则填写0)
以及传递附属信息 

sendCustomMessageWithAppKey

int sendNo , 
String msgTitle , 
String msgContent
发送带AppKey的消息
sendCustomMessageWithAppKey int sendNo , 
String msgTitle , 
String msgContent ,
String msgContentType ,
Map<String, Object> extra  
用户自定义消息类型,
以及传递附属信息 

代码示例

代码示例-发送带IMEI的通知
JPushClient jpush = new JPushClient(masterSecret, appKey);
//jpush.setEnableSSL(true);
int sendNo = 1;
String imei = "";
String msgTitle = "";
String msgContent = "";
 
MessageResult msgResult = jpush.sendNotificationWithImei(sendNo, imei, msgTitle, msgContent);
if (null != msgResult) {
    if (msgResult.getErrcode() == ErrorCodeEnum.NOERROR.value()) {
        System.out.println("发送成功, sendNo=" + msgResult.getSendno());
    } else {
        System.out.println("发送失败, 错误代码=" + msgResult.getErrcode() + ", 错误消息=" + msgResult.getErrmsg());
    }
} else {
    System.out.println("无法获取数据");
}
代码示例-IOS设置通知铃声和badge
JPushClient jpush = new JPushClient(masterSecret, appKey);
 
Map<String, Object> extra = new HashMap<String, Object>();
IOSExtra iosExtra = new IOSExtra(1, "Windows_Logon_Sound.wav");//badge and sound
extra.put("ios", iosExtra);
 
MessageResult msgResult = jpush.sendNotificationWithAppKey(sendNo, msgTitle, msgContent, 0, extra);

MessageResult 类

公共方法 方法用途

getSendno

 消息发送成功后,按客户端传输的sendNo原样返回

getErrcode

 错误代码,代码定义参考ErrorCodeEnum
getErrmsg  返回错误消息的描述

ErrorCode 类

错误代码-ErrorCodeEnum
package cn.jpush.api;
 
public enum ErrorCodeEnum {
     
    //没有错误,发送成功
    NOERROR(0),
 
    //系统内部错误
    SystemError(10),
 
    //不支持GET请求
    NotSupportGetMethod(1001),
 
    //缺少必须参数
    MissingRequiredParameters(1002),
 
    //参数值不合法
    InvalidParameter(1003),
 
    //验证失败
    ValidateFailed(1004),
 
    //消息体太大
    DataTooBig(1005),
 
    //IMEI不合法
    InvalidIMEI(1007),
 
    //appkey不合法
    InvalidAppKey(1008),
 
    //msg_content不合法
    InvalidMsgContent(1010),
 
    //没有满足条件的推送目标
    InvalidPush(1011),
 
    //IOS不支持自定义消息
    CustomMessgaeNotSupportIOS(1012);
 
    private final int value;
    private ErrorCodeEnum(final int value) {
        this.value = value;
    }
 
    public int value() {
        return this.value;
    }
}

JPush极光推送Java服务器端API的更多相关文章

  1. JPush极光推送Java服务器端实例

    import cn.jpush.api.JPushClient; import cn.jpush.api.common.resp.APIConnectionException; import cn.j ...

  2. JPush极光推送 Java调用服务器端API开发

       极光推送是:使得开发者可以即时地向其应用程序的用户推送通知或者消息,与用户保持互动,从而有效地提高留存率,提升用户体验.简单的说就是通过JPush后台管理网站进行app消息的推送.可以让用户及时 ...

  3. **极光推送PHP服务器端推送移动设备消息(Jpush V2 api)

    jpush.php  这是推送方法  用到curl发送请求 <?php /** * 极光推送php 服务器端 * @author yalong sun * @Email <syl_ad@1 ...

  4. C#—ASP.NET:集成极光推送(Push API v3)

    C#—ASP.NET:集成极光推送(Push API v3) 原文地址: https://blog.csdn.net/CXLLLK/article/details/86489994   1.极光推送官 ...

  5. 用JPUSH极光推送实现服务端向安装了APP应用的手机推送消息(C#服务端接口)

    这次公司要我们做一个功能,就是当用户成功注册以后,他登录以后要收到消息,当然这个消息是安装了我们的手机APP应用的手机咯. 极光推送的网站的网址是:https://www.jpush.cn/ 极光推送 ...

  6. atitit.web 推送实现方案集合(2)---百度云,jpush 极光推送 ,个推的选型比较.o99

    atitit.web 推送实现方案集合(2)---百度云,jpush 极光推送 ,个推的选型比较.o99 1.1. 云推送有推送次数或频率的限制吗? 1 1.2. 推送的消息长度 1 1.3. 离线消 ...

  7. Laravel 集成 JPush 极光推送指北

    我是一个 Laravel 小白,我是一个 Laravel 小白,我是一个 Laravel 小白(默念三遍再往下读,如果非小白就不用看了). Laravel 使用 Composer 来管理代码依赖.所以 ...

  8. 使用JPush(极光推送)实现远程通知

    使用JPush(极光推送)实现远程通知 远程推送是APP 必备的功能, 现在第三方的 SDK 已经做的非常完备了, 在 iOS10.0出来之后, 极光推送也及时更新了他的 SDK, 今天小试了一下效果 ...

  9. 极光推送-Java后台实现方式一:Http API

    Java后台实现极光推送有两种方式,一种是使用极光推送官方提供的推送请求API:https://api.jpush.cn/v3/push,另一种则是使用官方提供的第三方Java APIjar包,这里先 ...

随机推荐

  1. hdu 4283 You Are the One 区间dp

    You Are the One Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  2. 手机号 和 email 的正则匹配

    手机号   /^1[3|4|5|8] \d{9}$/ email  /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/

  3. js的常用api

    JavaScript常用API总结 原创 2016-10-02 story JavaScript 下面是我整理的一些JavaScript常用的API清单. 目录 元素查找 class操作 节点操作 属 ...

  4. 谈谈Javascript的this关键字(this is not this)

    前言: 看文章标题你就知道,这篇文章我只讲一个简单的Javascript的this关键字,说它简单——它又不简单,因为曾几何时我也对this关键字有些困惑,它也确实会让不少程序员感到不解——它像是一个 ...

  5. .htaccess根据IP地址限制访问

    屏蔽IP地址 屏蔽IP地址有时是非常必要的,比如对于一个外贸公司网站,来自国内的访问是不会带来任何经济效益的,而且还占用服务器资源,造成访问延迟等问题. 如果要屏蔽某一特定IP可以使用: order ...

  6. 全真模拟 (1) day1

    第一题: 题目大意: 给出N个数的m对关系(a,b)表示a大于b. 每个数至少为100,求这些书最小可能的和. 解题过程: 1.看到这题就想到之前USACO的一道题,那题是N头牛排序,然后给出m对关系 ...

  7. bzoj1211: prufer序列 | [HNOI2004]树的计数

    题目大意: 告诉你树上每个节点的度数,让你构建出这样一棵树,问能够构建出树的种树 这里注意数量为0的情况,就是 当 n=1时,节点度数>0 n>1时,所有节点度数相加-n!=n-2 可以通 ...

  8. Echarts源码总括

    Echarts采用MVC模型,典型的以数据驱动视图的逻辑. 所有的用于绘图的元素存放于Echarts::Zrender::storage中,所有的动画对象存放于Echarts::Zrender::an ...

  9. 一步步调试解决iOS内存泄漏

      虽然iOS 5.0版本之后加入了ARC机制,由于相互引用关系比较复杂时,内存泄露还是可能存在.所以了解原理很重要. 这里讲述在没有ARC的情况下,如何使用Instruments来查找程序中的内存泄 ...

  10. 解决iOS8安装企业版无反应问题

    iOS7可以下载没有任何问题,iOS8发现挂在官网上的企业版的app点击了提示是否安装应用程序,但是确认以后没有反应,找了很久,都没有发现问题.后来查看了的device console发现安装的时候出 ...