极光api推送消息java实现


  1.  
  2. import cn.jiguang.common.ClientConfig;  
  3. import cn.jiguang.common.resp.APIConnectionException;  
  4. import cn.jiguang.common.resp.APIRequestException;  
  5. import cn.jpush.api.JPushClient;  
  6. import cn.jpush.api.push.PushResult;  
  7. import cn.jpush.api.push.model.Message;  
  8. import cn.jpush.api.push.model.Options;  
  9. import cn.jpush.api.push.model.Platform;  
  10. import cn.jpush.api.push.model.PushPayload;  
  11. import cn.jpush.api.push.model.audience.Audience;  
  12. import cn.jpush.api.push.model.notification.IosNotification;  
  13. import cn.jpush.api.push.model.notification.Notification;  

  14.   
  15.   
  16. public class JPushClientUtil {  
  17.   
  18.    //在极光注册上传应用的 appKey 和 masterSecret  
  19.     private static final String appKey ="7b6c132dd2xxxxff37bfxxx0";必填,例如466f7032ac604e02fb7bda89  
  20.     private static final String masterSecret = "284f35c2xxxxc912a74dxxx0";//必填,每个应用都对应一个masterSecret  
  21.   
  22.  
  23.     public static void main(String[] args) throws Exception {  
  24.         JPushClient jpushClient = new JPushClient(masterSecret, appKey, null, ClientConfig.getInstance());  
  25.   

  26.         PushPayload payload = buildPushObject_ios_tagAnd_alertWithExtrasAndMessage();  
  27.   
  28.         try {  
  29.             PushResult result = jpushClient.sendPush(payload);  
  30.             System.out.println(result.msg_id);  
  31.             System.out.println(result);  
  32.   
  33.         } catch (APIConnectionException e) {  

  34.   
  35.         } catch (APIRequestException e) {  
  36.             
  37.         }  
  38.     }  
  39.   
  40.   
  41.     public static PushPayload buildPushObject_ios_tagAnd_alertWithExtrasAndMessage() {  
  42.         return PushPayload.newBuilder()  
  43.                 .setPlatform(Platform.ios())  
  44.                 .setAudience(Audience.alias("1647af0e50e4444dbe05b3d7b79dadfd"))  
  45.                 .setNotification(Notification.newBuilder()  
  46.                         .addPlatformNotification(IosNotification.newBuilder()  
  47.                                 .setAlert("死亡如风")  
  48.                                 .setSound("sohappy")  
  49.                                 .addExtra("issueId""哈哈")  
  50.                                 .addExtra("type","哈哈")  
  51.                                 .build())  
  52.                         .build())  
  53.                 .setMessage(Message.content("老汉来推推推啦~"))  
  54.                 .setOptions(Options.newBuilder()  
  55.                         .setApnsProduction(false)  
  56.                         .build())  
  57.                 .build();  
  58.     }  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

茂林修竹丶

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值