极光推送集成到后台服务器

一、(参考)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()); 

       

   

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值