[ 极光文档 ]html
进去以后,建立一个应用,已有应用可跳过 前端
建立完成 java
进入应用,看到AppKey和MasterSecret,这两个参数在sdk集成的时候会用到 android
<dependency> <groupId>cn.jpush.api</groupId> <artifactId>jpush-client</artifactId> <version>3.2.17</version> </dependency> <dependency> <groupId>cn.jpush.api</groupId> <artifactId>jiguang-common</artifactId> <version>1.0.3</version> </dependency> <dependency> <groupId>io.netty</groupId> <artifactId>netty-all</artifactId> <version>4.1.6.Final</version> <scope>compile</scope> </dependency> <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> <version>2.3</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.7</version> </dependency>
com.weiwend.jdpush //包名
jdpush //类名ios
接下来是jdpush类的操做
其实,极光已经给咱们集成好了,只需调用推送方法便可web
//极光推送>>Android //Map<String, String> parm是我本身传过来的参数,同窗们能够自定义参数 public static void jpushAndroid(Map<String, String> parm) { // 设置好帐号的app_key和masterSecret String appKey = "**************"; String masterSecret = "************"; //建立JPushClient JPushClient jpushClient = new JPushClient(masterSecret, appKey); //推送的关键,构造一个payload PushPayload payload = PushPayload.newBuilder() .setPlatform(Platform.android())//指定android平台的用户 .setAudience(Audience.all())//你项目中的全部用户 .setNotification(Notification.android(parm.get("msg"), "这是title", parm)) //发送内容,这里不要盲目复制粘贴,这里是我从controller层中拿过来的参数) .setOptions(Options.newBuilder().setApnsProduction(false).build()) //这里是指定开发环境,不用设置也不要紧 .setMessage(Message.content(parm.get("msg")))//自定义信息 .build(); try { PushResult pu = jpushClient.sendPush(payload); } catch (APIConnectionException e) { e.printStackTrace(); } catch (APIRequestException e) { e.printStackTrace(); } }
//极光推送>>ios
//Map<String, String> parm是我本身传过来的参数,同窗们能够自定义参数
public static void jpushIOS(Map<String, String> parm) {
// 设置好帐号的app_key和masterSecret是必须的
String appKey = "*********************"; String masterSecret = "**********************"; //建立JPushClient JPushClient jpushClient = new JPushClient(masterSecret, appKey); PushPayload payload = PushPayload.newBuilder() .setPlatform(Platform.ios())//ios平台的用户 .setAudience(Audience.all())//全部用户 .setNotification(Notification.newBuilder() .addPlatformNotification(IosNotification.newBuilder() .setAlert(parm.get("msg")) .setBadge(+1) .setSound("happy") .addExtras(parm) .build()) .build()) .setOptions(Options.newBuilder().setApnsProduction(false).build()) .setMessage(Message.newBuilder().setMsgContent(parm.get("msg")).addExtras(parm).build())//自定义信息 .build(); try { PushResult pu = jpushClient.sendPush(payload); } catch (APIConnectionException e) { e.printStackTrace(); } catch (APIRequestException e) { e.printStackTrace(); } }
.setOptions(Options.newBuilder().setApnsProduction(false).build())api
[ 极光文档Push API v3 ]
//这是个人添加文章的接口方法 //如今我要添加一篇文章后,进行推送 public Map<String, Object> addArticle() throws Exception { Map<String, Object> result = new HashMap<String, Object>(); .... //省略文章添加的步骤 //从前端页面传个参数过来判断是否推送 if((infoMap.get("is_push").toString()).trim().equals("1")){ //设置推送参数 //这里同窗们就能够自定义推送参数了 Map<String, String> parm =new HashMap<String, String>(); //这是个人文章id parm.put("id",(""+id).trim()); //文章标题 parm.put("Atitle",(String) infoMap.get("Atitle") ); //设置提示信息,内容是文章标题 parm.put("msg",(String) infoMap.get("Atitle") ); //调用ios的 Jdpush.jpushIOS(parm); //而后调用安卓的 Jdpush.jpushAndroid(parm); } return result; }
Your request params is invalid. Please check them according to error message.
Error response from JPush server. Should review and fix it.
//而后状态码是
INFO 2017-07-14 11:08:04,208 com.weiwend.jdpush.Jdpush.http-bio-8080-exec-7 HTTP Status: 400
INFO 2017-07-14 11:08:04,208 com.weiwend.jdpush.Jdpush.http-bio-8080-exec-7 Error Code: 1011
INFO 2017-07-14 11:08:04,208 com.weiwend.jdpush.Jdpush.http-bio-8080-exec-7 Error Message: cannot find user by this audience
INFO 2017-07-14 11:08:04,208 com.weiwend.jdpush.Jdpush.http-bio-8080-exec-7 Msg ID: 4241206476app
这就很尴尬了
若是你的项目中有用户,
可是,是你的参数(setAudience)设置错了,也会也会报错.框架