- import cn.jiguang.common.ClientConfig;
- 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.IosNotification;
- import cn.jpush.api.push.model.notification.Notification;
- public class JPushClientUtil {
- //在极光注册上传应用的 appKey 和 masterSecret
- private static final String appKey ="7b6c132dd2xxxxff37bfxxx0";必填,例如466f7032ac604e02fb7bda89
- private static final String masterSecret = "284f35c2xxxxc912a74dxxx0";//必填,每个应用都对应一个masterSecret
- public static void main(String[] args) throws Exception {
- JPushClient jpushClient = new JPushClient(masterSecret, appKey, null, ClientConfig.getInstance());
- PushPayload payload = buildPushObject_ios_tagAnd_alertWithExtrasAndMessage();
- try {
- PushResult result = jpushClient.sendPush(payload);
- System.out.println(result.msg_id);
- System.out.println(result);
- } catch (APIConnectionException e) {
- } catch (APIRequestException e) {
- }
- }
- public static PushPayload buildPushObject_ios_tagAnd_alertWithExtrasAndMessage() {
- return PushPayload.newBuilder()
- .setPlatform(Platform.ios())
- .setAudience(Audience.alias("1647af0e50e4444dbe05b3d7b79dadfd"))
- .setNotification(Notification.newBuilder()
- .addPlatformNotification(IosNotification.newBuilder()
- .setAlert("死亡如风")
- .setSound("sohappy")
- .addExtra("issueId", "哈哈")
- .addExtra("type","哈哈")
- .build())
- .build())
- .setMessage(Message.content("老汉来推推推啦~"))
- .setOptions(Options.newBuilder()
- .setApnsProduction(false)
- .build())
- .build();
- }
- }
极光api推送消息java实现
最新推荐文章于 2023-01-17 18:33:02 发布