一、(参考)https://github.com/jpush/jpush-api-java-client
1. 将gson-2.2.4.jar
jiguang-common-1.0.2.jar
jpush-client-3.2.16.jar
slf4j-api-1.7.7.jar
slf4j.log4j12-1.7.7.jar等五个jar包导入ofbiz项目中
2. 服务端配置
//初始化配置
ClientConfig clientConfig = ClientConfig.getInstance();
//替换MASTER_SECRET和 APP_KEY的值
(1) JPushClient jpushClient = new JPushClient(MASTER_SECRET, APP_KEY, null, clientConfig);
(2)//同时指定离线消息保存时间
JPushClient jpush = new JPushClient(masterSecret, appKey,timeToLive);
//制定推送格式
PushPayload payload = PushPayload.newBuilder()
.setPlatform(Platform.android_ios())//设置平台
.setAudience(Audience.tag(tags)) //设置推送目标或者推送人群
.setNotification(Notification.newBuilder()//自定义推送形式
.setAlert(ALERT) //设置推送内容
.addPlatformNotification(AndroidNotification.newBuilder() //android平台接收到的格式定义
.setTitle(TITLE) //设置推送标题
.addExtra("id", "222").build()) //添加额外字段
.addPlatformNotification(IosNotification.newBuilder() //ios平台接收到的格式定义
.incrBadge(1)
.addExtra("extra_key", "extra_value").build())
.build())
.build();
//推送消息(result为推送结果)
PushResult result = jpushClient.sendPush(payload);
3. 推送格式
推送标题:
推送内容:
推送目标平台:分为Android、IOS
推送人群:分为广播(所有人)、设备标签(TAG)、设备别名(Alias)
额外标签信息:(不固定) 包括URL
TagListResult list =jpushClient.getTagList();//获取所有设备名称
二、服务器端统计接口
注意:传入参数为:推送返回值里面的msg_id
publicstaticvoidcountPush(String mid){
JPushClient jpushClient = new JPushClient(masterSecret,appKey);
PushPayload payload = null;
try {
ReceivedsResult result = jpushClient.getReportReceiveds(mid);
Received received = result.received_list.get(0);
System.out.println("android_received:"+ received.android_received
+ "\nios:" + received.ios_apns_sent);
System.out.println("countPush Got result - " + result);
} catch (APIConnectionException e) {
// Connection error, should retry later
System.out.println("Connection error, should retry later"+e);
} catch (APIRequestException e) {
// Should review the error, and fix the request
System.out.println("Should review the error, and fix the request"+e);
System.out.println("HTTP Status: " + e.getStatus());
System.out.println("Error Code: " + e.getErrorCode());
System.out.println("Error Message: " + e.getErrorMessage());
}
}