极光官网链接 : https://www.jiguang.cn/
Java后端的整合如下:
<dependency> <groupId>cn.jpush.api</groupId> <artifactId>jpush-client</artifactId> <version>3.4.2</version> </dependency> <dependency> <groupId>cn.jpush.api</groupId> <artifactId>jiguang-common</artifactId> <version>1.1.3</version> </dependency>
创建一个工具类 JiGuangPushUtil.java
package com.zy.cm.common.core.util; import cn.jiguang.common.resp.APIConnectionException; import cn.jiguang.common.resp.APIRequestException; import cn.jpush.api.JPushClient; import cn.jpush.api.push.PushResult; import cn.jpush.api.push.model.Message; import cn.jpush.api.push.model.Options; import cn.jpush.api.push.model.Platform; import cn.jpush.api.push.model.PushPayload; import cn.jpush.api.push.model.audience.Audience; import cn.jpush.api.push.model.notification.AndroidNotification; import cn.jpush.api.push.model.notification.IosAlert; import cn.jpush.api.push.model.notification.IosNotification; import cn.jpush.api.push.model.notification.Notification; import java.util.HashMap; import java.util.List; import java.util.Map; public class JiGuangPushUtil { /** * 两个参数分别填写你申请的masterSecret和appKey## */ private static String masterSecret = "你的masterSecret"; private static String appKey = "你的appKey"; private static JPushClient jPushClient=new JPushClient(masterSecret,appKey); /** * 全平台推送 * @param parm map里面可以根据自身情况增加一些参数 比如页面跳转的地址等 * @param list 用户id集合 这里我们是以用户id作为别名的方式注册到极光 所以我们只需要把用户id给极光 他就会直接给对应用户推送 */ public static void jpushAll(Map<String, String> parm,List<String> list) { PushPayload payload = PushPayload.newBuilder() //所有平台的用户 .setPlatform(Platform.all()) //指定用户 .setAudience(Audience.alias(list)) .setNotification(Notification.newBuilder() //ios推送 .addPlatformNotification(IosNotification.newBuilder() .setAlert(IosAlert.newBuilder().setTitleAndBody(parm.get("title"),null,parm.get("body")).build()) .setBadge(+1) .setSound("qxgf") .addExtras(parm) .build()) //Android推送 也可以分开写 .addPlatformNotification(AndroidNotification.newBuilder() .setTitle(parm.get("title")) .addExtras(parm) .setAlert(parm.get("body")) .build()) .build()) //指定开发环境 .setOptions(Options.newBuilder().setApnsProduction(false).build()) //自定义信息 .setMessage(Message.newBuilder().setMsgContent(parm.get("title")).addExtras(parm).build()) .build(); try { PushResult pushResult = jPushClient.sendPush(payload); System.out.println(pushResult); if(pushResult.getResponseCode()==200){ System.out.println(pushResult.getResponseCode()); } } catch (APIConnectionException e) { e.printStackTrace(); } catch (APIRequestException e) { e.printStackTrace(); } } /** * 参数设置 * @param title * @param body * @param list 用户集合 */ public static void jpushPush(String title, String body, List<String> list){ Map<String, String> parm = new HashMap<>(); //标题 parm.put("title",title); //内容 parm.put("body",body); JiGuangPushUtil.jpushAll(parm,list); } }
最后哪里使用在哪里直接调用:
JiGuangPushUtil.jpushPush(MedicalConstant.System_Schedule,body,list);