jpush 推送
来源:互联网 发布:matlab给数据加噪声 编辑:程序博客网 时间:2024/06/04 23:14
JPush极光推送Java服务器端API
// 对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);
masterSecretString必须Portal上注册应用时生成的 masterSecretappKeyString必须Portal上注册应用时生成的 appKeytimeToLivelong可选
保存离线消息的时长。秒为单位。最多支持10天(864000秒)。
0 表示该消息不保存离线。即:用户在线马上发出,当前不在线用户将不会收到此消息。
此参数不设置则表示默认,默认为保存1天的离线消息(86400秒)。
可选值:DeviceEnum.Android, DeviceEnum.IOS。
不填或者null值为同时支持 Android 与 iOS。
发送消息
JPushClient公共方法
sendNotificationWithImei
int sendNo(发送编号),String imei (IMEI字符串) ,
String msgTitle (消息标题/通知标题) ,
String msgContent (消息内容/通知内容) 发送带IMEI的通知sendNotificationWithImeiint 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的消息sendCustomMessageWithImeiint sendNo ,
String imei ,
String msgTitle ,
String msgContent,
String msgContentType (消息内容类型,原样返回),
Map<String, Object> extra 用户自定义消息类型,
以及传递附属信息
sendNotificationWithTag
int sendNo ,String tag (Tag字符串) ,
String msgTitle ,
String msgContent发送带Tag的通知sendNotificationWithTagint sendNo ,
String tag ,
String msgTitle ,
String msgContent ,
int builderId ,
Map<String, Object>extra自定义通知栏(没有则填写0)
以及传递附属信息
sendCustomMessageWithTag
int sendNo ,String tag ,
String msgTitle ,
String msgContent发送带Tag的消息sendCustomMessageWithTagint sendNo ,
String tag ,
String msgTitle ,
String msgContent ,
String msgContentType ,
Map<String, Object> extra 用户自定义消息类型,
以及传递附属信息
sendNotificationWithAlias
int sendNo ,String alias (Alias字符串) ,
String msgTitle ,
String msgContent发送带Alias的通知sendNotificationWithAliasint 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的消息sendCustomMessageWithAliasint sendNo ,
String alias ,
String msgTitle ,
String msgContent ,
String msgContentType ,
Map<String, Object> extra 用户自定义消息类型,
以及传递附属信息
sendNotificationWithAppKey
int sendNo ,String msgTitle ,
String msgContent发送通知给AppKey的所有用户sendNotificationWithAppKeyint sendNo ,
String msgTitle ,
String msgContent ,
int builderId ,
Map<String, Object>extra自定义通知栏(没有则填写0)
以及传递附属信息
sendCustomMessageWithAppKey
int sendNo ,String msgTitle ,
String msgContent发送带AppKey的消息sendCustomMessageWithAppKeyint 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
错误代码,代码定义参考ErrorCodeEnumgetErrmsg 返回错误消息的描述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;
}
}
0 0
- jpush推送
- jpush 推送
- JPush推送
- 极光推送JPush
- 试用JPush极光推送
- JPUSH andoid推送开发
- JPush 服务器消息推送
- Android Jpush极光推送
- 极光推送Jpush
- Android 推送 之 JPush
- JPush 推送应用
- jpush极光推送
- 导入 JPush推送
- JPush推送整理总结
- jpush停止推送
- JPush极光推送
- Android 推送 之 JPush
- iOS JPush极光推送
- js实现html的placeholder属性效果
- 【Tomcat】eclipse如何安装tomcat插件
- 警报:XcodeGhost已扩散至第三方框架
- NSString+NSMutableString+NSValue+NSAraay用法汇总
- 关于C语言的fprintf与fwrite使用区别
- jpush 推送
- Android系统移植与调试之------->如何修改Android系统默认显示【开发者选项】并默认打开【USB调试】和【未知来源】开关
- EditPlus配置代码快速行注释和取消行注释
- [Unity热更新]unity5中的assetbundle
- SynchronizedMap和ConcurrentHashMap的深入分析
- GridView合并单元格
- Linux(RHEL)5.4/5.5/5.8/6.0/6.3 ISO镜像文件-下载地址
- SQL中count()/max() /min()/sum()avg()/sum()等函数用法
- iOS关于系统短信和电话的调用