栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

个推推送记录

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

个推推送记录

个推推送记录

个推文档:https://docs.getui.com/getui/server/rest_v2/push/

流程
  1. 用户端通过帮绑定别名(手机号)与cid的之间的关系,绑定之后服务端能够获取到这个映射关系,具体绑定获取cid链接如下:个推别名绑定 , h5获取clientId
  2. 服务端通过别名与这个进行发送,发送的时候个推服务会通过别名找到这cid然后就能够发送信息了
  3. app 使用一定要云打包。
服务端代码

   com.getui.push
    restful-sdk
    1.0.0.3

public PushApi createApi() {
        // 设置httpClient最大连接数,当并发较大时建议调大此参数。或者启动参数加上 -Dhttp.maxConnections=200
        System.setProperty("http.maxConnections", "200");
        GtApiConfiguration apiConfiguration = new GtApiConfiguration();
        apiConfiguration.setAppId(appId);
        apiConfiguration.setAppKey(appKey);
        apiConfiguration.setMasterSecret(masterSecret);
        // 接口调用前缀,请查看文档: 接口调用规范 -> 接口前缀, 可不填写appId
        apiConfiguration.setDomain("https://restapi.getui.com/v2/");
        // 实例化ApiHelper对象,用于创建接口对象
        ApiHelper apiHelper = ApiHelper.build(apiConfiguration);
        // 创建对象,建议复用。目前有PushApi、StatisticApi、UserApi
        PushApi pushApi = apiHelper.creatApi(PushApi.class);
        return pushApi;
}
public void send(MessageVO messageVO){
	    // 根据手机号进行推送
        PushDTO pushDTO = new PushDTO<>();
        // 设置推送参数
        pushDTO.setRequestId(System.currentTimeMillis() + "");
        // 通知
        //配置推送条件    
        // 1: 表示该消息在用户在线时推送个推通道,用户离线时推送厂商通道;    
        // 2: 表示该消息只通过厂商通道策略下发,不考虑用户是否在线;    
        // 3: 表示该消息只通过个推通道下发,不考虑用户是否在线;    
        // 4: 表示该消息优先从厂商通道下发,若消息内容在厂商通道代发失败后会从个推通道下发。    
        Strategy strategy=new Strategy();    
        strategy.setDef(1);    
        Settings settings=new Settings();    
        settings.setStrategy(strategy);    
        pushDTO.setSettings(settings);    
        settings.setTtl(3600000);//消息有效期,走厂商消息需要设置该值    
        
        GTNotification notification = new GTNotification();
        notification.setTitle(messageVO.getTitle());
        notification.setBody(messageVO.getContext());
        PushMessage pushMessage = new PushMessage();
        // 当定义payload的时候可进行
        notification.setClickType("payload");
        notification.setPayload(JSON.toJSONString(messageVO));
        pushMessage.setNotification(notification);
        pushDTO.setPushMessage(pushMessage);
         // 配置 android 厂商通道
        AndroidDTO androidDTO = new AndroidDTO();
        Ups ups = new Ups();
        ThirdNotification thirdNotification = new ThirdNotification();
        thirdNotification.setClickType(CommonEnum.ClickTypeEnum.TYPE_STARTAPP.type);
        thirdNotification.setTitle(messageVO.getTitle());
        thirdNotification.setBody(messageVO.getContext());
        ups.setNotification(thirdNotification);
        androidDTO.setUps(ups);
        pushChannel.setAndroid(androidDTO);
        // ios
        IosDTO iosDTO = new IosDTO();
        Aps aps = new Aps();
        alert alert = new alert();
        alert.setTitle(messageVO.getTitle());
        alert.setBody(messageVO.getContext());
        aps.setalert(alert);
        iosDTO.setAps(aps);
        iosDTO.setType("notify");
        pushChannel.setIos(iosDTO);
        pushDTO.setPushChannel(pushChannel);
         // 设置接收人信息
        Audience audience = new Audience();
        audience.addAlias(person.getPhone());
        pushDTO.setAudience(audience);
        log.info("开始推送-->{}", pushDTO);
        ApiResult>> mapApiResult = pushApi.pushToSingleByAlias(pushDTO);
        log.info("推送结果-->{}", mapApiResult);
}

unipush拿不到payload参数:
需要使用receive进行接收,而不是click事件 Unipush常见问题

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/682535.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号