极光推送集成厂商通道(java)

极光推送后台开发文档:https://docs.jiguang.cn//jpush/server/push/rest_api_v3_push/

自定义厂商通道

   try {
            JPushClient jpushClient = new JPushClient("", "", null, ClientConfig.getInstance());
            /**
             * scheduleName        日程名称
             * scheduleTime        日程时间(格式:yyyy-MM-dd HH:mm:ss)
             */
            ScheduleListResult sResult =   jpushClient.getScheduleList();
            String userId = "";
            // 自定义推送模型
            PushModel model = new PushModel();
            model.setBody("内容");
            model.setTitle("标题");
            model.setType(1);
            model.setDomainId("1");
            IosAlert iosAlert = IosAlert.newBuilder().setTitleAndBody(model.getTitle(), null, model.getBody()).build();
            // 通知信息
            Notification notification = Notification.newBuilder()
                    .addPlatformNotification(IosNotification.newBuilder()
                            .setAlert(iosAlert)
                            .incrBadge(1)
                            .addExtra("extras", JSON.toJSONString(model))
                            .build())
                    .addPlatformNotification(AndroidNotification.newBuilder()
                            .setAlert(model.getBody())
                            .setTitle(model.getTitle())
                            // 安卓自定义activity  接收厂商通知
                            .addCustom("uri_activity","net.bontec.wxqd.activity.JPushOpenActivity")
                            .addExtra("extras", JSON.toJSONString(model))
                            .build())
                    .build();

            // 推送相关设置
            //pushProduction针对ios极光推送设置测试环境或正式环境 True 表示推送生产环境,False 表示要推送开发环境
            Options options = Options.newBuilder()
                    .setApnsProduction(true)
                    .setSendno(1)
                    .setTimeToLive(86400)
                    .build();
            // 推送场景构造
            PushPayload build = PushPayload.newBuilder()
                    .setAudience(Audience.alias(userId))
                    .setPlatform(Platform.android_ios())
                    .setNotification(notification)
                    .setOptions(options)
                    .build();

            System.out.println(JSON.toJSONString(build));
            PushResult pushResult =  jpushClient.sendPush(build);
            System.out.println(JSON.toJSONString(pushResult));
        }  catch (Exception e) {
            log.error("极光推送失败{}", e);
        }
# java   工具  

评论

企鹅群:39438021

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×