1 maven配置文件
cn.jpush.api
jpush-client
3.2.7
cn.jpush.api
jiguang-common
1.1.1
io.netty
netty-all
4.1.6.Final
compile
com.google.code.gson
gson
2 极光推送工具类
package com.zjxnjz.mall.restfulapi.common.util;
import cn.jpush.api.JPushClient;
import cn.jpush.api.common.resp.APIConnectionException;
import cn.jpush.api.common.resp.APIRequestException;
import cn.jpush.api.push.PushResult;
import cn.jpush.api.push.model.Message;
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.Notification;
/**
* 极光推送 Jpush 工具类
* @author SHF
* @version 创建时间:2018年6月15日 下午4:33:46
*/
public class JPushUtil {
private static String AppKey = "06947ff1ce4a86f1b0b1f2c1";
private static String Maste_Secret = "9b23669ef51f984c6ad17f8c";
public static PushResult push(Notification notification,Message message) {
//创建jpush对象
JPushClient jPushClient=new JPushClient(Maste_Secret,AppKey);
PushPayload payload = PushPayload.newBuilder()
.setPlatform(Platform.all())
.setAudience(Audience.all())
.setNotification(notification)
.setMessage(message)
.build();
try {
PushResult result = jPushClient.sendPush(payload);
System.out.println("success");
System.out.println("消息id为:"+result.msg_id);
System.out.println("发送id为:"+result.sendno);
return result;
} catch (APIConnectionException e) {
e.printStackTrace();
} catch (APIRequestException e) {
e.printStackTrace();
}
return null;
}
}
转载至链接:https://my.oschina.net/u/3677987/blog/1831104