极光推送
這里使用別名方式推送!!!
Andriod和IOS同步使用別名形式!
必要參數:
PUSHCLIENTPRO_KEY=598ffcxxxxx1c0c
PUSHCLIENTPRO_MASTERSECRET=c373bdaxxxxxx3a008
1.引入極光推送jar
2.自定義工具類
@Slf4j @Service @Transactional public class JPushSendMessageServiceImpl implements JPushSendMessageService{@Value("${spring.profiles.active:}")private String PUBLISH_EVN;@Value("${ssx.jpush.apnsProduction}")private boolean APNSPRODUCTION;private static final String PUSHCLIENTPRO_KEY = "598fxxxxc1c0c";private static final String PUSHCLIENTPRO_MASTERSECRET = "c373xxxx3a008";@Overridepublic int jpush(JPushCommonParam param) throws APIConnectionException, APIRequestException {PushResult pushResult;HttpProxy proxy = null;// 非dev環境,使用代理進行測試if (Arrays.asList("test", "run").contains(PUBLISH_EVN)) {proxy= new HttpProxy(HttpConfigure.getProxySslIp(), HttpConfigure.getProxySslPort());log.info("========== 代理服務器地址: {}", JSON.toJSONString(proxy.getNetProxy().address()));}Platform platform = Platform.all();Options options = Options.newBuilder().setApnsProduction(APNSPRODUCTION).build();//android通知AndroidNotification androidNotification =AndroidNotification.newBuilder().setAlert(param.getContent()).setTitle(param.getTitle()).addExtra("bid", param.getBid()).build();//ios通知IosAlert alert = IosAlert.newBuilder().setTitleAndBody(param.getTitle(),null,param.getContent()).setActionLocKey("PLAY").build();IosNotification iosNotification = IosNotification.newBuilder().setAlert(alert).setSound("default").setBadge(+1).addExtra("bid", param.getBid()).addExtra("btype", btype).build();//設置別名Audience audience;if(param.getRegistraidList() != null && !param.getRegistraidList().isEmpty()){List<String> userCodeAndActive = new ArrayList<>();param.getRegistraidList().stream().forEach(x->{userCodeAndActive.add(x + "_" + PUBLISH_EVN);});audience = Audience.alias(userCodeAndActive);}else{audience = Audience.all();//廣播}Notification notification = Notification.newBuilder().addPlatformNotification(androidNotification).addPlatformNotification(iosNotification).build();PushPayload pushPayload = PushPayload.newBuilder().setPlatform(platform).setAudience(audience).setOptions(options).setNotification(notification).build();JPushClient pushClient = new JPushClient(PUSHCLIENTPRO_MASTERSECRET, PUSHCLIENTPRO_KEY,proxy, ClientConfig.getInstance());try {log.info("========【開始推送】input:{}",JSON.toJSONString(pushPayload));pushResult = pushClient.sendPush(pushPayload);if(pushResult.getResponseCode() == 200){log.info("=======【推送成功】input:{}",pushResult.getResponseCode());return 1;}} catch (APIConnectionException e) {log.info("=======【推送失敗】sendPush APIConnectionException: "+e.getMessage());} catch (APIRequestException e) {log.info("=======【推送失敗】sendPush APIRequestException: "+e.getMessage());} catch (Exception e){log.info("=======【推送失敗】sendPush exception: "+e.getMessage());}return 0;} }3.準備參數-推送
JPushCommonParam jPushCommonParam = new JPushCommonParam(); //設置業務 jPushCommonParam.setBid(mCode); jPushCommonParam.setTitle(pubNumberMatter.getTitle()); jPushCommonParam.setRegistraidList(userCodeList); jPushCommonParam.setContent(pubNumberMatter.getTabloid()); jPushSendMessageService.jpush(jPushCommonParam)總結
- 上一篇: ES5-拓展 this指向的总结
- 下一篇: ES5-拓展 箭头函数的this、thi